Avatar of bfuchs
bfuchs
Flag for United States of America asked on

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
Microsoft AccessWindows OSNetworkingFile Sharing SoftwareScripting Languages

Avatar of undefined
Last Comment
Alan

8/22/2022 - Mon
arnold

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

...
Alan

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.
Shaun Vermaak

Could also be that file is locked, path too long errors. That error can mean a bunch of things
All of life is about relationships, and EE has made a viirtual community a real community. It lifts everyone's boat
William Peck
Jeffrey Coachman

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
bfuchs

ASKER
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
Alan

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.
⚡ FREE TRIAL OFFER
Try out a week of full access for free.
Find out why thousands trust the EE community with their toughest problems.
bfuchs

ASKER
@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
Alan

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

ASKER
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
I started with Experts Exchange in 2004 and it's been a mainstay of my professional computing life since. It helped me launch a career as a programmer / Oracle data analyst
William Peck
Alan

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

ASKER
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
Alan

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.
⚡ FREE TRIAL OFFER
Try out a week of full access for free.
Find out why thousands trust the EE community with their toughest problems.
bfuchs

ASKER
I get File not found msg, see attached.
But it does exists..
See second attachment.

Thanks,
Ben
Untitled.png
Capture.PNG
Alan

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

ASKER
Hi

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

Open in new window


Thanks,
Ben
Your help has saved me hundreds of hours of internet surfing.
fblack61
Alan

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

ASKER
No, followed exactly that & didnt help.
See attached.

Thanks,
Ben
Capture.PNG
Alan

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.
⚡ FREE TRIAL OFFER
Try out a week of full access for free.
Find out why thousands trust the EE community with their toughest problems.
bfuchs

ASKER
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
Alan

Hi Ben,

I have replied on that question.

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

Alan.
bfuchs

ASKER
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
Experts Exchange has (a) saved my job multiple times, (b) saved me hours, days, and even weeks of work, and often (c) makes me look like a superhero! This place is MAGIC!
Walt Forbes
Alan

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

ASKER
Hi,

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

Thanks,
Ben
Alan

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.
⚡ FREE TRIAL OFFER
Try out a week of full access for free.
Find out why thousands trust the EE community with their toughest problems.
bfuchs

ASKER
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
ASKER CERTIFIED SOLUTION
Alan

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
bfuchs

ASKER
OK This seems like working.
Just wondering if file exists, wouldn't I get an error?

Thanks,
Ben
Alan

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.
Experts Exchange is like having an extremely knowledgeable team sitting and waiting for your call. Couldn't do my job half as well as I do without it!
James Murphy
bfuchs

ASKER
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
bfuchs

ASKER
Thank you very much Alan!
bfuchs

ASKER
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
⚡ FREE TRIAL OFFER
Try out a week of full access for free.
Find out why thousands trust the EE community with their toughest problems.
Alan

Hi Ben,

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

Thanks,

Alan.
bfuchs

ASKER
No, same error.

Thanks,
Ben
Alan

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.
This is the best money I have ever spent. I cannot not tell you how many times these folks have saved my bacon. I learn so much from the contributors.
rwheeler23
bfuchs

ASKER
Hi Alan,

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

I apologize.

Thanks,
Ben
Alan

No problem.  Perhaps add a line to your code to check that the source file exists before doing the filecopy?

Alan.