shatterstar6457
Programmer
Im getting the permission denied runtime error on the following line of code
strTargetFolder = objFSO.CreateFolder(strStartTargetFolder & "\" & objFile.Name)
and yes I am the admin on my machine.
Here is the rest of the code:
Option Explicit
Dim objFSO, objFile, objFolder, objSubFolder, objShell,_
colFiles, colFolders, colSubFolders,_
strStartDir, strExtension, strFolderPath, strSubFolderPath, strTargetFolder, strStartTargetFolder,_
intCount
strStartDir = InputBox("Full path of folder to check?")
strExtension = InputBox("Please enter the File Extension To Search For")
strStartTargetFolder = InputBox("Where would you like to Place the files? (Starting Directory)")
Set objShell = CreateObject("WScript.Shell")
Set objFSO = WScript.CreateObject("Scripting.FileSystemObject")
Set objFolder = objFSO.GetFolder(strStartDir)
Set colFiles = objFolder.Files
strFolderPath = objFolder.Path
intCount = 0
For each objFile in colFiles
If lcase(Right(objFile.Name,3)) = strExtension Then
strTargetFolder = objFSO.CreateFolder(strStartTargetFolder & "\" & objFile.Name)
objFile.Copy strTargetFolder, True
intCount = intCount + 1
Else
WScript.Echo "The File " & objFile.Name & " Isn't a match according to your query"
end If
Next
ScanSubFolders(objFolder)
WScript.Echo "I Copied " & intCount & " " & strExtension & " Files"
Sub ScanSubFolders(objFolder)
Set colFolders = objFolder.SubFolders
For Each objSubFolder In colFolders
strSubFolderPath = objSubFolder.Path
Set colFiles = objSubFolder.Files
For Each objFile in colfiles
If lcase(Right(objFile.Name,3)) = strExtension Then
strTargetFolder = objFSO.CreateFolder(strStartTargetFolder & "\" & objFile.Name)
objFile.Copy strTargetFolder, True
intCount = intCount + 1
Else
WScript.Echo "The File " & objFile.Name & " Isn't a match according to your query"
end If
Next
ScanSubFolders(objSubFolder)
Next
End Sub
strTargetFolder = objFSO.CreateFolder(strStartTargetFolder & "\" & objFile.Name)
and yes I am the admin on my machine.
Here is the rest of the code:
Option Explicit
Dim objFSO, objFile, objFolder, objSubFolder, objShell,_
colFiles, colFolders, colSubFolders,_
strStartDir, strExtension, strFolderPath, strSubFolderPath, strTargetFolder, strStartTargetFolder,_
intCount
strStartDir = InputBox("Full path of folder to check?")
strExtension = InputBox("Please enter the File Extension To Search For")
strStartTargetFolder = InputBox("Where would you like to Place the files? (Starting Directory)")
Set objShell = CreateObject("WScript.Shell")
Set objFSO = WScript.CreateObject("Scripting.FileSystemObject")
Set objFolder = objFSO.GetFolder(strStartDir)
Set colFiles = objFolder.Files
strFolderPath = objFolder.Path
intCount = 0
For each objFile in colFiles
If lcase(Right(objFile.Name,3)) = strExtension Then
strTargetFolder = objFSO.CreateFolder(strStartTargetFolder & "\" & objFile.Name)
objFile.Copy strTargetFolder, True
intCount = intCount + 1
Else
WScript.Echo "The File " & objFile.Name & " Isn't a match according to your query"
end If
Next
ScanSubFolders(objFolder)
WScript.Echo "I Copied " & intCount & " " & strExtension & " Files"
Sub ScanSubFolders(objFolder)
Set colFolders = objFolder.SubFolders
For Each objSubFolder In colFolders
strSubFolderPath = objSubFolder.Path
Set colFiles = objSubFolder.Files
For Each objFile in colfiles
If lcase(Right(objFile.Name,3)) = strExtension Then
strTargetFolder = objFSO.CreateFolder(strStartTargetFolder & "\" & objFile.Name)
objFile.Copy strTargetFolder, True
intCount = intCount + 1
Else
WScript.Echo "The File " & objFile.Name & " Isn't a match according to your query"
end If
Next
ScanSubFolders(objSubFolder)
Next
End Sub