Public Group

# problem using system("move")

This topic is 4817 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

In my c++ program, i'm trying to move a file to docs and setts all users but when I run the program, it says it's an invalid syntax error. I know this is because of the spaces in the dest directory name. I've tried a lot of things but I have had absolutely no luck. could someone please hlep me and maybe post an example so I know how to write it? Thanks.

##### Share on other sites
Why not just save yourself the trouble and use Win32 methods? Include windows.h
and use
BOOL MoveFile(  LPCTSTR lpExistingFileName,  LPCTSTR lpNewFileName);

or

BOOL MoveFileEx(  LPCTSTR lpExistingFileName,  LPCTSTR lpNewFileName,  DWORD dwFlags);

##### Share on other sites
ROFL, never knew a function existed in win32 api. But why would I think that, Microsoft has something for everything!, thanks!

##### Share on other sites
Try adding quotes to the command. Like so:

move "filename1" "filename2"

Now, to do that in a system command you will need to use escape characters, so do this (I think):

system ("move /" dir 1 blah blah blah /" /" dir 2 dfsdf dfdf /" ");

That should work.

##### Share on other sites
Interesting! Does the Win32's "Move" method pop up that cool window too (the one that comes up when you move things), or do you have to manually code that? Very interesting, I never thought to look in the Win32API for that either. =)

##### Share on other sites
Quote:
 Interesting! Does the Win32's "Move" method pop up that cool window too (the one that comes up when you move things)

No, it won't. The console window is used to enter MSDOS commands and is used by the routine 'system' to execute the commands you give it (on Windows).
Quote:
 system ("move /" dir 1 blah blah blah /" /" dir 2 dfsdf dfdf /" ");

'\' is used to escape characters, so it would actually be:
system ("move \" dir 1 blah blah blah \" \" dir 2 dfsdf dfdf \" ");

1. 1
2. 2
3. 3
frob
14
4. 4
5. 5

• 10
• 13
• 14
• 68
• 14
• ### Forum Statistics

• Total Topics
632134
• Total Posts
3004305

×