greeting Hans, hope all is well
this works:
Shell "cmd /c xcopy /y C:\Users\MyName\Documents\NewFolder\FileName.txt C:\Users\MyName\Documents\"
this does not work:
Shell "cmd /c xcopy /y C:\Users\MyName\Documents\New Folder\FileName.txt C:\Users\MyName\Documents\"
NewFolder versus New Folder
have tried seemingly every method I can think of to encapsulate the space in the path name, and googled quite a bit but no joy....
a senior moment perhaps...
space in path
-
- Administrator
- Posts: 78537
- Joined: 16 Jan 2010, 00:14
- Status: Microsoft MVP
- Location: Wageningen, The Netherlands
Re: space in path
How about
Shell "cmd /c xcopy /y ""C:\Users\MyName\Documents\New Folder\FileName.txt"" C:\Users\MyName\Documents\"
Shell "cmd /c xcopy /y ""C:\Users\MyName\Documents\New Folder\FileName.txt"" C:\Users\MyName\Documents\"
Best wishes,
Hans
Hans
-
- 3StarLounger
- Posts: 308
- Joined: 24 Dec 2015, 16:41
Re: space in path
nothing fires
it throws no error...but does nothing either (both cases newfolder -or- new folder)
also tried with or without the \ at the end
if I leave a space between " " it won't set up: Expected end of statement
....hmmm may have to set this up on a different PC/infrastructure and check - - while I see many q/a online on this topic, haven't found the handle to this
it throws no error...but does nothing either (both cases newfolder -or- new folder)
also tried with or without the \ at the end
if I leave a space between " " it won't set up: Expected end of statement
....hmmm may have to set this up on a different PC/infrastructure and check - - while I see many q/a online on this topic, haven't found the handle to this
-
- Administrator
- Posts: 7210
- Joined: 15 Jan 2010, 22:52
- Location: Middle of England
Re: space in path
[code]...FileName.txt"" C:\Users\MyName\Documents\[/code]
should be
[code]FileName.txt" "C:\Users\MyName\Documents\[/code]
(i.e. the space before C:\ is in the wrong place.)
Please ignore the above - apologies Hans!
Otherwise, I would try running:
Code: Select all
xcopy "C:\Users\MyName\Documents\New Folder\FileName.txt" "C:\Users\MyName\Documents\" /y
Note: based on BATch files I use, the "/y" would come at the end.
(And I assume you are changing "MyName" to something legitimate?)
Leif
-
- 3StarLounger
- Posts: 308
- Joined: 24 Dec 2015, 16:41
Re: space in path
hi Leif ... in reverse order:
xcopy "C:\Users\MyName\Documents\New Folder\FileName.txt" "C:\Users\MyName\Documents\" /y
- - this won't set up if I leave a space between " " it won't set up: Expected end of statement highlighting the 2nd clause
which is the same issue on the 2nd/middle example:
FileName.txt" "C:\Users\MyName\Documents\
and then in regard to the top/1st example:
...FileName.txt"" C:\Users\MyName\Documents\
- - - I did not set it up that way, didn't see it that way probably due to the line wrap and instead used:
...FileName.txt""C:\Users\MyName\Documents\
- - - this without spaces sets up, but nothing fired, as reported
baffled...
xcopy "C:\Users\MyName\Documents\New Folder\FileName.txt" "C:\Users\MyName\Documents\" /y
- - this won't set up if I leave a space between " " it won't set up: Expected end of statement highlighting the 2nd clause
which is the same issue on the 2nd/middle example:
FileName.txt" "C:\Users\MyName\Documents\
and then in regard to the top/1st example:
...FileName.txt"" C:\Users\MyName\Documents\
- - - I did not set it up that way, didn't see it that way probably due to the line wrap and instead used:
...FileName.txt""C:\Users\MyName\Documents\
- - - this without spaces sets up, but nothing fired, as reported
baffled...
-
- Administrator
- Posts: 7210
- Joined: 15 Jan 2010, 22:52
- Location: Middle of England
Re: space in path
My apologies - Not realising you were online, I had corrected my original post!
I'm surprised you are getting that error when running from a Command prompt...
I'm surprised you are getting that error when running from a Command prompt...
Leif
-
- Administrator
- Posts: 78537
- Joined: 16 Jan 2010, 00:14
- Status: Microsoft MVP
- Location: Wageningen, The Netherlands
Re: space in path
Do you have a specific reason for using Shell and xcopy instead of the built-in VBA command FileCopy?
Best wishes,
Hans
Hans
-
- 3StarLounger
- Posts: 308
- Joined: 24 Dec 2015, 16:41
Re: space in path
Leif - sorry misunderstanding - am in a sub did not move to command prompt
Hans - just came out of the gates with xcopy ... must have used before and was in my personal library...will redo via FileCopy and report in....
Hans - just came out of the gates with xcopy ... must have used before and was in my personal library...will redo via FileCopy and report in....
-
- Administrator
- Posts: 78537
- Joined: 16 Jan 2010, 00:14
- Status: Microsoft MVP
- Location: Wageningen, The Netherlands
Re: space in path
The syntax is
FileCopy "sourcefile", "targetfile"
No Shell needed.
FileCopy "sourcefile", "targetfile"
No Shell needed.
Best wishes,
Hans
Hans
-
- Administrator
- Posts: 78537
- Joined: 16 Jan 2010, 00:14
- Status: Microsoft MVP
- Location: Wageningen, The Netherlands
Re: space in path
Leif is correct that the /y switch should come at the end:
When I used paths and a file on my computer, this worked.
Code: Select all
Shell "cmd /c xcopy ""C:\Users\MyName\Documents\New Folder\FileName.txt"" C:\Users\MyName\Documents\ /y"
Best wishes,
Hans
Hans
-
- 3StarLounger
- Posts: 308
- Joined: 24 Dec 2015, 16:41
Re: space in path
To follow up:
FileCopy works
...which is to say, I experimented with spaces in the strings and all worked fine
anyone reading this string however should be aware that the FileCopy Destination string MUST include the file name. Didn't see that point in the documentation and so I learned this the hard way. An obvious thing if one is changing the file name such as appending a back-up date - - - but not intuitive when one is keeping the same file name and my first attempts just went as far as the folder which did not work....
have not circled back to try and figure out XCopy so that's still a mystery - - for another time....
FileCopy works
...which is to say, I experimented with spaces in the strings and all worked fine
anyone reading this string however should be aware that the FileCopy Destination string MUST include the file name. Didn't see that point in the documentation and so I learned this the hard way. An obvious thing if one is changing the file name such as appending a back-up date - - - but not intuitive when one is keeping the same file name and my first attempts just went as far as the folder which did not work....
have not circled back to try and figure out XCopy so that's still a mystery - - for another time....
-
- PlutoniumLounger
- Posts: 15641
- Joined: 24 Jan 2010, 23:23
- Location: brings.slot.perky
Re: space in path
Hi CData.
I have learned that it can be worthwhile
(a) to check that the target file does NOT exist before the FileCopy and
(b) to check that the target file DOES exist after the FileCopy.
Especially if I am writing an application that runs unattended.
Cheers
Chris
He who plants a seed, plants life.
-
- PlatinumLounger
- Posts: 5411
- Joined: 24 Jan 2010, 08:33
- Location: A cathedral city in England
Re: space in path
I may be being obtuse, but you are placing the whole of that command on a single line, aren't you?
The error message you report makes me think that you are using two separate lines, which is guaranteed to fail...
John Gray
"(or one of the team)" - how your hospital appointment letter indicates that you won't be seeing the Consultant...
"(or one of the team)" - how your hospital appointment letter indicates that you won't be seeing the Consultant...
-
- 3StarLounger
- Posts: 308
- Joined: 24 Dec 2015, 16:41
Re: space in path
hi CG ... actually in my case the target file will always pre-exist as the need is to over-write the prior file with a newer file..... so I may have more work to do....
hi JG, yes was always one code line. though note in my original first post that the code line began w 'Shell .... which could well be part of the issue.... haven't gone back to wrestle with the xcopy method any further
hi JG, yes was always one code line. though note in my original first post that the code line began w 'Shell .... which could well be part of the issue.... haven't gone back to wrestle with the xcopy method any further