FileSystemObject Problem (1 Viewer)

MikeAngelastro

Registered User.
Local time
Today, 05:00
Joined
Mar 3, 2000
Messages
254
Hi,

I am importing files that I want to move to another folder after the import is complete. I tried the MoveFile method and I get an error 70 for permission denied. I then tried the CopyFile method with the idea of deleting the file after the copy. The copy works but the delete doesn't and throws the same error. Anyone have any idea why? The code I am using is below.

Dim fs As New FileSystemObject

'Move imported file to the imported file folder.
Source = FileName
Destination = IMPORTED_PO_FOLDER & Dir$(FileName)

'This works.
fs.CopyFile Source, Destination

'This does not work - error: 70 - Permission denied.
'The FileExists works.
If fs.FileExists(Destination) Then fs.DeleteFile (Source)

'This does not work - error: 70 - Permission denied.
fs.MoveFile Source, Destination

Thanks,

Mike
 

pono1

Registered User.
Local time
Today, 04:00
Joined
Jun 23, 2002
Messages
1,186
Mike,

Without a hard look at the code, here's a guess.

Your commands:
Copy -- this works
Move (which is a copy and a delete operation) -- doesn't work
Delete -- doesn't work

Do you have full permissions on the source folder? In Windows Explorer, right click the source folder, click Properties, then the Security tab to figure it out.

Regards,
Tim
 

MikeAngelastro

Registered User.
Local time
Today, 05:00
Joined
Mar 3, 2000
Messages
254
Hi Pono1,

Yes, I do have full permissions on the source folder. In fact I am able to manually cut and past from the source folder to the destination folder.

Thanks,

Mike
 

pono1

Registered User.
Local time
Today, 04:00
Joined
Jun 23, 2002
Messages
1,186
Mike,

Try code like this:
Code:
Dim fs As Variant
Set fs = CreateObject("Scripting.FileSystemObject")
  
Dim strSource As String
Dim strDestination As String

'get source and destination
strSource = "F:\Folder X\X.txt"
strDestination = "F:\Folder Y\"

'copy source to dest
fs.CopyFile strSource, strDestination

'kill source file
fs.deletefile strSource

Also, have you seen this article? It may or may not apply but does offer some work-arounds.

Last thought. Could the file's permissions (as opposed to the folder permissions) be restricting the delete?

Regards,
Tim
 

IMO

Now Known as ___
Local time
Today, 12:00
Joined
Sep 11, 2002
Messages
723
Mike,
Try this, I use this to import and move .csv files.

Dim InputDir, ImportFile As String, tblName As String, FinalName As String
Dim InputMsg As String
InputDir = "c:\YOUR DIRECTORY TO IMPORT FROM\"
ImportFile = Dir(InputDir & "\*.csv")
Do While Len(ImportFile) > 0
'tblName = Left(ImportFile, (InStr(1, ImportFile, ".") - 1)) 'Use this to import each file into separate tables.
tblName = "History" 'I use this to import all my files into one table.
DoCmd.TransferText acImportDelim, , tblName, InputDir & ImportFile, True
ImportFile = Dir
Loop
Dim fs
Set fs = CreateObject("Scripting.FileSystemObject")
'If fs.FileExists("c:\YOUR DIRECTORY TO IMPORT FROM\*.csv") Then
fs.MoveFile "c:\YOUR DIRECTORY TO IMPORT FROM\*.csv", "c:\YOUR DIRECTORY TO RECEIVE MOVED FILES\"

Let me know how you get on.

IMO
 

MikeAngelastro

Registered User.
Local time
Today, 05:00
Joined
Mar 3, 2000
Messages
254
Pono1 and IMO,

Thanks for all your help.

I opened an empty database for test purposes and found that the code I was using worked with the same paths. This result suggested that there may be some corruption where I had the code. Because moving the file was a small part of a large function that imported it, I retyped the code in the calling sub where the file-move would take place if the import was successful. This worked.

I also found that, if I used the "New" key word when I dimensioned the FileSystemObject, I did not need the "Set" command.

Thanks again for your help.

Mike
 

IMO

Now Known as ___
Local time
Today, 12:00
Joined
Sep 11, 2002
Messages
723
Glad it all worked out

IMO
 
R

rcassani

Guest
I am trying to write a similar routine. Using the code above I always get the error "Object doesn't support this property or method" on the fs.Move statement. Am I missing something?
 

MikeAngelastro

Registered User.
Local time
Today, 05:00
Joined
Mar 3, 2000
Messages
254
I believe that you do not have a reference to the MS Windows Scripting Host.
 
R

rcassani

Guest
Okay, I added the Reference but still get the error. Does it need to be positioned anywhere specific?

FYI, I am able to use the object to search a folder and populate a listbox with all the .xls files in it. I use the fs.Execute method as well as the fs.foundfiles.count method. I only get the error if I try to use the fs.Move, fs.Copy, or fs.Delete methods.
 

Users who are viewing this thread

Top Bottom