|
Answer» I am trying to create a batch file to compare 2 file names from different directories. I have been reading and trying different things, but with no luck. I can create the batch file, but I keep getting errors about the IF command
This is what I am trying to achieve I am wanting to compare the filenames only from C:\program files\my folder\my app *.mde to Z:\upgrades\my app *.mde (the * is for LIKE version 6.1 or 7.3 and so on) I am wanting to check to see if the version numbers are the same, and if they are not, I would like to warn the user of a new edition and give them an option of 1. Upgrading - which would delete the current file and copy the newer version in the same folder, then give them a mesage "Copy Complete" or 2. Wait till later - which would not change anything , but open the current file
Any help would be appreciated, what I have to go through to make this change on every PC is very time comsuming, which none of use have a lot of time anymore! Gratefull for Your TIME! DaveTry something like this:
@echo off setlocal set SourcePath=C:\program files\my folder\ set DestPath=Z:\upgrades\ set FileSpec=My app*.mde
for /f "delims=" %%a in ('dir /b /a-d "%SourcePath%\%FileSpec%") do if exist "%DestPath%\%%na%%xa" ( echo Same file exists ) else ( echo New edition of "%%na%%xa". set /p Answer=Press 1 to upgrade now, or 2 to upgrade later: if {%Answer%}=={1} delete %DestPath%\%%na%%xa"© "%SourcePath%\%FileSpec%" "%SourcePath%\%FileSpec%" if {%Answer%}=={2} start "%SourcePath%\%FileSpec%"&goto :EOF echo You are supposed to enter 1 or 2 ) I am having trouble with this,when I run this I get this
Code: [Select]C:\>mytest.bat
C:\>setlocal
C:\>set SourcePath=C:\MM3M3
C:\>set DestPath=Y:\dsd19\upgrade
C:\>set FileSpec=MM6.mde
C:\>for /F "delims=" %a in ('dir /b /a-d "C:\MM3M3\MM6.mde") do if exist "Y:\dsd19\upgrade\%na%xa" (echo same file exist ) else ( echo new edition of "%na%xa" set /p Answer=Press 1 to Upgrade Now, or 2 to upgrade later: if {%Answer%}=={1} delete %DestPath%\%%na%%xa"© "%SourcePath%\%FileSpec%" "%SourcePath%\%FileSpec%" if {%Answer%}=={2} start "%SourcePath%\%FileSpec%"&goto :EOF echo complete ) The system cannot find the file 'dir /b /a-d "C:\MM3M3\MM6.mde".
C:\> I can get it to function without 'dir /b /a-d And the second problem is the return of "%na%xa" instead of the filename.
This is what I have got in the bat file There should be an * in PLACE of the 6 in the filename, I changed it to get it to find the file, is an * used as a wildcard. Since that is what would be different in each file name?
Code: [Select]setlocal set SourcePath=C:\MM3M3 DestPath=Z:\dsd19\upgrade set FileSpec=MM6.mde
for /f "delims=" %%a in ('dir /b /a-d "%SourcePath%\%FileSpec%") do if exist "%DestPath%\%%na%%xa" ( echo Same file exists ) else ( echo New edition of "%%na%%xa". set /p Answer=Press 1 to upgrade now, or 2 to upgrade later: if {%Answer%}=={1} delete %DestPath%\%%na%%xa"© "%SourcePath%\%FileSpec%" "%SourcePath%\%FileSpec%" if {%Answer%}=={2} start "%SourcePath%\%FileSpec%"&goto :EOF echo You are supposed to enter 1 or 2 )
Any Ideals or than me being total lost?
Oops. Forgot the closing single quote in the FOR /F.
Code: [Select]@echo off setlocal set SourcePath=C:\MM3M3 set DestPath=Z:\dsd19\upgrade set FileSpec=MM6.mde
for /f "delims=" %%a in ('dir /b /a-d "%SourcePath%\%FileSpec%"') do if exist "%DestPath%\%%na%%xa" ( echo Same file exists ) else ( echo New edition of "%%na%%xa". set /p Answer=Press 1 to upgrade now, or 2 to upgrade later: if {%Answer%}=={1} delete %DestPath%\%%na%%xa"© "%SourcePath%\%FileSpec%" "%SourcePath%\%FileSpec%" if {%Answer%}=={2} start "%SourcePath%\%FileSpec%"&goto :EOF echo You are supposed to enter 1 or 2 ) Still have an 2 ISSUES, one may take care of the other 1 set FileSpec=MM6.mde can I use * as a wildcard for the digit following MM
2 in the return I am still getting new edition of "%na%xa"
The comparesome is still wrong, I can change the file name to the same and it still says new edition of "%na%xa".
Is "%na%xa" supposed to be a filename?
ThanksYes, you should be able to use a wildcard.
Sorry about the return ... I need to remember to test my code if it is more than a LINE or two. Replace the "Echo New edition ..." with
Code: [Select]echo New edition of "%%~na%%~xa"
|