Windows Vista Tips

Windows Vista Tips > Newsgroups > Windows Server > Scripting > File copy and paste script

Reply
Thread Tools Display Modes

File copy and paste script

 
 
Sam
Guest
Posts: n/a

 
      02-12-2009
Hi,

I need to traverse a bunch of folders looking for files whose name contain
"MyPhrase" in them and copy them into a folder on say my desktop. I'd
appreciate some pointers in writing this script.

Basically, I want to tell the script what folder to start from. It will go
through all its subfolders and whenever it finds "MyPhrase" in file name, it
will copy and paste that file into a folder on my desktop.

Thanks for your help.
--
Thanks,

Sam
 
Reply With Quote
 
 
 
 
Pegasus \(MVP\)
Guest
Posts: n/a

 
      02-12-2009

"Sam" <> wrote in message
news:76989B96-44F6-4D4C-992C-...
> Hi,
>
> I need to traverse a bunch of folders looking for files whose name contain
> "MyPhrase" in them and copy them into a folder on say my desktop. I'd
> appreciate some pointers in writing this script.
>
> Basically, I want to tell the script what folder to start from. It will go
> through all its subfolders and whenever it finds "MyPhrase" in file name,
> it
> will copy and paste that file into a folder on my desktop.
>
> Thanks for your help.
> --
> Thanks,
>
> Sam


Try this script:

Set oFSO = CreateObject("Scripting.FileSystemObject")
sFolder = "d:\Some Folder"
sPhrase = "Some Phrase"
CheckFolder oFSO.GetFolder(sFolder)

'--------------------------
'Check a folder recursively
'--------------------------
Sub CheckFolder(oFolder)
For Each oFile In oFolder.Files
If InStr(1, oFile.Name, sPhrase, 1) > 0 Then
WScript.Echo "Copying " & oFile.path
End If
Next

For Each oSubfolder In oFolder.Subfolders
CheckFolder oSubfolder
Next
End Sub

I leave it to you to implement the functions that will prompt the user for a
folder name and the one that performs the actual copy action.


 
Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
Please help...My windows cannot drag, copy or paste a file... d412w1n Windows Media Center 4 08-04-2009 02:36 AM
Same File Name Copy/Paste PrismPast Windows Vista File Management 1 03-02-2009 09:39 AM
copy from file paste to an existing xls.. PK Scripting 0 10-13-2007 11:14 PM
Windows native file copy in folders (copy and paste) Fastest Tram Windows Server 0 12-27-2006 08:47 AM
Copy & Paste Script Kevin Gibson Scripting 2 10-02-2003 08:54 PM



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59