Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Copy Files except one's with certain extension to another directory 1

Status
Not open for further replies.

PRUSA

Technical User
Joined
Sep 23, 2004
Messages
35
Location
US
Hello Everyone,

I am extremely new to vbscript, but I was told I needed this to come up with a solution to my problem.

Lets say I have a folder called "OldFiles" and the path was C:\OldFiles.

In this folder i have *.txt, *.doc, *.xls, *.mdb, and *.exe files.

I want to copy all the files except for any files that have a .exe extension into a new directory, which is call "NewFiles". C:\NewFiles.

Is this possible in vbScript?

If so please keep in mind I'm an Newbie to this, how do i start and what would I need to complete this task.

Thanks In Advance,
 
It is possible and not terribly hard. Search this forum for examples of the FileSystemObject its Files collection. That should get you started.

[red]"... isn't sanity really just a one trick pony anyway?! I mean, all you get is one trick, rational thinking, but when you are good and crazy, oooh, oooh, oooh, the sky is the limit!" - The Tick[/red]
 
Hi TomThumbKP

Thanks for the advise I found someone who had a similar question and I was able to use it for my purposes. I always thought vbscript was for web pages.

What books do you recommend that would be helpful for me to learn VBS. Because I'm sure I'll need to do more of these tasks for my job..

Thanks Again for the help..
 
To a certain degree it depends on what you plan to use VBScript for. If you search this forum for 'books', you'll find several.

[red]"... isn't sanity really just a one trick pony anyway?! I mean, all you get is one trick, rational thinking, but when you are good and crazy, oooh, oooh, oooh, the sky is the limit!" - The Tick[/red]
 
Hello everyone,

My situtation has gotten more complicated. As it turns out, we here have a Main folder called "ABC", within that folder there are are many subfolders, which have more folders.

So basically I need to copy the entire cotents of the main folder "ABC" but leave out any .PAG files contained in any subfolders.

Does this complicate things alot? Please realize I'm extremly new to VBScript. This is what i have so far but this only works for one folder to another.
-----------------------------------------------------------


dim oFSO, oFolder, srcfolder, tgtfolder, oFile


srcfolder="C:\1"
tgtfolder="C:\2"

set oFSO = CreateObject("Scripting.FileSystemObject")

on error resume next

set oFolder = oFSO.GetFolder(tgtfolder)

if err.number<>0 then
wscript.echo "The Backup Folder does not exists. Operation aborted."
set oFolder = nothing : set oFSO = nothing
wscript.quit(1)
end if

set oFolder = oFSO.GetFolder(srcfolder)
if err.number<>0 then
wscript.echo "The Source Folder does not exists. Operation aborted."
set oFolder = nothing : set oFSO = nothing
wscript.quit(2)
end if
on error goto 0

for each oFile in oFolder.files
if UCASE(Right(oFile.Name, 3)) <> "PAG" then
oFSO.copyfile oFile.path, tgtFolder & "\" & oFile.name, true
end if
next
set oFolder = nothing : set oFSO = nothing

---------------------------------------------------------

Thanks so much..
 
Search this forum for threads on 'recursion' or 'recursive'. Doing something to subfolders has been covered many times.

[red]"... isn't sanity really just a one trick pony anyway?! I mean, all you get is one trick, rational thinking, but when you are good and crazy, oooh, oooh, oooh, the sky is the limit!" - The Tick[/red]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top