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

FSO file copy how do i get around run-time error 70

Status
Not open for further replies.

Santor

Technical User
Dec 2, 2002
22
US
How do I get around a Run-time error 70 "Permission Denied" when I try to run a fso.copy(filedest) or fso.MoveFile
file, destpath command (where fso is equal to a valid file name). Here is the actual code (I'm a newbie so be gentle)..

Public LogTemp As Object
Public fso As Object
Public TempFolder As String
Public PermFolder As String
'
Sub Main()
Set FSys = CreateObject("Scripting.FileSystemObject")
Today = Month(Date) & "-" & Day(Date) & "-" & Year(Date)
Set LogTemp = FSys.CreateTextFile("C:\Print_XFER\" & Today & "_log.txt", True)
LogTemp.writeline ("Files transfered " & Date)
LogTemp.writeline
TempFolder = "F:\PDF_TEMP\"
PermFolder = "F:\PDF\"
FolderName = TempFolder
RecurseFolderList (FolderName)
End Sub
'
Public Function RecurseFolderList(FolderName As String) _
As Boolean

On Error Resume Next
Dim fso, f, fc, fj, f1
Dim SubFolderName As String
Set fso = CreateObject("Scripting.FileSystemObject")
'
If Err.Number > 0 Then
RecurseFolderList = False
Exit Function
End If
'
On Error GoTo 0
If fso.FolderExists(FolderName) Then
Set f = fso.GetFolder(FolderName)
Set fc = f.Subfolders
Set fj = f.Files
'For each subfolder in the Folder
For Each f1 In fc
'Do something with the Folder Name
' Debug.Print f1
'Fpath = f1.Path
LogTemp.writeline
LogTemp.writeline (f1.Name)
'
RecurseFolderList (f1)
Next

'For each folder check for any files
For Each f1 In fj
LogTemp.writeline (f1)
LogTemp.writeline (FolderName)
' Set path for permanent storage of file
permpath = Replace(FolderName, TempFolder, PermFolder, , , vbTextCompare)
LogTemp.writeline (permpath)
LogTemp.writeline (permpath & "\" & f1.Name)
' Copy file to permanent storage location
If fso.FolderExists(permpath) Then
f1.Copy (permpath)
Else
LogTemp.writeline (permpath & ": Does not Exsist! Creating new folder!")
fso.CreateFolder permpath
If fso.FolderExists(permpath) Then
fso.MoveFile f1, permpath
Else
LogTemp.writeline ("ERROR! " & permpath & "Could not be created! " & f1 & " not moved!")
End If
End If

Next
'
Set f = Nothing
Set fc = Nothing
Set fj = Nothing
Set f1 = Nothing
'
Else
RecurseFolderList = False
End If
'
Set fso = Nothing
'
End Function
 
It seems that you don't have access to the folder that you are trying to write to. make sure that you can manually do so.
 
remember with NT security all the following is possible

1) you can see a directory and its contents but not be able to write to it
2) You can see a directory but not its contents
3) you can not see a directory but you can write to it
...

there are other permutations.

basically as Majd said you might not have writes to the directory that you are trying to right to or even read from. Unless you get your code running under a different security context you'll have get the security context (account) it is running under rights to all resources it tries to work with. NT/W2k/XP will not let you circumvent security via code.
 
Thanks for the responses.
I have administrator rights on the server where both the source and destination folders reside and permissions on these folders is Everyone/Full and I can get a file to copy with a DOS command string and the Shell command. (just one though, I think it might be a folder names to long for DOS problem). Its almost as if grabbing the file with FSO commands takes possesion of the file as if it were open. Is this correct?

John
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top