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!

Repost. FSO error 70. Why do I get this? How do I avoid it?

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)..

It is not a security issue since drive F: is a partition on my machine (the machine running the program).

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
 
Are you QUITE sure the error occurs on the copy or move code lines?
 
Strongm
Yes, quite sure, since when I comment out those lines the errors do not appear. Also, when I replaced those lines with a DOS string followed by a Shell command to perform the copy the program did copy one of the files and no errors appeared (I believe it only copied one file due to DOS not liking my long folder names on the other files).
Looking at my code, does it appear as though the files should be copying? Does grabbing a file with the FSO cause the file to appear open to anything else trying to access it?

Thanks
John
 
OK, the reason I ask is because the only way (so far) that I can get your code to generate the error you have mentioned is by having an already existing "C:\Print_XFER\" & Today & "_log.txt"
 
strongm,
So are you telling me that the code works fine for you unless that file exsists?

John
 
strongm
I promise this is the last ime I'll bother you on this.
I erased the _log.txt files and ran it again with the same "Run-time error 70. Permission Denied" error. I'm running it from within VB, would this mess it up?
When the error occurs chosing the "Debug" button pinpoints the error at the "f1.Copy (permpath)" statement. I don't understand how the _log.txt file would have any effect since CreateTextFile overwrites if it exists anyway.
I'm at my wits end here. Any more thoughts?
I'm this close (2 fingers held up very close together) to adding a API function to do this step but this is virgin territory to me.

Thanks for helping
John
 
How about file properties? May be it's silly question but ... are you sure it's not ReadOnly or Hidden?
 
Sorry it's me again. How about Folder properties? If folder is ReadInly and File not, nevertheless this Error 70 will appear.
 
Both the folder and file are set to archive only.
I take it both of you have copy/moved files using the FSO commands before with out this problem.

John
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top