|
Answer» Right, let me explain.
What I want to do, is create a BATCH file (MS-DOS) that basically searches in the directory the file is installed, INCLUDING all subfolders for a particular file, say EXAMPLE.TXT for the purposes of this. If it exists, I don't want anything to happen, and it should just skip the rest of the command to the end. If the file doesn't exist, I'd ideally want it to search for another file in the same directory, if this exists, it would need to copy another file from Location A to Location B, if this file as well doesn't exist, it would ideally want to pop up an error message reading, 'File XXX' doesn't exist.
I'm sorry for my ignorance, but I believe this is possible using the IF command, but am really quite new to MS-DOS and I really prefer learning from examples if anyone could be kind enough to show me a possible way.
Many Thanks
RichardThe logic will look like this
The && operator works like this
operation1 && operation2
Perform operation1 and (only) if it is successful, perform operation2
CODE: [Select]REM searches in the directory the file is installed, REM including all subfolders for a particular file, say EXAMPLE.TXT REM If it exists, I don't want anything to happen, REM and it should just skip the rest of the command to the end. dir /s /b "example.txt" && GOTO end
REM If the file doesn't exist, I'd ideally want it to search for another file in the same directory, REM if this exists, it would need to copy another file from Location A to Location B, IF exist "another.file" ( copy "LocationA:\yet another file" "LocationB" goto end )
REM if this file as well doesn't exist, it would ideally want to pop up REM an error message reading, 'File XXX' doesn't exist. echo MESSAGE: another.file does not exist
:end
this may work
for /f %%a in ('dir /s/b example.txt') do ( call :getdir %%a set targetdir=%tempdir:~-11% call :cpyfile %targetdir% ) goto :eof
:cpyfile for /f %%b in ('dir /s /b %* | find /v /i "secondfile") do copy %%b location2 goto :eof
:getdir set tempdir=%* goto :eoferobby, your code is a good answer to a different question, not the one ASKED!
|