Solved

how do I filter for all files in a folder created on a particular day of week?

Posted on 2014-09-28
22
218 Views
Last Modified: 2014-10-27
Hi Experts,
I have a folder that its used to store daily backup files, now once in a while I want to get rid of all files and week only each 7th file, is there a way to get windows to list only the files created on Sundays for example?
0
Comment
Question by:bfuchs
  • 10
  • 10
  • 2
22 Comments
 
LVL 90

Expert Comment

by:John Hurst
ID: 40348984
In your other question about file size, I suggested Tree Size (Jam Software). This will do what you want I think.

Also you can you Windows Explorer.

Now both tools show date changed and optionally date created.  Neither tool (I am looking at Tree Size just) have a column for day of week.

So then you need to sort and then select out what you want to delete.

I have look at the columns you can get in Windows Explorer and that does not include day of week.
0
 
LVL 3

Author Comment

by:bfuchs
ID: 40349114
Hi John,
Thanks for replying,
I am still in middle of experimenting those  software mentioned there, will keep you posted.
Re this question, are you sure there is no easy way to accomplish this, as I do have hundreds of files accumulated, it would be tough to have to do it manually..
0
 
LVL 90

Expert Comment

by:John Hurst
ID: 40349120
I have checked thoroughly through Explorer, Tree Size, Total Commander and good old DIR and do not see any way to get Day of Week displayed. I think only several different dates are kept (changed, created, etc.).  

You would probably have to run DIR to a file, load the file into program to extract day of week, filter for the day, and then output a batch file to delete the results.
0
 
LVL 24

Expert Comment

