[<<]Message[>>]    [<<]Author[>>]    [<<]Subject[>>]    [<<]Thread[>>]

Number : 4747 Date : 2003-06-04 Author : Garry Deane Subject : Re: xxcopy to CD-RW Size(KB) : 2
--- In xxcopy@yahoogroups.com, "garrydeane" wrote: > He's probably got that sorted by now but here's how to > CD to the batch file directory (tested on DOS 6.22, W98 > & NT/W2k/XP, untested on ME but should be OK). > Kan, I overlooked that the previous code is not totally bulletproof. It can fail in the fairly rare case of someone placing install.bat (and other xxcopy files) in their path and invoking it without a path (e.g. just typing INSTALL) when the current directory is different. It's not a problem if someone double clicks on it from explorer or specifies the path or it's in the current directory. In NT/W2k/XP this is easily fixed with "cd /d %~f0\.." or "cd /d % ~dp0". For DOS/W9x/ME, it requires a lot of additional code. See this post for getting the full name of a batch file. http://groups.google.com/groups?hl=en&lr=&ie=UTF- 8&selm=37FC3C42.CF54DC10%40aol.com This can be simplified a little to get just the path then use the techniques previously posted to CD to that path. Here's the modified (somewhat lengthy) code. @echo off if "%rec%"=="01" goto :ckpath :: Change to the batch file directory for NT/W2k/XP if "%OS%"=="Windows_NT" ((cd /d %~dp0)&(goto :next)) :: Find the path to this batch file for DOS/W9x set src= echo %0+ |find.exe /i ".bat+" >nul if errorlevel 1 set src=%0.bat if not errorlevel 1 set src=%0 if exist %src% goto :CDrive :: Run this batch file again with the path as parameters set rec=01 %src% %path% :: Search for this batch file in the path :ckpath if exist %1.\%src% goto found shift goto :ckpath :found set rec= if exist %1\%src% set src=%1\%src% if exist %1%src% set src=%1%src% if not exist %src% goto :notfound :CDrive :: Change to the batch file drive if necessary echo %src% |find.exe ":" >nul if errorlevel 1 goto :CDir %src%\ :CDir :: Change to the batch file directory if necessary echo %src% |find.exe "\" >nul if errorlevel 1 goto :next cd %src%\.. goto :next :notfound echo Error!! Unable to locate %src% goto :end :next echo The current directory is: cd pause :end set src= cls Garry
This message if part of XXCOPY's message Archive. The archive contains all the messages posted at Yahoo!Groups: XXCOPY.