Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win


Batch file to search folder for files based on Date

Posted on 2011-02-23
Medium Priority
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?
Question by:POINTGREEN
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
  • 6
  • 5
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

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

Author Comment

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.

Author Comment

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)

Veeam Disaster Recovery in Microsoft Azure

Veeam PN for Microsoft Azure is a FREE solution designed to simplify and automate the setup of a DR site in Microsoft Azure using lightweight software-defined networking. It reduces the complexity of VPN deployments and is designed for businesses of ALL sizes.

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
LVL 58

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?

LVL 14

Accepted Solution

Don Thomson earned 2000 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

Author Closing Comment

ID: 34970258
works like a champ, automate the file list update, couple quick and dirty reports and Im done. Thanks a ton.
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

Author Comment

ID: 34971900
any hints on the macro to import the Filelist.txt doc daily?

Author Comment

ID: 34972609
I can get it to import, but its appending as opposed to overwriting.
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

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

Featured Post

Enroll in October's Free Course of the Month

Do you work with and analyze data? Enroll in October's Course of the Month for 7+ hours of SQL training, allowing you to quickly and efficiently store or retrieve data. It's free for Premium Members, Team Accounts, and Qualified Experts!

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…
Introduction: Recently, I got a requirement to zip all files individually with batch file script in Windows OS. I don't know much about scripting, but I searched Google and found a lot of examples and websites to complete my task. Finally, I was ab…
This course is ideal for IT System Administrators working with VMware vSphere and its associated products in their company infrastructure. This course teaches you how to install and maintain this virtualization technology to store data, prevent vuln…
Visualize your data even better in Access queries. Given a date and a value, this lesson shows how to compare that value with the previous value, calculate the difference, and display a circle if the value is the same, an up triangle if it increased…
Suggested Courses

609 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