Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 107
Default filesystemobject

hi guys
i want to copy a particular file from each folder of "e:" drive
how am i to loop each folder from a drive
(Drive is remote drive ---cd-rom)
please help ... i am all blank at present
--
hemu
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,986
Default filesystemobject

Take a look at this site for some guidelines.

http://www.ozgrid.com/VBA/loop-through.htm

"Hemant_india" wrote:

hi guys
i want to copy a particular file from each folder of "e:" drive
how am i to loop each folder from a drive
(Drive is remote drive ---cd-rom)
please help ... i am all blank at present
--
hemu

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 7,247
Default filesystemobject

If you want to search through only the top level directories under the E:
root, use

Sub CopyTheFiles()
Dim FSO As Scripting.FileSystemObject
Dim RD As Scripting.Folder
Dim FF As Scripting.Folder
Dim F As Scripting.File


Set FSO = New Scripting.FileSystemObject
Set RD = FSO.GetDrive("E").RootFolder
For Each FF In RD.SubFolders
Set F = FF.Files("TheFileName.xls") '<<< CHANGE FILE NAME
F.Copy Destination:="C:\Whatever\" & F.Name '<<< CHANGE FOLDER
Next FF
End Sub

If you want to look through EVERY folder and subfolder under the E: root,
use

Sub CopyTheFiles()
Dim FSO As Scripting.FileSystemObject
Dim RD As Scripting.Folder
Dim FF As Scripting.Folder
Dim F As Scripting.File

Set FSO = New Scripting.FileSystemObject
Set RD = FSO.GetDrive("G").RootFolder
For Each FF In RD.SubFolders
DoOneFolder WhatFolder:=FF
Next FF
End Sub

Sub DoOneFolder(WhatFolder As Scripting.Folder)
Dim F As Scripting.File
Dim FF As Scripting.Folder
Set F = WhatFolder.Files("TheFileName.xls")
F.Copy Destination:="C:\Whatever\" & F.Name

For Each FF In WhatFolder.SubFolders
DoOneFolder WhatFolder:=FF
Next FF
End Sub

See also http://www.cpearson.com/Excel/RecursionAndFSO.htm for example code.


--
Cordially,
Chip Pearson
Microsoft MVP - Excel, 10 Years
Pearson Software Consulting
www.cpearson.com
(email on the web site)


"Hemant_india" wrote in message
...
hi guys
i want to copy a particular file from each folder of "e:" drive
how am i to loop each folder from a drive
(Drive is remote drive ---cd-rom)
please help ... i am all blank at present
--
hemu


  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 107
Default filesystemobject

thank both of you sir(s)
after i posted my query i gave a try using dir() function
it is also working
but i am going to use chip's code. The only thing i have to do is
to add a referance . am i right?
thanks again
--
hemu


"Chip Pearson" wrote:

If you want to search through only the top level directories under the E:
root, use

Sub CopyTheFiles()
Dim FSO As Scripting.FileSystemObject
Dim RD As Scripting.Folder
Dim FF As Scripting.Folder
Dim F As Scripting.File


Set FSO = New Scripting.FileSystemObject
Set RD = FSO.GetDrive("E").RootFolder
For Each FF In RD.SubFolders
Set F = FF.Files("TheFileName.xls") '<<< CHANGE FILE NAME
F.Copy Destination:="C:\Whatever\" & F.Name '<<< CHANGE FOLDER
Next FF
End Sub

If you want to look through EVERY folder and subfolder under the E: root,
use

Sub CopyTheFiles()
Dim FSO As Scripting.FileSystemObject
Dim RD As Scripting.Folder
Dim FF As Scripting.Folder
Dim F As Scripting.File

Set FSO = New Scripting.FileSystemObject
Set RD = FSO.GetDrive("G").RootFolder
For Each FF In RD.SubFolders
DoOneFolder WhatFolder:=FF
Next FF
End Sub

Sub DoOneFolder(WhatFolder As Scripting.Folder)
Dim F As Scripting.File
Dim FF As Scripting.Folder
Set F = WhatFolder.Files("TheFileName.xls")
F.Copy Destination:="C:\Whatever\" & F.Name

For Each FF In WhatFolder.SubFolders
DoOneFolder WhatFolder:=FF
Next FF
End Sub

See also http://www.cpearson.com/Excel/RecursionAndFSO.htm for example code.


--
Cordially,
Chip Pearson
Microsoft MVP - Excel, 10 Years
Pearson Software Consulting
www.cpearson.com
(email on the web site)


"Hemant_india" wrote in message
...
hi guys
i want to copy a particular file from each folder of "e:" drive
how am i to loop each folder from a drive
(Drive is remote drive ---cd-rom)
please help ... i am all blank at present
--
hemu


Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
FileSystemObject help please. Tom Ogilvy Excel Programming 0 July 8th 05 04:44 PM
FileSystemObject help please. Bob Phillips[_7_] Excel Programming 0 July 8th 05 04:44 PM
Filesystemobject Help CyndyG Excel Programming 4 May 17th 05 01:00 AM
filesystemobject Alvin Hansen[_2_] Excel Programming 2 February 16th 05 03:47 PM
FileSystemObject lol[_2_] Excel Programming 2 April 6th 04 09:56 PM


All times are GMT +1. The time now is 05:39 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"