?
Solved

Forefiles Script

Posted on 2014-10-15
9
Medium Priority
?
258 Views
Last Modified: 2014-10-15
I have a script to delete files older than 3 months but it suddenly stopped working?  I'm not sure what's going on..
Here's the script:
Forfiles -p"D:\share\share\share" -s -m*.* -d-3 -c"CMD /c Del @File  : date -30 days"
I'm getting an error that says invalid arguement/option -pD:\...
0
Comment
Question by:WellingtonIS
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 5
  • 3
9 Comments
 
LVL 43

Expert Comment

by:Steve Knight
ID: 40382060
Looks to me just like a space missing beteen the /p and first " of the path though difficult to tell on mobile.


Steve
0
 

Author Comment

by:WellingtonIS
ID: 40382070
No I don't think there's supposed to a space there.
0
 
LVL 43

Expert Comment

by:Steve Knight
ID: 40382111
Have you tried?  on my PC it errors if there isn't:

C:\Users\stephen>forfiles /p "d:"
"$RECYCLE.BIN"
"IBM Support.pdf"
"MS_Learning_Transcript.PDF"
"TrialPrice.xlsx"

C:\Users\stephen>forfiles /p"d:"
ERROR: Invalid argument/option - '/pd:'.
Type "FORFILES /?" for usage.
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:WellingtonIS
ID: 40382124
yes.  I think I found my issue. I'll let you know - thanks
0
 

Author Comment

by:WellingtonIS
ID: 40382139
Nope it didn't work.  I need something to run every 30 days to delete files older than 3 months.  Thats what this was doing.  I'm just not sure what went wrong suddnely
0
 
LVL 85

Accepted Solution

by:
oBdA earned 2000 total points
ID: 40382500
Several issues. You do need a space after each option (tested on Server 2008 R2 and Windows 7), you should use a slash for the options (makes it easier to read, since the date specifiers accept a "-" as well), and most of all, since you're recursing, you need @Path, not @File. Finally, the "  : date -30 days" doesn't throw an error, but it has nothing lost in the command line.
And if you want to delete files older then 3 months, you need (about) "/d -90", not /d-3.
Try if this works for you; it will only display the files in question, not delete anything. Replace the "ECHO" with "DEL" to run it for real:
forfiles.exe /p "D:\share\share\share" /s /m *.* /d -90 /c "CMD /c ECHO @Path"

Open in new window

0
 
LVL 43

Expert Comment

by:Steve Knight
ID: 40382512
thanks oBdA, helps when sitting at a PC then trying to remember settings... I didn't look at the rest since the error was related to the space and the command apparently worked before!

Steve
0
 

Author Comment

by:WellingtonIS
ID: 40382534
Many thanks I'll try it.
0
 

Author Closing Comment

by:WellingtonIS
ID: 40382553
Thanks - I'll set this up to run once a month.
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Background Information Recently I have fixed file server permission issues for one of my client. The client has 1800 users and one Windows Server 2008 R2 domain joined file server with 12 TB of data, 250+ shared folders and the folder structure i…
Possible fixes for Windows 7 and Windows Server 2008 updating problem. Solutions mentioned are from Microsoft themselves. I started a case with them from our Microsoft Silver Partner option to open a case and get direct support from Microsoft. If s…
This tutorial will give a short introduction and overview of Backup Exec 2012 and how to navigate and perform basic functions. Click on the Backup Exec button in the upper left corner. From here, are global settings for the application such as conne…
This tutorial will walk an individual through the steps necessary to enable the VMware\Hyper-V licensed feature of Backup Exec 2012. In addition, how to add a VMware server and configure a backup job. The first step is to acquire the necessary licen…
Suggested Courses

752 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question