Solved

Forefiles Script

Posted on 2014-10-15
9
246 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
  • 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
 

Author Comment

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

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

 

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 83

Accepted Solution

by:
oBdA earned 500 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

Control application downtime with dependency maps

Visualize the interdependencies between application components better with Applications Manager's automated application discovery and dependency mapping feature. Resolve performance issues faster by quickly isolating problematic components.

Question has a verified solution.

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

Suggested Solutions

Not long ago I saw a question in the VB Script forum that I thought would not take much time. You can read that question (Question ID  (http://www.experts-exchange.com/Programming/Languages/Visual_Basic/VB_Script/Q_28455246.html)28455246) Here (http…
The recent Microsoft changes on update philosophy for Windows pre-10 and their impact on existing WSUS implementations.
This tutorial will show how to configure a new Backup Exec 2012 server and move an existing database to that server with the use of the BEUtility. Install Backup Exec 2012 on the new server and apply all of the latest hotfixes and service packs. The…
This Micro Tutorial hows how you can integrate  Mac OSX to a Windows Active Directory Domain. Apple has made it easy to allow users to bind their macs to a windows domain with relative ease. The following video show how to bind OSX Mavericks to …

867 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

Need Help in Real-Time?

Connect with top rated Experts

26 Experts available now in Live!

Get 1:1 Help Now