|
|
Our Hot Pick: Rising Antivirus 2006 - Certified by TUV & Checkmark! Get 10% discount by entering this coupon code: ONDISCOUNT10
Hi
I have a script here that delete old files from a Windows 2000 server and keep a log of what been deleted by a log file created but it does not work on XP or windows 2003 server.
On the windows 2000 server - i run the file like this cscript scripname.vbs
Please can you help me get this working on a xp and windows 2003.
Error message it get is this
D:\test>cscript test.vbs Input Error: Can not find script file "D:\test\test.vbs". Thanks
here a copy of the script file in .vbs
' ' Script to delete files older than a given number of days. ' ' ' ' Set StdOut = WScript.StdOut
Main
Sub Main() ' ' DropOldFiles ' folderspec - Folder where you want to delete files ' logfile - File where logfile will be generated. ' days - Number of days to keep files. ' Call DropOldFiles("D:\test","D:\test\log1.txt", 6) End Sub
Sub DropOldFiles(folderspec, logfile, days) Dim fso,f,f1,s,fi, cnt, tot StdOut.WriteLine "Starting DropOldFiles..." LogOpen(logfile) cnt = 0 tot = 0 Set fso = CreateObject("Scripting.FileSystemObject") Set f = fso.GetFolder(folderspec) Set fc = f.Files For Each f1 in fc If DateDiff ("d",f1.DateLastModified, Now ) > days Then LogWrite f1.name & " DateLastModified:" & f1.DateLastModified & " DaysOld:" & DateDiff ("d",f1.DateLastModified, Now ) fso.DeleteFile (folderspec & f1.name) cnt = cnt + 1 End If tot = tot + 1 Next LogWrite "--------------------------------------------------------------" LogWrite " Processed " & tot & " file(s). Deleted " & cnt & " file(s)." LogWrite "--------------------------------------------------------------" LogClose StdOut.WriteLine "Ending DropOldFiles..."
End Sub ' ' ***************************************************************************************** ' ' ' Write to the Logfile '
Dim LogFile
Sub LogWrite (Text) LogFile.WriteLine "[" & Now & "] " & Text End Sub
Sub LogClose () LogFile.Close Set Logfile=nothing End Sub
Sub LogOpen (LogPath) Dim fso, f1 Const ForAppend = 8 Set fso = CreateObject("Scripting.FileSystemObject") Set LogFile = fso.OpenTextFile(LogPath, ForAppend, True) Set fso = nothing End Sub
|
|
Maybe you have file types hidden, and really the file's true name is test.vbs.txt Try disabling "Hide know file extensions",
Start / Control Panel / Folder Options / ....and untick "Hide extensions for known file types"
....then go back to the folder and rename the file to test.vbs and then try running it again.
Regards, Dave.
"Praful Varsani" <PrafulVarsani[ at ]discussions.microsoft.com> wrote in message news:438C8E48-2233-4610-9154-6297A0E04E37[ at ]microsoft.com...
[Quoted Text] > Hi > > I have a script here that delete old files from a Windows 2000 server and > keep a log of what been deleted by a log file created but > it does not work on XP or windows 2003 server. > > On the windows 2000 server - i run the file like this cscript > scripname.vbs > > Please can you help me get this working on a xp and windows 2003. > > Error message it get is this > > D:\test>cscript test.vbs > Input Error: Can not find script file "D:\test\test.vbs". > Thanks > > here a copy of the script file in .vbs > > ' > ' Script to delete files older than a given number of days. > ' > ' ' > ' > Set StdOut = WScript.StdOut > > Main > > Sub Main() > ' > ' DropOldFiles > ' folderspec - Folder where you want to delete files > ' logfile - File where logfile will be generated. > ' days - Number of days to keep files. > ' > Call DropOldFiles("D:\test","D:\test\log1.txt", 6) > End Sub > > Sub DropOldFiles(folderspec, logfile, days) > Dim fso,f,f1,s,fi, cnt, tot > > StdOut.WriteLine "Starting DropOldFiles..." > > LogOpen(logfile) > cnt = 0 > tot = 0 > > Set fso = CreateObject("Scripting.FileSystemObject") > Set f = fso.GetFolder(folderspec) > Set fc = f.Files > For Each f1 in fc > If DateDiff ("d",f1.DateLastModified, Now ) > days Then > LogWrite f1.name & " DateLastModified:" & f1.DateLastModified & " > DaysOld:" & DateDiff ("d",f1.DateLastModified, Now ) > fso.DeleteFile (folderspec & f1.name) > cnt = cnt + 1 > End If > tot = tot + 1 > Next > LogWrite "--------------------------------------------------------------" > LogWrite " Processed " & tot & " file(s). Deleted " & cnt & " file(s)." > LogWrite "--------------------------------------------------------------" > LogClose > StdOut.WriteLine "Ending DropOldFiles..." > > End Sub > > ' > ' > ***************************************************************************************** > ' > ' > ' Write to the Logfile > ' > > Dim LogFile > > Sub LogWrite (Text) > LogFile.WriteLine "[" & Now & "] " & Text > End Sub > > Sub LogClose () > LogFile.Close > Set Logfile=nothing > End Sub > > Sub LogOpen (LogPath) > Dim fso, f1 > Const ForAppend = 8 > Set fso = CreateObject("Scripting.FileSystemObject") > Set LogFile = fso.OpenTextFile(LogPath, ForAppend, True) > Set fso = nothing > End Sub
|
|
"P.V." Wrote: Thanks David, i did that and renamed is to .vbs and re-run the script but another error message now Starting DropOldFiles... D:\test\Purging Script\delete\delete.vbs(33, 3) Microsoft VBScript runtime error: File not found (Windows 2003 server and XP)
"D.R." wrote:
[Quoted Text] > Maybe you have file types hidden, and really the file's true name is > test.vbs.txt > Try disabling "Hide know file extensions", > > Start / Control Panel / Folder Options / > ....and untick "Hide extensions for known file types" > > ....then go back to the folder and rename the file to test.vbs and then try > running it again. > > Regards, > Dave. > > > "Praful Varsani" <PrafulVarsani[ at ]discussions.microsoft.com> wrote in message > news:438C8E48-2233-4610-9154-6297A0E04E37[ at ]microsoft.com... > > Hi > > > > I have a script here that delete old files from a Windows 2000 server and > > keep a log of what been deleted by a log file created but > > it does not work on XP or windows 2003 server. > > > > On the windows 2000 server - i run the file like this cscript > > scripname.vbs > > > > Please can you help me get this working on a xp and windows 2003. > > > > Error message it get is this > > > > D:\test>cscript test.vbs > > Input Error: Can not find script file "D:\test\test.vbs". > > Thanks > > > > here a copy of the script file in .vbs > > > > ' > > ' Script to delete files older than a given number of days. > > ' > > ' ' > > ' > > Set StdOut = WScript.StdOut > > > > Main > > > > Sub Main() > > ' > > ' DropOldFiles > > ' folderspec - Folder where you want to delete files > > ' logfile - File where logfile will be generated. > > ' days - Number of days to keep files. > > ' > > Call DropOldFiles("D:\test","D:\test\log1.txt", 6) > > End Sub > > > > Sub DropOldFiles(folderspec, logfile, days) > > Dim fso,f,f1,s,fi, cnt, tot > > > > StdOut.WriteLine "Starting DropOldFiles..." > > > > LogOpen(logfile) > > cnt = 0 > > tot = 0 > > > > Set fso = CreateObject("Scripting.FileSystemObject") > > Set f = fso.GetFolder(folderspec) > > Set fc = f.Files > > For Each f1 in fc > > If DateDiff ("d",f1.DateLastModified, Now ) > days Then > > LogWrite f1.name & " DateLastModified:" & f1.DateLastModified & " > > DaysOld:" & DateDiff ("d",f1.DateLastModified, Now ) > > fso.DeleteFile (folderspec & f1.name) > > cnt = cnt + 1 > > End If > > tot = tot + 1 > > Next > > LogWrite "--------------------------------------------------------------" > > LogWrite " Processed " & tot & " file(s). Deleted " & cnt & " file(s)." > > LogWrite "--------------------------------------------------------------" > > LogClose > > StdOut.WriteLine "Ending DropOldFiles..." > > > > End Sub > > > > ' > > ' > > ***************************************************************************************** > > ' > > ' > > ' Write to the Logfile > > ' > > > > Dim LogFile > > > > Sub LogWrite (Text) > > LogFile.WriteLine "[" & Now & "] " & Text > > End Sub > > > > Sub LogClose () > > LogFile.Close > > Set Logfile=nothing > > End Sub > > > > Sub LogOpen (LogPath) > > Dim fso, f1 > > Const ForAppend = 8 > > Set fso = CreateObject("Scripting.FileSystemObject") > > Set LogFile = fso.OpenTextFile(LogPath, ForAppend, True) > > Set fso = nothing > > End Sub > > >
|
|
|