|
|
|||||||||
|
|||||||||
|
|||||||||
| |
||
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
#1
|
|||
|
|||
|
VBScript - How to get files from Sub Folders
Hello Guy's,
Please help me with this code. I am new in VBScript. Here is my Code; dim BackupFilesSigDate, HTRoFSO, HTRFile, HTRFolder, HTRsrcfolder BackupFilesSigDate = Now()-0.1 wscript.echo BackupFilesSigDate 'HTRsrcfolder= "C:\HTRDATA\DM4FS1" & "C:\HTRDATA\DM4FS2" '& C:\HTRDATA\DM4FS2"THIS DOES NOT WORK HTRsrcfolder= "C:\HTRDATA\DM4FS1" set HTRoFSO = CreateObject("Scripting.FileSystemObject") on error resume next set HTRFolder = HTRoFSO.GetFolder(HTRsrcfolder) Wscript.Echo HTRFolder.Path on error goto 0 on error resume next for each HTRFile in HTRFolder.files if HTRFile.DateLastModified>=BackupFilesSigDate then wscript.echo HTRFile 'HTRoFSO.DeleteFile HTRFile.path, HTRtgtfolder & "\" & HTRFile.name, True 'THIS DOES NOT WORK 'wscript.echo HTRoFSO.Delete 'THIS DOES NOT WORK 'HTRFile.path, HTRtgtfolder & "\" & HTRFile.name, True 'THIS DOES NOT WORK on error resume next end if Next set HTRFolder = nothing : set HTRoFSO = nothing Two Issues; 1. With above code, i can not able to delete files (i am sorting newest file for last 4 hrs...Basically trying to get newest few hrs old files). I got the files but couldn't able to delete them. 2. i have many sub-folders. What will be the easy way to find 4 hrs (lastmodifiedDate) files from all the sub-folder and delete them. I do appreciate in advance for all expertiese. Sam |
|
#2
|
|||||
|
|||||
|
You were basically on the right track, but you had a lot of syntax errors. There's also no point toggling error-handling on and off that many times.
I've streamlined your code a bit and made it more efficient by using subroutines. I've also added subfolders to it and made it so that you can add more folders to the list. Just add them to the array. vb Code:
__________________
Click the image if at any point you don't like my decision.Scripting problems? Windows questions? Ask the Windows Guru! Last edited by Nilpo : August 24th, 2007 at 07:55 PM. |
|
#3
|
|||
|
|||
|
How to get files from Sub Folders
Quote: Nilpo, As always, I really appreciated your helpful reply. I do get error for "For i = 0 To arrFolders.Count - 1" 'object Required'. I can take hint to resolve this my own. I am enjoying VBScript. Also - Would you recomend any books etc for a beginer like me. Thanks Again Sam |
|
#4
|
||||
|
||||
|
To resolve the Object Required error, be sure that your array is not empty and is properly initialized.
|
![]() |
| Viewing: ASP Free Forums > System Administration > Windows Scripting > VBScript - How to get files from Sub Folders |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|