asked on
Dim objFSO
Dim sSourceFolder
Dim sDestFolder
Dim sDBFile
Dim sDateTimeStamp
Set objFSO = CreateObject("Scripting.FileSystemObject")
sSourceFolder = "C:\Oceanside\"
sBackupFolder = "C:\Files_Found\"
sDBFile = array _
("ROWP19-0499","ROWP19-0543","ROWP19-0544","ROWP19-0545","ROWP19-0550","ROWP19-0559","ROWP19-0562","ROWP19-0567","ROWP19-0645")
sDBFileExt = "pdf"
'If the backup folder doesn't exist, create it.
If Not objFSO.FolderExists(sBackupFolder) Then
objFSO.CreateFolder(sBackupFolder)
End If
'Copy the file as long as the file can be found
For i = 0 to Ubound(sDBFile)
If objFSO.FileExists(sSourceFolder & "\" & sDBFile(i) & "." & sDBFileExt) Then
objFSO.CopyFile sSourceFolder & "\" & sDBFile(i) & "." & sDBFileExt,_
sBackupFolder & "\" & sDBFile(i) & "." & sDBFileExt
MsgBox sSourceFolder & "\" & sDBFile(i) & "." & sDBFileExt & " was copied to " & sBackupFolder
End if
Next
Set objFSO = Nothing
Thanks in advance!
$SourceFolder = "C:\Oceanside"
$BackupFolder = "C:\Files_Found"
$DBFile = "ROWP19-0499", "ROWP19-0543", "ROWP19-0544", "ROWP19-0545", "ROWP19-0550", "ROWP19-0559", "ROWP19-0562", "ROWP19-0567", "ROWP19-0645"
$DBFileExt = "pdf"
If (-not (Test-Path -Path $BackupFolder)) {
New-Item -ItemType Directory -Path $BackupFolder | Out-Null
}
$copied = Get-ChildItem -Path $SourceFolder -Recurse -File -Filter $DBFileExt |
Where-Object {$DBFile -contains $_.BaseName} |
Copy-Item -Destination $BackupFolder -PassThru -Verbose
Add-Type -AssemblyName System.Windows.Forms
If ($copied) {
$message = "Copied the following files to '$($BackupFolder)':`r`n$($copied.FullName -join "`r`n")"
} Else {
$message = "No files were found!"
}
[void][System.Windows.Forms.Messagebox]::Show($message)
Dim objFSO
Dim sSourceFolder
Dim sDestFolder
Dim sDBFile
Dim sDateTimeStamp
Set objFSO = CreateObject("Scripting.FileSystemObject")
sSourceFolder = "C:\Oceanside"
sBackupFolder = "C:\Files_Found"
sDBFile = array("ROWP19-0499","ROWP19-0543","ROWP19-0544","ROWP19-0545","ROWP19-0550","ROWP19-0559","ROWP19-0562","ROWP19-0567","ROWP19-0645")
sDBFileExt = "pdf"
'If the source folder doesn't exist, exit.
If Not objFSO.FolderExists(sSourceFolder) Then
MsgBox "Source folder """ & sSourceFolder & """does not exist."
WScript.Quit()
End If
'If the backup folder doesn't exist, create it.
If Not objFSO.FolderExists(sBackupFolder) Then
objFSO.CreateFolder(sBackupFolder)
End If
'Copy the file as long as the file can be found
ProcessFolder objFSO.GetFolder(sSourceFolder)
Set objFSO = Nothing
Sub ProcessFolder(oFolder)
For i = 0 to Ubound(sDBFile)
If objFSO.FileExists(oFolder.Path & "\" & sDBFile(i) & "." & sDBFileExt) Then
objFSO.CopyFile oFolder.Path & "\" & sDBFile(i) & "." & sDBFileExt, sBackupFolder & "\" & sDBFile(i) & "." & sDBFileExt
MsgBox sSourceFolder & "\" & sDBFile(i) & "." & sDBFileExt & " was copied to " & sBackupFolder
End if
Next
For Each oSubFolder In oFolder.SubFolders
ProcessFolder oSubFolder
Next
End Sub
ASKER
ASKER
VBScript (Visual Basic Scripting Edition) is an interpreted scripting language developed by Microsoft that is modeled on Visual Basic, but with some important differences. VBScript is commonly used for automating administrative and other tasks in Windows operating systems (by means of the Windows Script Host) and for server-side scripting in ASP web applications. It is also used for client-side scripting in Internet Explorer, specifically in intranet web applications.
TRUSTED BY
I’ll check back in the morning...
~bp