How to delete files older than x days + what's Powershell?

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
OM3
Posts: 32
Joined: 17 Mar 2014 08:43

How to delete files older than x days + what's Powershell?

#1 Post by OM3 » 29 Jun 2015 13:45

I want to delete files and folders older than xx days

I have found this code:

forfiles -p "C:\what\ever" -s -m *.* /D -<number of days> /C "cmd /c del @path"

But does that delete folders as well?

I also found other code that said it was for Powershell
I've seen Powershell a few times but havent ever looked into
There are 2 versions of the code V2 and V3

The code looks alien to me! Not come across before
Is Powershell better than DOS?

I opened Powershell and typed Dir
It took about 15 seconds to respond and give any output
Am I doing something wrong?

Thanks


OM

ShadowThief
Expert
Posts: 1167
Joined: 06 Sep 2013 21:28
Location: Virginia, United States

Re: How to delete files older than x days + what's Powershel

#2 Post by ShadowThief » 29 Jun 2015 18:22

That code will only delete files, since the delete command doesn't delete folders. If you want to delete folders, use rd instead.

As for PowerShell, it's similar to batch, but can do different things. It's technically a completely different language, and it definitely has its uses. As to whether or not it's better, that's pretty objective. (Although asking this question on somewhere like Stack Overflow would get a pretty overwhelming "yes" response, but this forum is almost exclusively for batch (give or take a little vbscript).) Personally, I recommend batch for everything except doing math with numbers larger than 2^31 or decimals (batch numbers are signed 32-bit integers), or if you need to interact with GUIs (the only PowerShell script I've ever written was to open, move, and resize a bunch of graphs for work).

Post Reply