bfuchs
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
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
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.
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.
Could also be that file is locked, path too long errors. That error can mean a bunch of things
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:\YourDestinationNetwork Folder\tes t0.txt"
...or see if you would be allowed to change the read only status of the destination file...
JeffCoachman
If so, you may wish to try renaming the (destination/network) file.
For example:
FileCopy "C:\YourSourceLocalFolder\
...or see if you would be allowed to change the read only status of the destination file...
JeffCoachman
ASKER
Hi Experts,
This is the command I'm trying to execute, has wrapping & no spaces, long path or read only issues..
Thanks,
Ben
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"
Thanks,
Ben
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.
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.
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
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
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.
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.
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
Do you think I must use shell to execute a DOS command within Access?
Thanks,
Ben
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.
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.
ASKER
Okay, lets try that.
Would you know the syntax?
Is this correct?
Thanks,
Ben
Would you know the syntax?
Is this correct?
Shell("copy E:\test\y.txt E:\test\x.txt")
Thanks,
Ben
Hi Ben,
I have never actually tried it in anything other than Excel, but I would guess it will be the same or similar:
However, its been a very long time since I did that - maybe not even this century - so I might be out of date!
Alan.
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
However, its been a very long time since I did that - maybe not even this century - so I might be out of date!
Alan.
ASKER
I get File not found msg, see attached.
But it does exists..
See second attachment.
Thanks,
Ben
Untitled.png
Capture.PNG
But it does exists..
See second attachment.
Thanks,
Ben
Untitled.png
Capture.PNG
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.
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.
ASKER
Hi
Get same for the following which also exists..
Thanks,
Ben
Get same for the following which also exists..
ReturnValue = Shell("Copy C:\temp\Untitled.png C:\Temp")
Thanks,
Ben
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):
If that works, please try this:
Thanks,
Alan.
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")
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")
Thanks,
Alan.
ASKER
Hi Ben,
Please can you try this form directly in Access VBA:
Thanks,
Alan.
Please can you try this form directly in Access VBA:
FileCopy "C:\Temp\Untitled.png", "C:\Temp\Test1\Untitled.png"
Thanks,
Alan.
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
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
Hi Ben,
I have replied on that question.
Let's put this one on hold until you have resolved the other issue.
Alan.
I have replied on that question.
Let's put this one on hold until you have resolved the other issue.
Alan.
ASKER
Hi Alan,
I tried that from debugger window and works.
So now what should be tried next?
Thanks,
Ben
I tried that from debugger window and works.
FileCopy "C:\Temp\Untitled.png", "C:\Temp\Test1\Untitled.png"
So now what should be tried next?
Thanks,
Ben
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:
Thanks,
Alan.
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"
Thanks,
Alan.
ASKER
Hi,
This works in middle code too.
Just the E:\CaspioBackups\ location which gives me BAD FILE OR NUMBER error.
Thanks,
Ben
This works in middle code too.
Just the E:\CaspioBackups\ location which gives me BAD FILE OR NUMBER error.
Thanks,
Ben
Hi Ben,
Have you tried the same form, like this:
Thanks,
Alan.
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"
Thanks,
Alan.
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
Thanks,
Ben
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
Thanks,
Ben
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
OK This seems like working.
Just wondering if file exists, wouldn't I get an error?
Thanks,
Ben
Just wondering if file exists, wouldn't I get an error?
Thanks,
Ben
Hi Ben,
See here for how to check if a file exists:
https://www.rondebruin.nl/ win/s9/win 003.htm
If it exists, then I guess delete it (depending on your scenario) before doing the FileCopy.
Alan.
See here for how to check if a file exists:
https://www.rondebruin.nl/
If it exists, then I guess delete it (depending on your scenario) before doing the FileCopy.
Alan.
ASKER
Hi,
Just to check existence of file, I have it in the code above
Thanks,
Ben
Just to check existence of file, I have it in the code above
If Dir(sDestinationFolder & NewestFile(sDestinationFolder, "*.mdb")) <> "" Then
Just was wondering why the FileCopy permits me to execute even when file exists?Thanks,
Ben
ASKER
Thank you very much Alan!
ASKER
Hi Alan,
Not sure why but this error (file path not found) started popping up again
Command used as suggested
and these are the values
Thanks,
Ben
Not sure why but this error (file path not found) started popping up again
Command used as suggested
FileCopy sDownloadFolder & sLastFile, sBackupFolder & SLastFile
and these are the values
filecopy "C:\Users\bfuchs\Downloads\Tables_2017-Nov-15_1108.zip","E:\CaspioBackups\Tables_2017-Nov-15_1108.zip"
Thanks,
Ben
Hi Ben,
If you put that last full string / command into the immediate window, does it work?
Thanks,
Alan.
If you put that last full string / command into the immediate window, does it work?
Thanks,
Alan.
ASKER
No, same error.
Thanks,
Ben
Thanks,
Ben
And if you do it from a command prompt - same machine, same credentials, does it work?
Alan.
Copy C:\Users\bfuchs\Downloads\Tables_2017-Nov-15_1108.zip E:\CaspioBackups\Tables_2017-Nov-15_1108.zip
Alan.
ASKER
Hi Alan,
It was my logic error this time, file indeed didn't exists..
I apologize.
Thanks,
Ben
It was my logic error this time, file indeed didn't exists..
I apologize.
Thanks,
Ben
No problem. Perhaps add a line to your code to check that the source file exists before doing the filecopy?
Alan.
Alan.
...