Computer Hope

Microsoft => Microsoft DOS => Topic started by: JTS on June 15, 2009, 12:15:35 PM

Title: Can I use FORFILES to remove folders of files?
Post by: JTS on June 15, 2009, 12:15:35 PM
I have a backup script that places the backup file into a current date folder.  I want to use a script to say truncate all folders that are earlier than 30 days from today's date

I do have a FORFILES script but it appears it is for files only.  Is there a syntax to delete groups of folders based on the file system create date?

Thanks
Title: Re: Can I use FORFILES to remove folders of files?
Post by: ALAN_BR on June 15, 2009, 12:56:22 PM
"FORFILES script" is not a specific description., but Google found :-
http://www.pcreview.co.uk/forums/thread-1466456.php

That was posted by someone who wished to avoid the default action of deleting Folders as well as files - i.e. he did not like the default which you seem to require.

Regards
Alan
Title: Re: Can I use FORFILES to remove folders of files?
Post by: JTS on June 15, 2009, 02:23:52 PM
Ok then what DOS command would I use to delete folders with files after x given days...

Title: Re: Can I use FORFILES to remove folders of files?
Post by: gh0std0g74 on June 15, 2009, 06:46:32 PM
if its possible, you can download findutils (see my sig), and use the find command (different from Windows own find command)
Code: [Select]
c:\test> find c:\test -type f -mtime +1 -delete

the above delete files more than 1 day old. adjust as needed.
Title: Re: Can I use FORFILES to remove folders of files?
Post by: JTS on August 21, 2009, 10:02:26 AM
BAM01 gave me this..

Haven't tried this yet but it's supposed to move files to a second folder if they are 365 days old

forfiles /p E:\path /m *.* /d -365 /c "cmd /c move @file e:\DELETE.FILES"




Will try it out.
Title: Re: Can I use FORFILES to remove folders of files?
Post by: billrich on August 23, 2009, 08:26:50 AM

C:\>rmdir /?
Removes (deletes) a directory.

RMDIR [/S] [/Q] [drive:]path
RD [/S] [/Q] [drive:]path

    /S      Removes all directories and files in the specified directory
            in addition to the directory itself.  Used to remove a directory
            tree.

    /Q      Quiet mode, do not ask if ok to remove a directory tree with /S

C:\>
Title: Re: Can I use FORFILES to remove folders of files?
Post by: gh0std0g74 on August 28, 2009, 06:27:29 AM
C:\>rmdir /?
Removes (deletes) a directory.
it just removes directory, but does not check for X days to delete. extra code is needed.