Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.
Compare file names in batch file
Name: pgilbert11 Date: June 19, 2008 at 07:13:18 Pacific OS: XP SP2 CPU/Ram: Quad core p4 Product: HP
Comment:
HI
Trying to compare 2 file names and then react depending whether they are the same or not.
Code as follows: for /f %%a IN ('dir "c:\test\1\*.ver" /b') do @echo %%a for /f %%b IN ('dir "c:\test\2\*.ver" /b') do @echo %%b if %%a equ %%b goto same else goto diff
:same echo same file names goto end
:diff echo different filenames goto end
:end
Have placed the @echo %% at the end of the For lines just so i can see that it is picking up the correct value.
When it gets to the If line however it does not seem to see that the variables are different values. Please help!!
The code posted is meaningless at all, i.e. absolutely wrong and horrible as it demonstrates the OP has no knowledge of the For /F statement and the scope of the related variables (that are defined *inside* the loop itself and can't be accessed outside the sequence block).
So I give up and maybe M2 is so patient to rewrite the code from scratch.
0
Response Number 3
Name: pgilbert11 Date: June 20, 2008 at 00:59:26 Pacific
Reply:
Cracked it!
For those who might be interested: @echo off
for /f %%a IN ('dir "c:\test\1\*.ver" /b') do set file1=%%a for /f %%b IN ('dir "c:\test\2\*.ver" /b') do set file2=%%b
if %file1%==%file2% goto same
echo different filenames goto end
:same echo same file names goto end
:end
0
Response Number 4
Name: toast (by NoIdea) Date: June 20, 2008 at 01:32:55 Pacific
Summary: I'm looking for help with the DATE function in batch files and saw your postings on http://www.computing.net/programming/wwwboard/forum/2249.html %DATE% worked well on my winXP box for naming backup f...
Summary: The inverted commas are quite crucial, if you want to write the terms in full, rather than as 123456~1. So I created a batch file with "C:\Program Files\Outlook Express\Msimn.exe /mailurl:mailto:" and...
Summary: I get files often that have a crc checksum in the file name but no premade sfv to check it with. So I run the file through quicksfv and open the sfv file and compare the value in the file name and the...