Solved

Batch file to search folder for files based on Date

Posted on 2011-02-23
12
696 Views
Last Modified: 2012-05-11
1. I recieve nightly backups from 150+ locations and there is a corresponding folder for each location.

2. Within each of those folders is a backup for every day of the week. "BKU_CO_xxxx.xxx.zip" where xxxx.xxx is location.dayofweek.

3. This naming convention is universal across all folders.

What I want is:

1. Check the entire contents of that parent folder for backups on a current or previous date and:

2. Pipe it to a text document that I can look at in one spot as opposed to drilling through every folder.

Ive seen several posts that are close (copying, moving or deleting based on date or date range) but nothing on point. I dont want to copy, move or alter. Just check that the file exists

Any help?
0
Comment
Question by:POINTGREEN
  • 6
  • 5
12 Comments
 
LVL 14

Expert Comment

by:Don Thomson
ID: 34962607
If you just want to know if a particular file exists within one of the folders and all of the first level folders being the locations and all the contents are the actual backup files related to that location, then I would just use:

cd  \parentdir
dir /b /s  > c:\filelist.txt

Assumming that the folder names are the same length  or there abouts you can quickly determine what is there.

Make sure you don't puyt the filelist.txt in the same folder as you are using.

Once that is done - If you need to do sorts (assuming only 1 level deep from the parent folder, the filelist.txt can be brought into something like access - with the "\" being the delimiter - giving you 3 fileld
Drive
Folder
Filename

If there are other files in the folders other than the backup - just filter the data using the Ext.
If the path is extended like s:\data\locations\backups\stores\*.bks
Then just do an admin share on Backups  as backups$  then map a dummy drive to say s:

Then you goto s:\
Stores are you first folder
0
 
LVL 1

Author Comment

by:POINTGREEN
ID: 34962842
That does in fact give me a listing of all the folders, but perhaps I wasnt clear enough. There are 7 subfolders in every folder that are overwritten every week so that when sundays backup runs it over writes the 001.zip folder that is in there. Monday overwrites 002 etc.

What I need it to do is check the modified date to make sure that it was written that day as opposed to the previous week.

This gives me a list of the files but it doesnt tell me when it was modified.
0
 
LVL 1

Author Comment

by:POINTGREEN
ID: 34962899
This is what I get now with no refernce to date modified
This is what I see now (pathing changed to protect it of course)

D:\backups\0023\0023_001.ZIP
D:\backups\0023\0023_002.ZIP
D:\backups\0023\0023_003.ZIP
D:\backups\0023\0023_004.ZIP
D:\backups\0023\0023_005.ZIP
D:\backups\0023\0023_006.ZIP
D:\backups\0023\0023_007.ZIP
0
 
LVL 14

Expert Comment

by:Don Thomson
ID: 34965039
What I did is the following

dir /T:W /S /O:-D > filelist.txt

I imported access as a fixed field file

Saved the import spec as follows
Field Name                         Data      Type                        Start      Width      Indexed      Skip
Date            Text            1      10      No      0
Field2            Text            11      2      No      -1
Time            Text            13      8      No      0
Field4            Text            21      4      No      -1
Type            Text            25      5      No      0
Size            Text            30      10      No      0
FileName                           Text            40      40      No      0

You could right a couple of quick and dirty  delete queries that get rid of the garbage and then a query that brings up any file that's older than say 1 week

Take about 10 minutes of programming in access - assuming you have MS Access
If not then you could run it with the run time version.

Think about it  

I've attached an MBD that will show you what I mean I just did my documents folder to give you an idea

If  filelist.mdb
0
 
LVL 52

Expert Comment

by:Bill Prew
ID: 34966645
==> Check the entire contents of that parent folder for backups on a current or previous date and:

Can you explain this further?  Do you mean you want to check for files based on the day number in the filename?

Or do you want to check the date created of the file from the file information?

~bp
0
 
LVL 14

Accepted Solution

by:
Don Thomson earned 500 total points
ID: 34968699
By using the /t:W  it gives you the date that it was last modified
What I would do is to run the dir command from a cmd windows  exactly as above
Put the MDB file in whatever folder is good for you
Open it
Under Tables do New - Import - file type Text Files  and point it to the filelist.txt
the once the first screen is up goto advanced and click on Specs and chose the one that's there
Click on finish
It imports the list
Goto queries  -- Run the dQry-Cleanup-1  then the dQryCleanup-2
Now you have a ltable called file list that just has the files by name - the date they were last modified and the size (This can be used to determine if the actual backup was successfull or may have been aborted (each location should has a slowly increasing size each week - If you keep track of the sizes from the past week  by renaming the old filelist table to filelistprev - before doing the import of the new one
Then you  can do a query of this weeks sizes against prev sizes and anything that is much lower - you can check manually.

I'm attaching a revised MDB - That has the queries built -
By building a macro that does the import (filelist.txt must always be located in the same place) and then runs the two queries,  it takes about 10 seconds to get your report
 filelist.mdb
0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
LVL 1

Author Closing Comment

by:POINTGREEN
ID: 34970258
works like a champ, automate the file list update, couple quick and dirty reports and Im done. Thanks a ton.
0
 
LVL 14

Expert Comment

by:Don Thomson
ID: 34970365
I tend to use access a lot for small jobs like this - Believe it or not for cases where I have to parse things like this - if it's going to be sonmething that has to be repeated over and over, I still use a program called QBasic -  Develop a quick and dirty - import this - manipluate the data, write it out as a CSV or TXT file and bring it into Access - Sometimes you have all the data you ned - it's just not in a format you can use. Done thousands of these little helpers for clients

Glad I could help
0
 
LVL 1

Author Comment

by:POINTGREEN
ID: 34971900
any hints on the macro to import the Filelist.txt doc daily?
0
 
LVL 1

Author Comment

by:POINTGREEN
ID: 34972609
I can get it to import, but its appending as opposed to overwriting.
0
 
LVL 14

Expert Comment

by:Don Thomson
ID: 34972667
I create a macro that imports the filelist.txt from the root of the D drive    D:\filelist.txt
Open and goto design and change the path if you need to
I added the two queries
Just create a report with the wizard and add it as the 4th with an openreport - and fill in the stuff at the bottom
If you want to play with it - Try inserting a runapp  and call your batch file as your 1st line of the macro
Instert a blank by highlighting the first action and go Insert row from the top

If you create a separate Macro for the Batch file command then you could have Access autoload a form that you create theat has two command buttons - 1 - Get data   2 Process Data



 filelist.mdb
0
 
LVL 14

Expert Comment

by:Don Thomson
ID: 34972694
Rename the old filelist table first to something else - I.E - Archive for week of Feb 11 2011
The other thing if you dont't want to keep the old records is to insert an action before the 1st command that will delete the filelist table  use DeleteOBject  and in the bottom tell it that it's a table and the table name
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

TOMORROW TOMORROW.BAT is inspired by a question I get asked over and over again; that is, "How can I use batch file commands to obtain tomorrow's date?" The crux of this batch file revolves around the XCOPY command - a technique I discovered w…
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 tutorial gives a high-level tour of the interface of Marketo (a marketing automation tool to help businesses track and engage prospective customers and drive them to purchase). You will see the main areas including Marketing Activities, Design …
Internet Business Fax to Email Made Easy - With  eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, f…

895 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now