Emptying Folder Scripts
I need a .bat script to empty folders everyday through scheduled tasks. I have tried out several through MS technet and several others on the web. In the moment the job runs I can barely make out the error that DeleteFile command the script calls is not recognized. Is there a library I have to install? Here is the last script I tried.
Set objFSO = CreateObject("Scripting.FileSystemObject")
objFSO.DeleteFile("FOLDER PATH GOES HERE")
Anyone have a tried and true script or any solution to schedule a task to empty a folder each day?
Thanks
Set objFSO = CreateObject("Scripting.FileSystemObject")
objFSO.DeleteFile("FOLDER PATH GOES HERE")
Anyone have a tried and true script or any solution to schedule a task to empty a folder each day?
Thanks
Comments
-
BeaverC32 Member Posts: 670 ■■■□□□□□□□Do you need to empty a single folder or multiple folders?
I created a basic batch file on my home PC to clear downloads out of a folder every week.
I just CD to the directory, and delete everything (without prompting).
It looks like this:
CD [Path to directory]
DEL * /QMCSE 2003, MCSA 2003, LPIC-1, MCP, MCTS: Vista Config, MCTS: SQL Server 2005, CCNA, A+, Network+, Server+, Security+, Linux+, BSCS (Information Systems) -
nooch511 Member Posts: 11 ■□□□□□□□□□CD [Path to directory]
DEL * /Q
This is in a .bat correct? I do need to empty out about 4 dozen folders, but planned to create a job for each folder. Right now I am just testing to do one folder. I'll give the above a try. Thanks -
BeaverC32 Member Posts: 670 ■■■□□□□□□□Yeah, just a regular plain-old .bat file.
Rather than having 48 scheduled tasks, you could always include all folders in a single batch file.
You could manually change to a directory, delete the files, change to the next directory, delete those files, etc., and then create a single task to run that batch file.
There is probably an easier way to do it, but that's what I knowMCSE 2003, MCSA 2003, LPIC-1, MCP, MCTS: Vista Config, MCTS: SQL Server 2005, CCNA, A+, Network+, Server+, Security+, Linux+, BSCS (Information Systems) -
nooch511 Member Posts: 11 ■□□□□□□□□□That worked perfectly. After surfing and testing for 4 hours. it was as simple as
CD [Path to directory]
DEL * /Q
Microsoft need to re-visit.
Beaver, you should post that on their forum. -
BeaverC32 Member Posts: 670 ■■■□□□□□□□Feel free to post the solution yourself if you'd like. Otherwise, post a link and I will
Glad it worked out for you. It reminds me of a time in my UNIX programming class where our professor was explaining some long-winded solution to a problem. I raised my hand and was like "umm...I was able to get the same result with 5 lines of code".MCSE 2003, MCSA 2003, LPIC-1, MCP, MCTS: Vista Config, MCTS: SQL Server 2005, CCNA, A+, Network+, Server+, Security+, Linux+, BSCS (Information Systems) -
nooch511 Member Posts: 11 ■□□□□□□□□□Professors and their long winding coding! I hated it.
http://www.microsoft.com/technet/scriptcenter/scripts/msh/default.mspx?mfr=true
Here is around where I found MS Scripts.
Thanks again