Link to home
Start Free TrialLog in
Avatar of James Rodgers
James RodgersFlag for Canada

asked on

Batch File - file exists in directory on remote drive

I need to determine if a file exists in a series of directories on a remote drive, and i only have a partial file name!

l am terrible with batch files, been like 10 years since i wrote one, but here is what i need

given a list of directories i need to determine if a file with a specified date in the name exists, and where it doesn't exist create some kind of error report, basic attempt is below, not getting very far with it tho...

if there is a way for a batch file to mail a file or message that would be awesome too

any help is appreciated
@echo on
 
set var=\\backup01\backup\adsci\
 
set compDate=%date:~6,4%-%date:~3,2%-%date:~0,2%kjhjkh >> completed.txt
 
if dir %var% %compDate% goto 20
 
echo Found - File Name is : %var% - %dated% > completed.txt
dir %var% >> completed.txt
 
 
goto end
 
:20
 
echo No File found For %compDate% >> notexists.txt
 
:end

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of Qlemo
Qlemo
Flag of Germany image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
For the message/mail part, you can use either BLAT (www.blat.net) to mail from command line, even attach files, or msg to send a popup message on the screen of an arbitrary PC.
Keep in mind that %date% contents is different for the different regional settings. If you have machines in different countries you may get the dates in format mm/dd/yyyy, dd.mm.yyyy or what not. Here is a locale independent way to get the current date/time. It runs on 2003/XP and up.
FOR /F "skip=2 tokens=2-7 delims=," %%A IN ('WMIC Path Win32_LocalTime Get Day^,Hour^,Minute^,Month^,Second^,Year /Format:csv') DO (
        SET Day=%%A
        SET Hour=%%B
        SET Minute=%%C
        SET Month=%%D
        SET Second=%%A
        SET Year=%%F
)

Open in new window

Avatar of James Rodgers

ASKER

>>With slight changes, at it seems not useful to log that much to me
thanks, but all i need to know if is a file does not exist, the rest is just a catchall, wont even be exported/saved just there to test

>>Keep in mind that %date% contents is different
this will be run on one machine that i have total control over so regional settings will not be an issue, but just might add in your code just to be safe

testing and such then points, thanks,

FYI there will be a follow up about cycling/looping through a list of directories...
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
delyan_valchev,
do you find the (small) typo in your code snippet?
Eerie, I was just a second too late ...
Practicing my mind-reading... ;-)