Batch file to search folder for files based on Date

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. "" where 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?
Who is Participating?
Don ThomsonCommented:
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
Don ThomsonCommented:
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

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
POINTGREENAuthor Commented:
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 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.
Get expert help—faster!

Need expert help—fast? Use the Help Bell for personalized assistance getting answers to your important questions.

POINTGREENAuthor Commented:
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)

Don ThomsonCommented:
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
Bill PrewCommented:
==> 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?

POINTGREENAuthor Commented:
works like a champ, automate the file list update, couple quick and dirty reports and Im done. Thanks a ton.
Don ThomsonCommented:
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
POINTGREENAuthor Commented:
any hints on the macro to import the Filelist.txt doc daily?
POINTGREENAuthor Commented:
I can get it to import, but its appending as opposed to overwriting.
Don ThomsonCommented:
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

Don ThomsonCommented:
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
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.