Solved

Forefiles Script

Posted on 2014-10-15
9
241 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
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 

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

Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
Nmap how to find wich type of socks is this? 4 69
Do we need servers??? 5 131
Automate switch config backup 3 17
GPO Delegation 4 11
How to remove superseded packages in windows w60 or w61 installation media (.wim) or online system to prevent unnecessary space. w60 means Windows Vista or Windows Server 2008. w61 means Windows 7 or Windows Server 2008 R2. There are various …
Use this article to create a batch file to backup a Microsoft SQL Server database to a Windows folder.  The folder can be on the local hard drive or on a network share.  This batch file will query the SQL server to get the current date & time and wi…
This tutorial will show how to push an installation of Backup Exec to an additional server in both 2012 and 2014 versions of the software. Click on the Backup Exec button in the upper left corner. From here, select Installation and Licensing, then I…
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…

706 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

20 Experts available now in Live!

Get 1:1 Help Now