Solved

Batch File - file exists in directory on remote drive

Posted on 2009-05-12
8
951 Views
Last Modified: 2012-05-06
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

0
Comment
Question by:James Rodgers
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 3
8 Comments
 
LVL 70

Accepted Solution

by:
Qlemo earned 350 total points
ID: 24369825
With slight changes, at it seems not useful to log that much to me

@echo off
set var=\\backup01\backup\adsci\
set compDate=%date:~6,4%-%date:~3,2%-%date:~0,2%kjhjkh
if exists %var%%compDate% (
  echo Found - File Name is : %var% - %dated%
  dir %var%
) >> completed.txt else (
  echo No File found For %compDate% >> notexists.txt
)

Open in new window

0
 
LVL 70

Expert Comment

by:Qlemo
ID: 24369840
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.
0
 
LVL 4

Expert Comment

by:delyan_valchev
ID: 24369946
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

0
[Webinar] How Hackers Steal Your Credentials

Do You Know How Hackers Steal Your Credentials? Join us and Skyport Systems to learn how hackers steal your credentials and why Active Directory must be secure to stop them. Thursday, July 13, 2017 10:00 A.M. PDT

 
LVL 25

Author Comment

by:James Rodgers
ID: 24374203
>>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...
0
 
LVL 4

Assisted Solution

by:delyan_valchev
delyan_valchev earned 150 total points
ID: 24380191
Just found a typo in the getting the date script:
SET Second=%%A
should be:
SET Second=%%E
Here is the correct version:
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=%%E
        SET Year=%%F
)

Open in new window

0
 
LVL 70

Expert Comment

by:Qlemo
ID: 24380194
delyan_valchev,
do you find the (small) typo in your code snippet?
0
 
LVL 70

Expert Comment

by:Qlemo
ID: 24380202
Eerie, I was just a second too late ...
0
 
LVL 4

Expert Comment

by:delyan_valchev
ID: 24380208
Practicing my mind-reading... ;-)
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

One of my most closely kept secrets is revealed in this discussion How to output text on the same line This question was recently posted in EE by Simon336697 (http://www.experts-exchange.com/Programming/Languages/Scripting/Shell/Batch/Q_2459…
YESTERDAY YESTERDAY.BAT is inspired by a previous article I wrote entitled: TOMORROW.BAT (http://www.experts-exchange.com/OS/Microsoft_Operating_Systems/MS_DOS/A_4196-Advanced-Batch-File-Programming-TOMORROW-BAT.html). The crux of this batch f…
This is a high-level webinar that covers the history of enterprise open source database use. It addresses both the advantages companies see in using open source database technologies, as well as the fears and reservations they might have. In this…
In this video, viewers are given an introduction to using the Windows 10 Snipping Tool, how to quickly locate it when it's needed and also how make it always available with a single click of a mouse button, by pinning it to the Desktop Task Bar. Int…

696 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question