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 Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

backup all doc files

Status
Not open for further replies.

edms

IS-IT--Management
Dec 16, 2002
8
0
0
AU
I need to search for all .doc files on the c: drive and then back them up to a network drive, can this easily be done via vbscript?

 
Hello edms,

Check out script.filesystemobject from the documentation and search this forum for frequent treated topic.

Bascially, you initiate a filesystemobject. Get the root of the drive. Use .files collection to get to the files directly under it. After verified the file's extension is .doc, use copyfile to make the backup. Then use .subfolders to get to the subfolders. Repeat the procedure again until there are none subfolders.

regards - tsuji
 
This should work:

Option Explicit

' Global Constants...
Const sSearchDrive = "C:\"
Const sCopyTo = "F:\"

' Global Variables...
Dim fso

Call Main()
Call WScript.Quit()

Sub Main
Set fso = CreateObject("Scripting.FileSystemObject")

Dim fld
Set fld = fso.GetFolder(sSearchDrive)

Call RecurseFolder(fld)

Set fld = Nothing
Set fso = Nothing

MsgBox "Done"
End Sub

Sub RecurseFolder(fld)
Dim fldSub
Dim f

For Each fldSub in fld.Subfolders
Call RecurseFolder(fldSub)

For Each f in fldSub.Files
If UCase(Right(f.Name, 3)) = "JPG" Then
Call fso.CopyFile(f.Path, sCopyTo)
End If
Next
Next
End Sub
 
Sorry, I was testing with JPG's. Replace the line:

If UCase(Right(f.Name, 3)) = "JPG" Then

with

If UCase(Right(f.Name, 3)) = "DOC" Then
 
Thanks guys, much appreciated
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top