Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

delete all files except the ones created less than 30mins ago

Status
Not open for further replies.

anarchoi

Technical User
Jun 29, 2009
12
CA
I'm using this script:

Set objFileSys = CreateObject("Scripting.FileSystemObject")
Set objFolder = objFileSys.GetFolder("C:\DVR_Media\video")


For Each Folder In objFolder.SubFolders
FolderCreated = Folder.DateCreated
FolderAge = DateDiff("d", FolderCreated, Now)
If FolderAge >= 0 Then
get_ShowSubFolders(folder)
End If
Next

Sub get_ShowSubFolders(Folder)

For Each subfolder In Folder.Subfolders

if subfolder.name = "camera 04" then
subfolder.delete
end if

Next
End Sub



Right now the script will delete "camera 04" folder

I would like to modify this script to keep "camera 04" folder and delete all files inside this folder except the files that were created less than 30 minutes old

But i'm a newbie and i don't know how to do this... :( Could someone help me?

Thanks a lot!
 
>I'm using this script
But that script is misguided.

>FolderAge = DateDiff("d", FolderCreated, Now)
Is there any folder whose DateCreated is later than Now()? This condition therefore is meaning less.
> If FolderAge >= 0 Then
 
ok... but can you help me with my problem?
 
[tt] dim ofile, dt_now
[red]'[/red]if subfolder.name = "camera 04" then
if strcomp(subfolder.name,"camera 04",1)=0 then
[red]'[/red]subfolder.delete
dt_now=now()
for each ofile in subfolder.files
if datediff("n",ofile.datecreated,dt_now)>=30 then '30 mins
ofile.delete
end if
next
end if
[/tt]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top