|
Answer» I found this vbs submitted to this forum by Sidewinder on August 8, 2008:
+++++++++++++++++++++ Set fso = CreateObject("Scripting.FileSystemObject") fs = "c:\dvr_data" ShowFiles(fs)
Sub ShowFiles(Fld) Set k = fso.GetFolder(Fld) Set s = k.SubFolders Set kf = k.FILES For Each objFile In kf 'If fso.GetExtensionName(objFile) = "avi" then 'If objFile.DateCreated < date - 3 Then WScript.Echo objFile & " " & objFile.DateCreated 'fso.DeleteFile objfile 'End If 'End if Next For Each SubFolder In s ShowFiles SubFolder Next End Sub +++++++++++++++++++++
I can follow what is happening in most of the script and was able to modify it and put it to use for deleting OLD files in a specific folder.
How do I modify it so the starting folder is: "C:\Documents and Settings\%username%\some_folder"?
I do not know the syntax to set the username variable in the script. I know I can't use the %username% as I can in a batch file.
My goal is to use this in a logoff script to DELETE files OLDER than 1 day from a common folder in any user's folder in C:\Documents and Settings. Code: [Select]Set oShell = CreateObject( "WScript.Shell" ) user = oShell.ExpandEnvironmentStrings("%UserName%") fs = "C:\Documents and Settings\"&user&"\some_folder" Thank you. That works great and made my day!
I also changed objFile.DateCreated to objFile.DateLastModified. I found out there is a HISTORY file that needs to be retained in the target folder.
Thank you again for your attention to my question.
|