Windows 7 Forums
Welcome to Windows 7 Forums. Our forum is dedicated to helping you find support and solutions for any problems regarding your Windows 7 PC be it Dell, HP, Acer, Asus or a custom build. We also provide an extensive Windows 7 tutorial section that covers a wide range of tips and tricks.

Windows 7: Batch file counting dates compare

08 Jun 2014   #1

Windows 7 Ultimate Edition (64-bit) Service Pack 1
Batch file counting dates compare

Hello everyone,

Don`t know for sure if this is the correct place to put this question just tell me where else

I have a problem with a batch file.
I made a file that renames files to the date when I log off.
But I also want to let it clean files that are older than a month.
I thought I was able to make it happen just take the month minus 1 and compare names.

Although seems I can`t do a minus one in batch, searched alot over the internet.
Does anyone know a different way so I can compare file names to delete old logs?

Hope to hear something soon.

My System SpecsSystem Spec
08 Jun 2014   #2

Windows 10 Pro X64

Here is a good, short tutorial on basic math in Batch files: Batch files - Math
My System SpecsSystem Spec
09 Jun 2014   #3

Windows 7 Ultimate Edition (64-bit) Service Pack 1

Thx for the help just the site I needed.
Now I just solved my problem in a different way with forfiles.
Works alot easier as it already has a date function in it.

Now I clean the files as followed:
forfiles /p "D:\Logging" /s /m *.txt /c "cmd /c Del @path" /d -30

But again thx for the help will come in handy in the future.
My System SpecsSystem Spec

09 Jun 2014   #4

Windows 10 Pro X64

Very cool. I have never heard of forfiles before and I've been doing this for a long time. The /d is a great parameter.

Thanks for the info.

Edit: Ah, I see forfiles was introduced in Windows Vista. Does not exist in XP or earlier.
My System SpecsSystem Spec

 Batch file counting dates compare

Thread Tools

Similar help and support threads
Thread Forum
Contradictory file dates in Windows 7 File Explorer when I use search
Contradictory file dates in Windows 7 File Explorer when I use "Search My Documents" with *.docx I modified a Word file earlier today. When I view the file in File Explorer the correct file date/time is displayed, however when I search for Word files by entering *.docx in the "Search My...
General Discussion
How to run a batch file at logoff & some batch scripting help please
Hiya, I'd just like to run a simple batch file at logoff to backup some settings. I plan to use Robocopy, which is what i use to more thorough backups. Two questions: 1. How make it run by clicking Start > Shutdown? (i realise i could make a shutdown batch file and run it instead, but i'd...
Backup and Restore
Batch File that grabs file names from folder to insert into batch file
Ok I'm totally at a loss on how to word this so I'm just going to write it out the best that I can... :confused: First I have a batch file that I'm writing that will convert mp4 files to mp3 files (I have a lot) for a buddies band using ffmpeg. Here's the code that I'm using: ffmpeg -i...
General Discussion
Need duplicate file finder, compare and delete
Hello, I have a hard drive that has all sorts of archives of archives in it. So many, that I think I have duplicates of many files. They are not compressed or anything. I would like a program to go through the HD and pick out the duplicates and preferrably, automatically delete the oldest...
File folders and names with BC/AD dates
I'm trying to create a set of directories that show art from various eras. I want them to appear in chronological order. Thus, I want the BC years to proceed backward to 0 and then forward again after AD. I've tried putting negative numbers in front of the dates but this doesn't seem to help. Any...
General Discussion

Our Sites

Site Links

About Us

Find Us

Windows 7 Forums is an independent web site and has not been authorized, sponsored, or otherwise approved by Microsoft Corporation. "Windows 7" and related materials are trademarks of Microsoft Corp.

Designer Media Ltd

All times are GMT -5. The time now is 14:59.
Twitter Facebook Google+