General discussion

Locked

Command to delete files older than 1 day

By michelle_lovejoy ·
I would like to run a batch file to delete certain files that are older the 1 day on an NT Server. Does anyone know the syntax that I can use for this?

This conversation is currently closed to new comments.

7 total posts (Page 1 of 1)  
| Thread display: Collapse - | Expand +

All Comments

Collapse -

Command to delete files older than 1 day

by way_good_Guy In reply to Command to delete files o ...

There is no batch file to do it, but qbasic is on all nt platforms, you can write qbasic bas routine to do it
Make a call to attrib and read results
or
Use a windows scripting tool to get file properties.

Collapse -

Command to delete files older than 1 day

by michelle_lovejoy In reply to Command to delete files o ...

The question was auto-closed by TechRepublic

Collapse -

Command to delete files older than 1 day

by DC1 In reply to Command to delete files o ...

Try the following VB code.

Dim objArgs

Set objArgs = WScript.Arguments
on error resume next

intDays = objArgs(0)

wscript.echo "deleting files older than " & intDays & " days old."
Dim fso
Set fso = CreateObject("Scripting.FileSystemObject")

Set f = fso.GetFolder("c:your directory here")
Set fc = f.Files
For Each f1 in fc
modDate = f1.DateLastModified
sysDate = Date

If DateDiff("d", modDate, sysDate) >= Cint(intDays) then
f1.delete
End if
Next

Check on MSDN.microsoft.com for other vbscripts for admin tasks like these

Collapse -

Command to delete files older than 1 day

by michelle_lovejoy In reply to Command to delete files o ...

The question was auto-closed by TechRepublic

Collapse -

Command to delete files older than 1 day

by McKayTech In reply to Command to delete files o ...

This is kind of a funky workaround, but the xcopy command will copy all the files of a certain date and forward so you could theoretically copy the files you want to keep to a safe location, delete all the files in the original location and then copy the good ones back.

Or you could use the /L switch with xcopy to populate a list of the files to save and then run that list through a batch file using exception logic.

Or you could use DIR /TA > filelist.txt to populate a list of files by last access time (or /TC for creation date/time or /TW for last time written), run that list through a sort and then use that to run the delete process.

Gee, that VB script is starting to look awfully good....

paul

Collapse -

Command to delete files older than 1 day

by michelle_lovejoy In reply to Command to delete files o ...

The question was auto-closed by TechRepublic

Collapse -

Command to delete files older than 1 day

by michelle_lovejoy In reply to Command to delete files o ...

This question was auto closed due to inactivity

Back to Windows Forum
7 total posts (Page 1 of 1)  

Related Discussions

Related Forums