Re: copy text files only from all subfolders within a folder to a
- From: "Pegasus \(MVP\)" <I.can@xxxxxxxxxx>
- Date: Mon, 26 May 2008 23:14:12 +0200
"Yasser Elzefzaf" <YasserElzefzaf@xxxxxxxxxxxxxxxxxxxxxxxxx> wrote in
message news:7A4CF8AA-DD07-4ADA-92D4-216C127619C4@xxxxxxxxxxxxxxxx
first of all thank you so much for such great one, it really worked ;)
i managed the destination folder to which the files will be copied to so
as
not to overwrite the rrot one
but i would like to ask something about the below script (the one i tried
to
develop) it didn't work, abd every time i try to debug it , it returns
different error
HUG if you don't mind to help:
--------------------------------------------
My Script:
----------------------------------------------
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objFolder = objFSO.GetFolder("D:\Test")
Set colFiles = objFSO.GetFolder(subFolder).Files
AllFolders objFolder
Sub AllFolders (Folder)
For Each SubFolder in Folder.Subfolders
CopyTextFiles subfolder
AllFolders Subfolder
Next
End Sub
Sub CopyTextFiles (subFolder)
For Each objFile in colFiles
arrSplitName = Split(objFile.Name, ".")
strExtension = arrSplitName(UBound(arrSplitName) - 1)
If strExtension = "txt" Then
objFSO.CopyFile objFile.Path, "D:\Text\"
Wscript.Echo objFSO.Name
End If
Next
End Sub
Wscript.Echo "Done..."
--------------------------------------------------------------------------------------------------------------
I could not quite follow the logic in your script. Parts of it
appeared to recursive. Note also the following points:
- Avoid embedding important constants deep inside in your code.
Put them right up the top where they are highly visible. This
makes maintenance much, much easier.
- Keep your main routine in one contiguous block. Spreading
it before, in between and after your subroutines gets
confusing.
Try this script. It is fully tested.
01. Source = "D:\Temp\"
02. Target = "D:\Text\"
03. ext = ".txt"
04.
05. Set objFSO = CreateObject("Scripting.FileSystemObject")
06. If Not objFSO.FolderExists(Target) then objFSO.CreateFolder(Target)
07.
08. For Each sFolder In objFSO.GetFolder(Source).SubFolders
09. CopyTextFiles Source & sFolder.Name
10. Next
11. WScript.Echo "Done..."
12.
13. Sub CopyTextFiles (subFolder)
14. For Each objFile In objFSO.GetFolder(subFolder).Files
15. If LCase(Right(objFile.Name, 4)) = ext _
16. Then objFSO.CopyFile objFile.Path, Target
17. Next
18. End Sub
.
- References:
- copy text files only from all subfolders within a folder to a another folder
- From: Yasser Elzefzaf
- Re: copy text files only from all subfolders within a folder to a another folder
- From: James Whitlow
- Re: copy text files only from all subfolders within a folder to a
- From: Yasser Elzefzaf
- copy text files only from all subfolders within a folder to a another folder
- Prev by Date: Re: copy text files only from all subfolders within a folder to a
- Next by Date: Re: vbscript and HTA help
- Previous by thread: Re: copy text files only from all subfolders within a folder to a
- Next by thread: Write to a file
- Index(es):
Relevant Pages
|