Script needed to Delete Files in a Directory Based on Date
I have a folder that contains about 250,000 zipped files. Windows explorer is
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.
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 .
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
Script is in biterscripting can be download if you don't have it). Save the script in file C:/Scripts/DeleteFiles.txt. Kick off the script by typing this command into biterscripting.
s
Code:
cript "C:/Scripts/DeleteFiles.txt" d("d:/temp") n("30")
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?
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")
Then when you double click this icon, the script will be executed. (Basically, we are replacing the command word 'script' with path to biterscripting executable. This works with all scripts. I often do that.)
- 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")
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.
Re: Script needed to Delete Files in a Directory Based on Date
@ Yellowblock
Quote:
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
I am not sure if I fully understand, but sounds to me that you want to delete a file "deleteit.txt" that is a week old. There are multiple files called "deleteit.txt" on the drive, and you want to delete the one that was last modified a week ago.
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")
Each time you double click this icon, it will delete the file "deleteit.txt" that was modified 7 days ago from drive D:/.
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
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:
myfolder = "d:\temp\"
iMaxAge = 120
Set oFSO = CreateObject("Scripting.FileSystemObject")
If oFSO.FolderExists(myfolder) Then
for each oFile in oFSO.GetFolder(myfolder).Files
If DateDiff("d", oFile.DateLastModified, Now) > iMaxAge Then
wscript.echo "Deleting oFile.Name"
' oFile.Delete
End If
next
End If
After running this, if you are happy by the effect then you can activate this taking out the single quote from line
' oFile.Delete
Re: Script needed to Delete Files in a Directory Based on Date
Quote:
Originally Posted by
Pegasus \(MVP\)
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
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