Jump to content
Sign in to follow this  

Delete Files Older Than with One Line of Code

Recommended Posts

The single line of code below will delete files over seven days old. Additionally, it runs without the Windows Command Shell opening.

The only configuration required is the path to the directory, i.e., C:\PROGRA~1\ABC\Data\Archive. Long file names (C:\Program Files\ABC\Data\Archive) work, as well.

To review additional options for "forfiles," Google is your friend.

Run(@ComSpec & " /c " & "forfiles /p ""C:\PROGRA~1\ABC\Data\Archive"" /s /m *.* /c ""cmd /c Del @path"" /d -7", @SystemDir, @SW_HIDE)

Share this post

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

  • Recently Browsing   0 members

    No registered users viewing this page.

  • Create New...