Getting error while trying to copy file to network folder using FileCopy command

Hi Experts,

I'm trying to use FileCopy command to copy a file from a local folder to a network location.
When I copy manually from the windows explorer it works fine.
However when I want use it thru FileCopy command I get the attached error

Assuming this must be given special permissions, any suggestions?
Untitled.png
LVL 5
bfuchsAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

 
arnoldCommented:
Unhandles space in the name of a folder where you are copying from/to.

...
0
 
AlanConsultantCommented:
Hi,

To follow on from Arnold's post above, if that is the issue, try wrapping the path / filename in quotes something like this:

"C:\Temp\Use This Folder\Filename.txt"


Alan.
0
 
Shaun VermaakTechnical Specialist/DeveloperCommented:
Could also be that file is locked, path too long errors. That error can mean a bunch of things
0
Improve Your Query Performance Tuning

In this FREE six-day email course, you'll learn from Janis Griffin, Database Performance Evangelist. She'll teach 12 steps that you can use to optimize your queries as much as possible and see measurable results in your work. Get started today!

 
Jeffrey CoachmanMIS LiasonCommented:
Oddly enough, ..this error also occurs if you are trying to over-write a read only file.
If so, you may wish to try renaming the (destination/network) file.

For example:
FileCopy "C:\YourSourceLocalFolder\test.txt", "h:\YourDestinationNetworkFolder\test0.txt"

...or see if you would be allowed to change the read only status of the destination file...

JeffCoachman
0
 
bfuchsAuthor Commented:
Hi Experts,

This is the command I'm trying to execute, has wrapping & no spaces, long path or read only issues..

FileCopy "C:\Users\bfuchs\Downloads\Tables_2017-Nov-05_2053.zip","E:\CaspioBackups"

Open in new window


Thanks,
Ben
0
 
AlanConsultantCommented:
Hi Ben,

Are you running this from a user (with credentials) that have sufficient access to the files / folders in question?

If you aren't sure, try running it as a domain admin, and see if that works.  If so, then it tells you there is a probably a permissions issue, in which case you need to narrow it down and give the actual username that will run this the required permissions.

Thanks,

Alan.
0
 
bfuchsAuthor Commented:
@Alan,

Okay from DOS I can run it even w/o admin privileges.
Same is if I do it manually from win explorer.

So how come cant I do it from Access?
Any workaround?

Thanks,
Ben
0
 
AlanConsultantCommented:
Hi Ben,

That is odd.  Did you try running it from Access, but from a domain admin user login?

If that works, it still implies a permissions issue.

Is your Access code using credentials other than the user that ran Access at all?

Alan.
0
 
bfuchsAuthor Commented:
Well Everything is being done as same user login, which is my admin user at my own pc..
Do you think I must use shell to execute a DOS command within Access?

Thanks,
Ben
0
 
AlanConsultantCommented:
Hi Ben,

That would be the next thing to try - at least you know that it works from there (if you run it manually).

I don't see why that would work, whereas VBA won't, but maybe best to focus on getting it working any which way, then you can come back to it later if / when you have the time.


Alan.
0
 
bfuchsAuthor Commented:
Okay, lets try that.
Would you know the syntax?

Is this correct?
Shell("copy E:\test\y.txt E:\test\x.txt")

Open in new window


Thanks,
Ben
0
 
AlanConsultantCommented:
Hi Ben,

I have never actually tried it in anything other than Excel, but I would guess it will be the same or similar:

Option Explicit

Sub Test()

Dim ReturnValue as Variant

ReturnValue = Shell("Copy C:\Users\bfuchs\Downloads\Tables_2017-Nov-05_2053.zip E:\CaspioBackups\")

End Sub

Open in new window



However, its been a very long time since I did that - maybe not even this century - so I might be out of date!

Alan.
0
 
bfuchsAuthor Commented:
I get File not found msg, see attached.
But it does exists..
See second attachment.

Thanks,
Ben
Untitled.png
Capture.PNG
0
 
AlanConsultantCommented:
Hi Ben,

The error seems to be specific, but can you amend the code to try copying a 'test.txt' file from, say, C:\Temp\Test1\ to, say, C:\Temp\Test2\ to test that it works at all.

Thanks,

Alan.
0
 
bfuchsAuthor Commented:
Hi

Get same for the following which also exists..
ReturnValue = Shell("Copy C:\temp\Untitled.png C:\Temp")

Open in new window


Thanks,
Ben
0
 
AlanConsultantCommented:
Okay, but maybe try copying it to a different location such as:

C:\Temp\Test1\

rather than copying it to the same location it is already in.

I'm just trying to get a really clean, unambiguous, test that can't have any other possible issues or unknowns introduced.

This would be perfect (create the Test1 folder manually beforehand):

ReturnValue = Shell("Copy C:\Temp\Untitled.png C:\Temp\Test1\Untitled.png")

Open in new window


If that works, please try this:

ReturnValue = Shell("Copy C:\Users\bfuchs\Downloads\Tables_2017-Nov-05_2053.zip E:\CaspioBackups\Tables_2017-Nov-05_2053.zip")

Open in new window


Thanks,

Alan.
0
 
bfuchsAuthor Commented:
No, followed exactly that & didnt help.
See attached.

Thanks,
Ben
Capture.PNG
0
 
AlanConsultantCommented:
Hi Ben,

Please can you try this form directly in Access VBA:

FileCopy "C:\Temp\Untitled.png", "C:\Temp\Test1\Untitled.png"

Open in new window




 Thanks,

Alan.
0
 
bfuchsAuthor Commented:
Hi Alan,

Not sure if its safe for me to continue using my pc at the moment, as I ran into disaster mode..
See following
https://www.experts-exchange.com/questions/29066852/How-to-recover-deleted-folder-by-code.html

Thanks,
Ben
0
 
AlanConsultantCommented:
Hi Ben,

I have replied on that question.

Let's put this one on hold until you have resolved the other issue.

Alan.
0
 
bfuchsAuthor Commented:
Hi Alan,

I tried that from debugger window and works.

FileCopy "C:\Temp\Untitled.png", "C:\Temp\Test1\Untitled.png"

Open in new window


So now what should be tried next?

Thanks,
Ben
0
 
AlanConsultantCommented:
Hi Ben,

Just trying to get my head back into this space :-)

