Solved Windows Batch File to check backed up files in a folder

July 11, 2012 at 07:40:35
Specs: Windows XP

We do have 25 remote clients that have their software data backed up through our FTP server. The file names that are being sent on a daily basis are in the following format: depending on the client name (ClientA) and the day of the week. Backups are always sent late in the day so we usually do manual checks in the following morning. I made a text file in the same folder as the batch file to list client names. The name of that file is client_names.txt and it contains the following entries:

etc etc...

You will notice the dash (-) bvetween client names and day of the week...that's because of the naming convention of our backups.

I'd like to make a batch file that will check for files that were modified the day before. I'd like the batch file to do a comparison with the client names listing in the client_names.txt file and then copy client names that were NOT backed up the day before in a different file (could be "no_backups.txt")

If anyone can help me with that, it would be much appreciated

Thanks in advance

See More: Windows Batch File to check backed up files in a folder

Report •

July 11, 2012 at 19:25:53
✔ Best Answer
Here's an untested quickie, avoiding date math for the initial version:
@echo off & setlocal enabledelayedexpansion

for /f %%y in (yest) do set yesterday=%%y
:or set /p yesterday=<yest
> missed.txt echo checking non-backed clients for [%yesterday%]
for /f %%a in (clients.txt) do (
for %%b in (%%a*.zip) do (
set fdate=%%~tb
set fdate=!fdate:~0,10!
echo %%a:%%b:!fdate!:!yesterday!:
if !fdate! neq !yesterday! >> missed.txt echo %%a
>yest echo %date:~4%

not tested
there are numerous ways to do this, this is only one approach.

Report •

July 12, 2012 at 06:53:27
Thanks for your reply @nbrane,

However, the script doesn't create any missed.txt file. I know I do have more than one customers that were missing backups on the 11th (yesterday).

Here's a typical filename:

Could we eliminate the prompt for yesterday's date? I will most likely automate this batch file to run at 3am.

Thanks for your help; it is much appreciated

Report •

July 12, 2012 at 19:26:57
I ran a limited test (two files different dates), using the filename format you described,on my xp, and it seemed to work.
Try running the script manually, and add a diagnostic into the script here:
set fdate=!fdate:~0,10!
:add this next line for debugging
echo %%a:%%b:!fdate! >> diag
if !fdate! neq !yesterday! >> missed.txt echo %%a

then post a couple of lines (disguise the client's names of course).
Or just examine content of "diag" and you'll prob'ly see where it's fouling up.
I thought it might be lfn problem, but quotes didn't make a difference...
If this script is run daily, you can have as the very last line:
>yest echo %date%
Then when it runs the next time, it can read that value back out of file "yest"
(I know that seems clumsy, but so is date math).
I'm editing my script in resp.#1 to reflect these mod.s.

Report •

Related Solutions

July 13, 2012 at 07:04:02
Apparently, all client names go in the missed.txt file...not sure why. Here's the slightly modified code:

@echo off & setlocal enabledelayedexpansion

for /f %%i in ('wmic path win32_localtime get dayofweek') do set wd=%%i
:setting %wd% to yesterday day of week
if %wd% == 1 set wd=Sunday
if %wd% == 2 set wd=Monday
if %wd% == 3 set wd=Tuesday
if %wd% == 4 set wd=Wednesday
if %wd% == 5 set wd=Thursday
if %wd% == 6 set wd=Friday
if %wd% == 7 set wd=Saturday

set yesterday=%1
if not defined yesterday (
set /p yesterday=yesterday was? dd/mm/yyyy
for /f %%a in (client_names.txt) do (
for %%b in ( do (
set fdate=%%~tb
set fdate=!fdate:~0,10!
echo %%a:%wd%:%%b:!fdate! >> diag
if !fdate! neq !yesterday! >> missed.txt echo %%a
>yest echo %date%

Here's also an example of an entry in client_names.txt:

Here's the name of Abbyview's backup on yesterday:

I've sent you the content of the diag file in pm

Report •

July 13, 2012 at 19:09:48
My bad! file "yest" includes the dofw, which it should not. If you're using that method, change the last line to do this:
>yest echo %date:~4%
otherwise it will look like "thu 07/12/2012" and not "07/12/2012"
I've changed the post to correct my screw-up

Report •

Ask Question