tags:

views:

368

answers:

3

Hello i use the following command to delete files older than X days [%numb% is de amount of days]

forfiles -p "%temp%" -s -m *.* -d %numb% -c "cmd /c del @path"

Still..

When i execute it it just promps me with all features of forfiles and how it should be used... Help?

+1  A: 

One guess, since you haven't given much information, is if you're not on 2003/Vista, then you should not have a space after each parameter:

forfiles -p"%temp%" -s -m*.* -d%numb% -c"cmd /c del @path"

It's also possible your substitution parameters are not working as expected. I find it helpful often to prefix the command with "echo" to see what's actually being processed:

echo forfiles -p "%temp%" -s -m *.* -d %numb% -c "cmd /c del @path"
lavinio
A: 

Hi -

You may want to change your "DEL @path" to "echo @path" until you get the kinks worked out...

On my XPsp3 machine, I noticed that a hyphen before the number of days (%numb%) was important. So, this:

forfiles -p "%temp%" -s -m *.* -d 30 -c "cmd /c echo @path"

yeilded this: ERROR: No files found with the specified search criteria.

but this:

forfiles -p "%temp%" -s -m *.* -d -30 -c "cmd /c echo @path"

gave me a directory listing

RobW
thanks, is giving a lot of goodness... i think the before command actually said to look 30 days next... haha.
YourComputerHelpZ
A: 

Natively, you can use vbscript. this example, num days is 30

Set objFS = CreateObject("Scripting.FileSystemObject")
strFolder = "c:\test"
numdays=30
today=Now
Set objFolder = objFS.GetFolder(strFolder)
Go (objFolder)
Sub Go(objDIR)
  If objDIR <> "\System Volume Information" Then
    For Each eFolder in objDIR.SubFolders
        Go eFolder
    Next
    For Each strFile In objDIR.Files
        If DateDiff("d",strFile.DateLastModified,today) >= numdays Then
        WScript.Echo "file found that is 1 month old or more: " & strFile
        'objFSO.DeleteFile(strFile) 'uncomment to use
        End If 
    Next 
  End If  
End Sub
ghostdog74