by:lionelmm
ID: 40349686
agreed--if you use vbscripts or powershell getting the day of week is possible--however if you want to run a batch file, have it prompt you for a date then you enter the date (a Sunday's date) then it will delete all the files that match that date. but as mentioned above apps like WinDir and TreeSize and even Windows explorer can search for files based on a date and then you can see them and delete them.
0
 
LVL 3

Author Comment

by:bfuchs
ID: 40350945
I guess my option would be to create a module that accepts a name of a folder and run a loop for each file, check date created if its not a sunday, delete it..
Just wonder what do other people do, those in charge of keeping backups..do they keep all backup files? in my case each file takes approx a half a GIG...
0
 
LVL 24

Expert Comment

by:lionelmm
ID: 40351946
No I actually have a script that runs and keeps 30 days worth of backup files--in your case that may be too much so you may only want to keep xx amount--and then let the script run at the end of your backup script and remove any file over the amount of xx. Let me know if that is what you want and I will post that script for you.
0
 
LVL 3

Author Comment

by:bfuchs
ID: 40353051
Hi lionelmm,

What I need is to keep every seventh file, but of all years, this way when users request to see what was at a certain point of time, I can go and retrieve it.

Thanks,
Ben
0
 
LVL 24

Expert Comment

by:lionelmm
ID: 40353586
How are the files you want saved named? For instance is it 2014-09-30.bkf? I am going to have to think how to pick each 7th file--are you saying for instance you want each backup from Friday to be moved to a different folder and saved--if yes then we can use a scheduled task to do that
0
 
LVL 3

Author Comment

by:bfuchs
ID: 40357873
Hi lionelmm,
Sorry for not responding timely, its just that our server went down and we are working almost around the clock to get this setup...
I hope to follow up on this next week,
have a nice weekend!
0
 
LVL 24

Expert Comment

by:lionelmm
ID: 40358270
good luck--worst job in the world--trying to recover a crashed server.
0
 
LVL 3

Author Comment

by:bfuchs
ID: 40390878
Hi lionelmm,

We finally got our information back,
(I took some vacation afterwards..)

Re your question,
I have 2 different programs saving them in 2 ways.
1- name of the file plus seq# (for example bakup001, backup002, backup003 and so on.)
2- name of the file plus current date and time in YYYYMMDDHHMM format (bakup_200410190300, bakup_200410200300)

Thanks,
Ben
0
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 
LVL 24

Expert Comment

by:lionelmm
ID: 40390990
are you saying for instance you want each backup from Friday to be moved to a different folder and saved?
0
 
LVL 3

Author Comment

by:bfuchs
ID: 40391014
yes, that would also work, I was thinking from just deleting the other 6, however which is easier for you..
0
 
LVL 24

Expert Comment

by:lionelmm
ID: 40391871
Well I know of two ways to do this and since you want to delete them instead of moving I will give you once better suited to that. However you you want to delete and not move keep in mind that the next week when your scheduled task runs then the file you just saved for this week will be deleted the following week

set Dir1=C:\YourFolderLocation
for /F "tokens=* skip=1" %%A in ('dir /b /a-d /o-d "%Dir1%\*.bkf"') do del "%Dir1%\%%~A"
This command will delete all files except the most recent ONE so there will be only one file left; put this in a batch file and schedule it to run the batch file once every week. If you prefer to move it instead let me know and I will give you another script.
0
 
LVL 3

Author Comment

by:bfuchs
ID: 40392791
hi lionelmm,
The story is as follows, I am in change of cleaning that directory once in a while, (usually when the backup drive gets full..), at that time I have hundreds of daily backup files and only need to keep each 7th one, therefore, I don't think the above would help as it will leave me with one file only.
0
 
LVL 24

Expert Comment

by:lionelmm
ID: 40392922
Well this is not something you would do once in awhile you would run it once a week, on the day of the week which you want to keep. You can then move it to another location (which was my previous suggestion) and then next week it would move the next and so on and so on. At the end of the year you would then have 52 copies. You can also use this to keep 30 files (or 60 or 90 or 120)
set Dir1=C:\YourFolderLocation
for /F "tokens=* skip=30" %%A in ('dir /b /a-d /o-d "%Dir1%\*.bkf"') do del "%Dir1%\%%~A"
and then use this to move one
Set MoveIt=dir "%dir1%*.bkf" /OD /A-D /B
for /F "tokens=* delims= " %%i in ('%MoveIt%') do Move /y %MoveIt% C:\SaveLocation
0
 
LVL 24

Expert Comment

by:lionelmm
ID: 40393064
correction
Set MoveIt=dir "%dir1%*.bkf" /OD /A-D /B
should be
Set MoveIt=dir "%dir1%\*.bkf" /OD /A-D /B
0
 
LVL 3

Author Comment

by:bfuchs
ID: 40393358
OK, just to clarify, you're saying I should save (in one batch file) and run the below once a week and I will end up with 52 yearly?

set Dir1=C:\MyLocation
 for /F "tokens=* skip=1" %%A in ('dir /b /a-d /o-d "%Dir1%\*.bkf"') do del "%Dir1%\%%~A"

 Set MoveIt=dir "%dir1%\*.bkf" /OD /A-D /B
 for /F "tokens=* delims= " %%i in ('%MoveIt%') do Move /y %MoveIt% C:\SaveLocation

also is it possible you should explain how that works?
and one more thing, how can I test it before using it in production, can I copy the entire contents of the backup folder into a test folder and run it from there, or they will all be considered created at the same day?
0
 
LVL 24

Accepted Solution

by:
lionelmm earned 500 total points
ID: 40394303
This command wil delete all the files except the latest/newest--the "skip=1" is what controls that; if you want to save 30, or 60 or 90 adjust that to "skip=30" for example
set Dir1=C:\MyLocation
 for /F "tokens=* skip=1" %%A in ('dir /b /a-d /o-d "%Dir1%\*.bkf"') do del "%Dir1%\%%~A"
'dir /b /a-d /o-d "%Dir1%\*.bkf" this arranges the files in date order for parsing through it
do del "%Dir1%\%%~A" this does the deleting--you can use do echo del "%Dir1%\%%~A" to test--it will only show (echo) what it will delete but still I would test it on a copy folder rather than the live folder

and yes if you run this once a week say every friday then at the end of the year you will end up with 52 copies of the files in the C:\SaveLocation
0
 
LVL 3

Author Closing Comment

by:bfuchs
ID: 40405246
Thanks very much  lionelmm, I hope to test it at my next opportunity, will let you know if I encounter any issues.
BTW, you didn't answer what happens when I copy an entire folder, will that work for test or all files are considered as created the same date/time?
0
 
LVL 24

Expert Comment

by:lionelmm
ID: 40406207
IF the dates are all the same then this will still work by keeping only the number you specify (30, 60, 90) but that may not be the the most recent files--if you want something that will look at the create date (which is different than what I have given you here) then you will need a different script a VB or powershell script.
0
 
LVL 3

Author Comment

by:bfuchs
ID: 40407715
Thank you!
0

Featured Post

Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Suggested Solutions

This article is meant to give a basic understanding of how to use R Sweave as a way to merge LaTeX and R code seamlessly into one presentable document.
This is an explanation of a simple data model to help parse a JSON feed
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …
In this fourth video of the Xpdf series, we discuss and demonstrate the PDFinfo utility, which retrieves the contents of a PDF's Info Dictionary, as well as some other information, including the page count. We show how to isolate the page count in a…

758 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

20 Experts available now in Live!

Get 1:1 Help Now