How do i find a txt file (in batch)?

February 10, 2012 at 18:34:52
Specs: Windows 7
I need to find 'errorlog105697.txt' (the random numbers are to make sure there is only ONE errorlog105697 in the entire hard drive) and then move it to the path that the batch program is in. If errorlog105697.txt is already in the same location then use:

set errorcode=1

And that's all.

FYI if it has multiple errorlog105697 then set errorcode to 2

BTW I already tested if errorlog105697 exists earlier in the script. So this is what is done if it does NOT exist in the same location.

See More: How do i find a txt file (in batch)?

Report •

February 11, 2012 at 17:03:44
if exist errorlog105697.txt  set errorcode=1
dir /s errorlog105697.txt > List.txt
find /n "errorlog105697.txt" List.txt > LineNums.txt

I'm not that familiar with the SET parsing commands, but here's what you need to do:

If the number of records in LineNums.txt is > 3 then set errorcode = 2

LineNums.txt contains all the line numbers where the string "errorlog105697.txt" is found in List.txt. Subtract 2 from each of these line numbers to get the line numbers that contain the directory(s) where errorlog105697.txt can be found. Extract the path information from List.txt into environment variable "MyPath". Then:

copy %MyPath%errorlog105697.txt

You'll have to decide what to do if it is both in the current directory and someplace else.

Report •
Related Solutions

Ask Question