Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!
  • Students Click Here

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

How to backup certain file types from an entire multiple drive or folder using vbscript?

How to backup certain file types from an entire multiple drive or folder using vbscript?

How to backup certain file types from an entire multiple drive or folder using vbscript?

Greetings Viewers,

I'd Preciate if somone can provide a new working vbscript that can copy many file types such as:
"mp3", "dat", "txt"
and so on recrisively from more than one location or folder and subfolders such as:
"c:\", "%AppData%
and so on into a designated folder for example:

Below is the code I am currntly working on but its not working and doesn't seem to be solving my problem.

Require variables to be defined
Option Explicit

' Global variables
Dim strBaseFolder
Dim strDestFolder
Dim objFSO
Dim objFolder
Dim objFile

Dim objWShell
Set objWShell = WScript.CreateObject("WScript.Shell")
Dim homePath
homePath = objWShell.expandEnvironmentStrings("%HOMEPATH%")

' Define folders to work with
strBaseFolder = "C:\"
strBaseFolder = "D:\"
strBaseFolder = "F:\"
strBaseFolder = homePath + "\AppData
strDestFolder = homePath + "\AppData\Roaming\backup"

' Create filesystem object
Set objFSO = CreateObject("Scripting.FileSystemObject")

' Exit if base folder does not exist
If Not objFSO.FolderExists(strBaseFolder) Then
Wscript.Echo "Missing base folder : """ & strBaseFolder & """"
End If

' Exit if dest folder does not exist
If Not objFSO.FolderExists(strDestFolder) Then
Wscript.Echo "Missing dest folder : """ & strDestFolder & """"
End If

' Look at each subfolder of base folder
For Each objFolder In objFSO.GetFolder(strBaseFolder).SubFolders
' Continue if we want this folder
If IncludeFolder(objFolder) Then
' Check each file in this folder
For Each objFile In objFolder.Files
' Continue if we want this file
If IncludeFile(objFile) Then
' Copy the file
'Wscript.Echo "Copying File :""" & objFile.Path & """"
objFile.Copy strDestFolder & "\" & objFile.Name
End If
End If

' Logic to determine if we process a folder
Function IncludeFolder(objFolder)
' Exclude certain folder names
Select Case LCase(objFolder.Name)
Case "exchange", "hr_daily_terminations", "pay", "terminations", "work folder"
IncludeFolder = False
Case Else
IncludeFolder = True
End Select
End Function

' Logic to determine if we process a file
Function IncludeFile(objFile)
IncludeFile = False
Select Case LCase(objFSO.GetExtensionName(objFile.Path))
' Include only these extensions
Case "txt", "dat", "tmp"
' Include only files dated today
If DateDiff("d", objFile.DateLastModified, Now) = 0 Then
IncludeFile = True
End If
End Select
End Function

Thank for your helping in advance.

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members! Already a Member? Login

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close