Solved Does my script delete 30 days after creating or opening?

June 17, 2018 at 09:13:27
Specs: Windows 7
Hi

Can anyone advise me if the script below deletes 30 days after the subfolder amended OR 30 days after it created.

What I need it to do is delete 30 days after the subfolder was created and not 30 days after last opened or amended.

@echo off
:: set folder path
set dump_path=S:\DOWNLOADS

:: set min age of files and folders to delete
set max_days=30

:: remove files from %dump_path%
forfiles -p %dump_path% -m *.* -d -%max_days% -c "cmd  /c del /q @path"

:: remove sub directories from %dump_path%
forfiles -p %dump_path% -d -%max_days% -c "cmd /c IF @isdir == TRUE rd /S /Q @path"


See More: Does my script delete 30 days after creating or opening?

Reply ↓  Report •

✔ Best Answer
June 19, 2018 at 05:46:18
Doing this is VBScript's pretty trivial, especially if you're like me and don't care about file safety at all.
cutOff = Date - 30
For Each dir In CreateObject("Scripting.FileSystemObject").GetFolder("S:\DOWNLOADS").SubFolders
  If dir.DateCreated <= cutoff Then dir.Delete
Next 'dir

How To Ask Questions The Smart Way



#1
June 17, 2018 at 11:32:34
last modified:

i typed forfiles /? in the cmd.exe window & i got:

/D date Selects files with a last modified date greater
than or equal to (+), or less than or equal to
(-), the specified date using the
"MM/dd/yyyy" format; or selects files with a
last modified date greater than or equal to (+)
the current date plus "dd" days, or less than or
equal to (-) the current date minus "dd" days. A
valid "dd" number of days can be any number in
the range of 0 - 32768.
"+" is taken as default sign if not specified.

i5-6600K[delid]@4.8GHz/4.4GHz@1.39v LLC=6 | 2x4GB Crucial-DDR4-2133CL15@14-14-14-30 1T 2800MHz@1.37v
MSI Armor RX 570 4GB@1430Mhz core@1.256v/1900MHz BiosModded


Reply ↓  Report •

#2
June 18, 2018 at 12:08:51
Thanks for that but it deletes the folders 30 days after they were last amended and I need then deleting 30 days after they were created.

a friend told me a VBS script?

I wouldnt have a clue where to start.


Reply ↓  Report •

#3
June 19, 2018 at 02:17:06
i know a way to do it :) give me a day or so, i do not have time to script it right now

i5-6600K[delid]@4.8GHz/4.4GHz@1.39v LLC=6 | 2x4GB Crucial-DDR4-2133CL15@14-14-14-30 1T 2800MHz@1.37v
MSI Armor RX 570 4GB@1430Mhz core@1.256v/1900MHz BiosModded


Reply ↓  Report •

Related Solutions

#4
June 19, 2018 at 05:46:18
✔ Best Answer
Doing this is VBScript's pretty trivial, especially if you're like me and don't care about file safety at all.
cutOff = Date - 30
For Each dir In CreateObject("Scripting.FileSystemObject").GetFolder("S:\DOWNLOADS").SubFolders
  If dir.DateCreated <= cutoff Then dir.Delete
Next 'dir

How To Ask Questions The Smart Way


Reply ↓  Report •

#5
June 19, 2018 at 07:36:20
nice, i would have done a batch for loop --> calling a vbscript checking if creating date(#3 token in dir/AD/B) + 30 would be greater than %date%

mine would take a bit more time to write :)

i5-6600K[delid]@4.8GHz/4.4GHz@1.39v LLC=6 | 2x4GB Crucial-DDR4-2133CL15@14-14-14-30 1T 2800MHz@1.37v
MSI Armor RX 570 4GB@1430Mhz core@1.256v/1900MHz BiosModded


Reply ↓  Report •

#6
June 19, 2018 at 08:54:25
Thanks everyone as helpful as ever...

Spot on Razor . You Legend...

message edited by GDB


Reply ↓  Report •

#7
June 19, 2018 at 10:00:37
Sorry Razor just noted something else im trying too .

The script deletes the folders no problem depending on number of days but I also have 7zip files that are file type "application" in the folder too.

Is there anyway I can get it to delete them too.


Reply ↓  Report •

Ask Question