system command to copy a file to a path with a space in it
Kenneth Brody
kenbrody at spamcop.net
Wed Mar 25 08:32:33 PDT 2015
On 3/25/2015 10:36 AM, Josh Reader wrote:
> Thanks to all who replied! Either of the following methods worked
> perfectly:
>
> Option 1
>
> -----------
>
> cm = "/bin/cp /reports/state.pdf \"/reports/Josh Reader/josh.pdf\""
> system cm
>
> Option 2
>
> ----------
>
> system "/bin/cp /reports/state.pdf '/reports/Josh Reader/josh.pdf'"
Note, of course, that both versions can be a single command. (No need to
create the temporary "cm" variable in the first version.) Assuming that the
filenames are hard-coded, that is.
The main thing is that the filename with spaces (or any "special
characters", such as semi-colons, ampersands, and so on) must be within
quotes in order for the shell to treat it as a single argument. Quotes can
be used in all cases, even if there are no "special characters" in the
filename. For example, this will work for any filename that doesn't contain
apostrophes (aka "single quotes"):
system "/bin/cp '" & SourceFilename & "' '" & DestFilename & "'"
--
Kenneth Brody
More information about the Filepro-list
mailing list