Please can you insert that into your original code, and see if it works like that:

FileCopy "C:\Temp\Untitled.png", "C:\Temp\Test1\Untitled.png"

Open in new window



Thanks,

Alan.
0
 
bfuchsAuthor Commented:
Hi,

This works in middle code too.
Just the E:\CaspioBackups\ location which gives me BAD FILE OR NUMBER error.

Thanks,
Ben
0
 
AlanConsultantCommented:
Hi Ben,

Have you tried the same form, like this:

FileCopy "C:\Users\bfuchs\Downloads\Tables_2017-Nov-05_2053.zip","E:\CaspioBackups\Tables_2017-Nov-05_2053.zip"

Open in new window


Thanks,

Alan.
0
 
bfuchsAuthor Commented:
OK, This seems to work as well..
So what should I try next..

FYI- The error I'm getting is by following file copy command
    sBackupFolder = "E:\CaspioBackups\"
'    sLastFile = NewestFile(sBackupFolder, "*.zip")
    sDestinationFolder = "C:\Application\"
'    If FileDateTime(sBackupFolder & sLastFile) < Date Then
        sDownloadFolder = DownloadsFolder & "\"
        sLastFile = NewestFile(sDownloadFolder, "*.zip")
        FileCopy sDownloadFolder & sLastFile, sBackupFolder
        UnZip sDownloadFolder & sLastFile, sDestinationFolder, False
    sDestinationFolder = "C:\Application\"
    If Dir(sDestinationFolder & NewestFile(sDestinationFolder, "*.mdb")) <> "" Then
        Kill sDestinationFolder & "Tables.MDB"
        Name sDestinationFolder & NewestFile(sDestinationFolder, "*.mdb") As sDestinationFolder & "Tables.mdb"
    End If

Open in new window


Thanks,
Ben
0
 
AlanConsultantCommented:
Hi Ben,

Did you try this:

FileCopy sDownloadFolder & sLastFile, sBackupFolder & SLastFile

Open in new window



Alan.
0

Experts Exchange Solution brought to you by ConnectWise

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
 
bfuchsAuthor Commented:
OK This seems like working.
Just wondering if file exists, wouldn't I get an error?

Thanks,
Ben
0
 
AlanConsultantCommented:
Hi Ben,

See here for how to check if a file exists:

https://www.rondebruin.nl/win/s9/win003.htm

If it exists, then I guess delete it (depending on your scenario) before doing the FileCopy.


Alan.
0
 
bfuchsAuthor Commented:
Hi,

Just to check existence of file, I have it in the code above
 If Dir(sDestinationFolder & NewestFile(sDestinationFolder, "*.mdb")) <> "" Then

Open in new window

Just was wondering why the FileCopy permits me to execute even when file exists?

Thanks,
Ben
0
 
bfuchsAuthor Commented:
Thank you very much Alan!
0
 
bfuchsAuthor Commented:
Hi Alan,

Not sure why but this error (file path not found) started popping up again
Command used as suggested
FileCopy sDownloadFolder & sLastFile, sBackupFolder & SLastFile

Open in new window


and these are the values
filecopy "C:\Users\bfuchs\Downloads\Tables_2017-Nov-15_1108.zip","E:\CaspioBackups\Tables_2017-Nov-15_1108.zip"

Open in new window


Thanks,
Ben
0
 
AlanConsultantCommented:
Hi Ben,

If you put that last full string / command into the immediate window, does it work?

Thanks,

Alan.
0
 
bfuchsAuthor Commented:
No, same error.

Thanks,
Ben
0
 
AlanConsultantCommented:
And if you do it from a command prompt - same machine, same credentials, does it work?

Copy C:\Users\bfuchs\Downloads\Tables_2017-Nov-15_1108.zip E:\CaspioBackups\Tables_2017-Nov-15_1108.zip

Open in new window



Alan.
0
 
bfuchsAuthor Commented:
Hi Alan,

It was my logic error this time, file indeed didn't exists..

I apologize.

Thanks,
Ben
0
 
AlanConsultantCommented:
No problem.  Perhaps add a line to your code to check that the source file exists before doing the filecopy?

Alan.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.