|
| ||||||||||
| Tags: batch file, delete file, directory, script, windows explorer, zipped file |
![]() |
| | Thread Tools | Search this Thread |
|
#1
| |||
| |||
| Script needed to Delete Files in a Directory Based on Date
having tremendous difficulty opening such folder, even when it displays results (after 10 or so minutes) it hangs after I even highlight any files for deletion. a lot of these files go back to 2006 and 2007. I kindly NEED a DOS batch file or some script that I would enable me to delete the files that are older than may 2008 (In other words delete files between May 2008 and May 2006). Thank You, and your efforts are much appreciated in advance. |
|
#2
| |||
| |||
|
Try this script, written by Tom Lavedas and myself. It will delete files older than 120 days. sFolder = "d:\temp\" iMaxAge = 120 Set oFSO = CreateObject("Scripting.FileSystemObject") If oFSO.FolderExists(sFolder) Then for each oFile in oFSO.GetFolder(sFolder).Files If DateDiff("d", oFile.DateLastModified, Now) > iMaxAge Then wscript.echo "Deleting oFile.Name" ' oFile.Delete End If next End If Run the script in its current form. When you're happy with the result, activate it by removing the single quote from this line: ' oFile.Delete Tiny typo in the echo line, it should read ... wscript.echo "Deleting", oFile.Name |
|
#3
| |||
| |||
|
You could always use forfiles.exe. Here is a guide on using it with a working example. I ahve used it and it works great forfiles.exe comes with server 2003 or is downloadable from the server 200 resource kit. |
|
#4
| |||
| |||
| Re: Script needed to Delete Files in a Directory Based on Date
Im a newbie in creating script..I would like to ask if you can provide me a script that can be turn into a dos.bat file that I can run on my windows xp pc that will delete txt files older than 30 days my working directory is d:\temp . |
|
#5
| |||
| |||
| Re: Script needed to Delete Files in a Directory Based on Date
This script will delete all files that are not modified in n days within the directory structure d. Code: # Script DeleteFiles.txt
var str d, n, list, file
lf -r -n "*" $d (($ftype=="f") AND ($fmtime < addtime(diff("-"+$n)))) > $list
while ($list <> "")
do
lex "1" $list > $file
system del ("\""+$file+"\"")
echo -e "DEBUG: Deleted file " $file
done s Code: cript "C:/Scripts/DeleteFiles.txt" d("d:/temp") n("30") |
|
#6
| |||
| |||
| Re: Script needed to Delete Files in a Directory Based on Date
But is there a way that it can be made into a Dos bat file so that it can be executed once i double click it? |
|
#7
| |||
| |||
| Re: Script needed to Delete Files in a Directory Based on Date
Yes, there is a way to execute this script with a double-click. Create an icon on the desktop, and assign it this command. Code: "C:/biterscripting/biterscripting.ex" "C:/Scripts/DeleteFiles.txt" d("d:/temp") n("30") - There was an error in my first post - the first letter of the script command - s - somehow appears outside the code block. Now, I can not fix it. But, I am sure you figured it out. So, the correct command to execute the script interactively is - Code: script "C:/Scripts/DeleteFiles.txt" d("d:/temp") n("30") Last edited by ranjankumar09 : 13-03-2010 at 01:05 AM. |
|
#8
| |||
| |||
| Re: Script needed to Delete Files in a Directory Based on Date
Hi I want a script which will delete a file or folder or a drive on a date. Example: delete a file called " deleteit.txt" on date 8-20-2010 and the date should be future date , it means if todays date is 8-18-2010 i want a delete a file or folder or drive on 8-25-2010 Thanks. Yellowblock. |
|
#9
| |||
| |||
| Re: Script needed to Delete Files in a Directory Based on Date
@ Yellowblock Quote:
Here is a script Code: # Script Delete7days.txt
# Input arguments - drive letter, file name
var string drive, name
# Other variables
var string list, file, targettime
# Check if arguments assigned.
if ($drive=="") or ($name=="")
exit 1 "Error: Input arguments not assigned. Usage: script "Delete7days.txt" drive("D:/") file("deleteit.txt")
endif
# Target time is now - 7 days.
set $targettime = addtime( diff("-7000000") )
# Get a list of files that were modified earlier than $targettime.
lf -r -n $name $drive ($fmtime < $targettime) > $list
# Delete file.
while ($list <> "")
do
lex "1" $list > $file
system delete ("\""+$file+"\"")
done The "-7000000" means subtract 7 days, 00 hours, 00 mins, 00 seconds from current time. See the documentation for function addtime(). Save the script in file C:/Scripts/Delete7days.txt. Create a shortcut on desktop and assign it this command. Code: "C:/biterscripting/biterscripting.ex" "C:/Scripts/Delete7days.txt" drive("D:/
") name("deleteit.txt") |
|
#10
| |||
| |||
| Re: Script needed to Delete Files in a Directory Based on Date
I have folders named according to date format like 14Mar2011, 13Mar2011 so I want a script that deletes files older than 10 days thank you |
|
#11
| |||
| |||
| Re: Script needed to Delete Files in a Directory Based on Date
You can try to make use fo the script below and see if that helps you. This script will delete the files which are older than 120 days. You can change this value according to your need. Quote:
' oFile.Delete |
|
#12
| |||
| |||
| Re: Script needed to Delete Files in a Directory Based on Date Quote:
yo dude this works very fine but how do you make it instead of deleting a file, to run an .exe file after the specified time for example: after 30 days to RUN C:\folder\my.exe please reply |
![]() |
|
| Thread Tools | Search this Thread |
| |
Similar Threads for: "Script needed to Delete Files in a Directory Based on Date" | ||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Delete files based on creation date? | Hank Arnold (MVP) | Windows Server Help | 2 | 19-10-2010 12:55 AM |
| Batch script to delete directory | Logan 2 | Software Development | 4 | 01-04-2010 12:31 PM |
| Create new folder and move files based on creation date | dstiff | Windows Server Help | 3 | 13-11-2009 04:04 AM |
| Delete files with logoff/on script | Pine Le | Windows Security | 1 | 03-06-2008 11:19 PM |
| Need a script to delete temporary ASP.NET files | Mak66 | Windows Server Help | 2 | 13-02-2008 06:00 PM |