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

VBS Script to copy files Permission Denied

Status
Not open for further replies.

w107kam

IS-IT--Management
Apr 19, 2012
1
US
I wrote a simple script to copy .wav files from a temp location to another folder. The temp location has a folder structure:

\\TempWavs\YYYY\MM\DD\HH\*.wav

I'm copying the .wav files to another location, and then deleting the .wav file from the temp location. However, I'm receiving this error:

Line 23
Char 3
Permission Denied
800A0046
MicroSoft VBScript runtime error


Here's the code:

Set objFSO = CreateObject("Scripting.FileSystemObject")
objStartFolder = "D:\TempWavs"

Set objFolder = objFSO.GetFolder(objStartFolder)
Set colFiles = objFolder.Files



ShowSubfolders objFSO.GetFolder(objStartFolder)

Sub ShowSubFolders(Folder)

For Each Subfolder in Folder.SubFolders
Set objFolder = objFSO.GetFolder(Subfolder.Path)
Set colFiles = objFolder.Files
set filesys = CreateObject("Scripting.FileSystemObject")
dim WavFolder

For Each objFile in colFiles
EncFolder = Mid(objFile.Name, 19, 1)
If right(objFile.Name, 3) = "wav" Then
filesys.CopyFile objfile, "D:\Data\0"&WavFolder&"", True
filesys.DeleteFile objFile, True
End If
Next

ShowSubFolders Subfolder
Next
End Sub


I'm executing the script with a batch file as a scheduled task. It will sometime execute successfully, but other times it generates the Permission Denied error and hangs.
 
Are the wavs on the same machine you're executing the script on, or are you working across a network? IF across a network, is the scheduled task configured to run using a user account that has proper permissions?

How are the wavs being generated? Is it possible a file is in use while you try to move it?

Jeff
[small][purple]It's never too early to begin preparing for [/purple]International Talk Like a Pirate Day
"The software I buy sucks, The software I write sucks. It's time to give up and have a beer..." - Me[/small]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top