How do you copy a file to another directory, say, "script.iss" in the current directory to "c:\temp"?
Printable View
How do you copy a file to another directory, say, "script.iss" in the current directory to "c:\temp"?
:DCode:system("copy script.iss c:\\temp");
Somehow I'm thinking that isn't the cleanest way. :D
Well, there's there's always the API...Quote:
CopyFile
The CopyFile function copies an existing file to a new file.
The CopyFileEx function provides two additional capabilities. CopyFileEx can call a specified callback function each time a portion of the copy operation is completed, and CopyFileEx can be canceled during the copy operation.
BOOL CopyFile(
LPCTSTR lpExistingFileName, // name of an existing file
LPCTSTR lpNewFileName, // name of new file
BOOL bFailIfExists // operation if file exists
);
Parameters
lpExistingFileName
[in] Pointer to a null-terminated string that specifies the name of an existing file.
Windows NT/2000 or later: In the ANSI version of this function, the name is limited to MAX_PATH characters. To extend this limit to nearly 32,000 wide characters, call the Unicode version of the function and prepend "\\?\" to the path. For more information, see File Name Conventions.
Windows 95/98/Me: This string must not exceed MAX_PATH characters.
lpNewFileName
[in] Pointer to a null-terminated string that specifies the name of the new file.
Windows NT/2000 or later: In the ANSI version of this function, the name is limited to MAX_PATH characters. To extend this limit to nearly 32,000 wide characters, call the Unicode version of the function and prepend "\\?\" to the path. For more information, see File Name Conventions.
Windows 95/98/Me: This string must not exceed MAX_PATH characters.
bFailIfExists
[in] Specifies how this operation is to proceed if a file of the same name as that specified by lpNewFileName already exists. If this parameter is TRUE and the new file already exists, the function fails. If this parameter is FALSE and the new file already exists, the function overwrites the existing file and succeeds
I saw that but I don't know what constants to pass and check for. Got an example?
Uh......is what I'd assume ;)Code:CopyFile("script.iss", "c:\\temp\\script.iss", FALSE);
But it returns something; what constants (ERROR_SUCCESS, etc) can I use to check the return value?
what is wrong with system?Quote:
Originally posted by parksie
:DCode:system("copy script.iss c:\\temp");
Doesn't that fork out a process?
yeah, i think, but..
is this for the installer thing?
for something small it should be fine.
Yes, it is. Let's see what this does...
ERROR_SUCCESS == oxymoron ;)Quote:
Originally posted by filburt1
But it returns something; what constants (ERROR_SUCCESS, etc) can I use to check the return value?
How would I know if that executed correctly; does system return the return value of the process?Quote:
Originally posted by parksie
:DCode:system("copy script.iss c:\\temp");
Don't know. However, if it fails, then "File not found" or something (whatever is printed by copy) will be outputted to stdout or stderr (can't remember which, never tested :p).
Probably stderr. :)
I know system("cls") and the copy-thing you were talking about, but are there some else system-commands?
system just passes them to the underlying system, in this case DOS (or for NT-based, cmd.exe).
So you could do system("echo %PATH%"); :D
ok, cool.......
can you pass programs to start? like.....system("program.exe")?
Anything that can be interpreted by the command line interpreter :)
kewl, will try it.........
system() is cool. =). Just my 2 cents.
Z.
also, there is ShellExecute()
this is API
I like system("command")
didn't thought it was such a command........
try it!