Reputation: 105
I'm trying to copy a multiple files with a certain extension to a different folder, heres the code I'm using, not too familiar with VBS, but could someone point me in the right direction?
dim filesys
Set objFSO = CreateObject("Scripting.FileSystemObject")
objStartFolder = "V:\Auto Audiowall Music Uploads\MUSIC\"
Set objFolder = objFSO.GetFolder(objStartFolder)
Wscript.Echo objFolder.Path
Set colFiles = objFolder.Files
For Each objFile in colFiles
If UCase(objFSO.GetExtensionName(objFile.name)) = "MP3" Then
objFSO.CopyFile "V:\Auto Audiowall Music Uploads\MUSIC\".objFile.Name.".mp3", "V:\Auto Audiowall Uploads\New Music"
End If
If UCase(objFSO.GetExtensionName(objFile.name)) = "WAV" Then
objFSO.CopyFile "V:\Auto Audiowall Music Uploads\MUSIC\".objFile.Name.".wav", "V:\Auto Audiowall Uploads\New Music"
End If
Next
Upvotes: 0
Views: 2340
Reputation: 16311
You're concatenating your strings incorrectly in your CopyFile
function. You need to use an ampersand (&
) to concatenate strings in VBScript.
Rather than that, though, you can use objFile.Path
instead of concatenating strings to create the full source path.
objFSO.CopyFile objFile.Path, "V:\Auto Audiowall Uploads\New Music\"
Or you can just use the File
object's Copy
function:
objFile.Copy "V:\Auto Audiowall Uploads\New Music\"
In either case, end the destination path with a slash so that VBScript knows that you're copying into a folder and not copying to create a new file.
Upvotes: 1