Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Executing file copy with quotes in file name not working

Status
Not open for further replies.

HoustonGSC

IS-IT--Management
May 11, 2007
13
US
Please excuse any text wrapping.
I have a dataset that is in the following format:
'UN.GS4P.GSRT087.GSRT087C.TXT-CST02824-' and yes the quotes are part of the filename and I cannot rename the file.

I want to perform a copy of this dataset using File::Copy to another directory with the name of E:\FTPfiles\gs@cst02824@gsrt087.txt

The problem is the single quotes in the original dataset name. I have tried escaping them such as :
$filename=~s/\'/\\'/g;

but the copy continues to fail. This is what the script command is :
copy($filename, $szNewBBSfile) == 0 or logmsg("$szBBScmd file cannot be copied: ", $?);

The final copy command looks like this:
copy(e:\FTPfiles\mainframe\datafiles\done\\'UN.GS4P.GSRT087.GSRT087C.TXT-CST02824-\', E:\FTPfiles\gs@cst02824@gsrt087.txt)


When I display $? it says the return code was 0 but I never see the destination file created.

Any ideas?
 
The logic in your logging is incorrect.

File::Copy's 'copy' function returns 0 on failure, not success. Have a look at the contents of $! - that should hold any error message.

How do $filename and $szNewBBSfile get set?
 
The contents of $! says: No such file or directory
$filename gets set at the beginning of the script as such:
$filename = $ARGV[0]

$szNewBBSfile gets built as such:
my $bbsfilepath="E:\\FTPfiles\\mainframe\\ftp2gscapps\\";
$szBBSName=lc($companyid . "@" . $record[3] . "@" . $record[1] . $fileext);
$szNewBBSfile = $bbsfilepath.$szBBSName;

I have carefully scrutinized the final copy command and it all looks good :
copy(e:\FTPfiles\mainframe\datafiles\done\\'UN.GS4P.GSRT087.GSRT087C.TXT-CST02824-\', E:\FTPfiles\mainframe\ftp2gscapps\gs@cst02824@gsrt087.txt)

If I don't escape the single quotes in the input file, I get a different error.
 
copy(e:\FTPfiles\mainframe\datafiles\done\\'UN.GS4P.GSRT087.GSRT087C.TXT-CST02824-\', E:\FTPfiles\mainframe\ftp2gscapps\gs@cst02824@gsrt087.txt)


shouldn't that be

copy(e:\FTPfiles\mainframe\datafiles\done\\\'UN.GS4P.GSRT087.GSRT087C.TXT-CST02824-\', E:\FTPfiles\mainframe\ftp2gscapps\gs@cst02824@gsrt087.txt)


and I say just flip all the slashes around and save yourself some trouble.

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
[noevil]
Travis - Those who say it cannot be done are usually interrupted by someone else doing it; Give the wrong symptoms, get the wrong solutions;
 
I guess I said that without really thinking.. shouldn't there be quotes around all of that data anyway?

copy('e:/FTPfiles\mainframe/datafiles/done/\'UN.GS4P.GSRT087.GSRT087C.TXT-CST02824-\'', 'E:/FTPfiles/mainframe/ftp2gscapps/gs@cst02824@gsrt087.txt')


Try that command and see if you get better results.


Travis

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
[noevil]
Travis - Those who say it cannot be done are usually interrupted by someone else doing it; Give the wrong symptoms, get the wrong solutions;
 
Thanks for all the responses. I think I was getting my shorts all bunched up with the return code. I was expecting a successful copy to have a RC=0 but instead as someone pointed out RC=1 means success. I overlooked that when I reviewed the File::Copy documentation.

In my original post, I stated the copy command as:
copy($filename, $szNewBBSfile) == 0 or logmsg("$szBBScmd file cannot be copied: ", $?);

So even though the command succeeded, I would trigger the file cannot be copied error message which was incorrect.

I think I have it working now. Thanks again for all responses.



 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top