Page 1 of 1

When to use double and single quotes in TI?

Posted: Fri Jul 16, 2010 1:46 am
by harrytm1
Hi all,

I'm trying to write a ExecuteCommand to trigger a DOS xcopy in the Epilog. My original filepath and destination filepath both contain spaces.

Filepath = 'z:\Folder A\';
Filename = 'export.csv';
Filepathname = Filepath | Filename;
FilepathNew = 'z:\Folder B\';

Can you kindly advice when it is necessary to use double quotes and single quotes? Do I use it when I'm using variables like Filepathnew in the first parameter in the ExecuteCommand function because the parameter is supposed to be encased in a pair of single quotes? Or is it because, after resolving the FilepathNew, the actual path contains space?

Thanks.

Re: When to use double and single quotes in TI?

Posted: Fri Jul 16, 2010 4:19 am
by Alan Kirk
harrytm1 wrote: I'm trying to write a ExecuteCommand to trigger a DOS xcopy in the Epilog. My original filepath and destination filepath both contain spaces.

Filepath = 'z:\Folder A\';
Filename = 'export.csv';
Filepathname = Filepath | Filename;
FilepathNew = 'z:\Folder B\';

Can you kindly advice when it is necessary to use double quotes and single quotes? Do I use it when I'm using variables like Filepathnew in the first parameter in the ExecuteCommand function because the parameter is supposed to be encased in a pair of single quotes? Or is it because, after resolving the FilepathNew, the actual path contains space?
Single quotes are what you use to surround literal strings in TurboIntegrator. That distinguishes the text contained within those quotes from function names and variable names. Therefore Filepath has no single quotes around it because it's a variable name. 'z:\Folder A\' on the other hand, does have to be surrounded by quotes, because it's a literal string.

Double quotes have no meaning within TI itself (not in its syntax anyway), so disregard them in that sense. The only place that they matter is in the command line that you pass to Windows. Consequently what you need to do is create the command line just as if you were running it directly in a command line window, and build the string accordingly. Don't think about TI at all when you do this.

If you run the command directly in the command line window it would need to be as follows. (I'm using Y:\Temp where you used Z:\; also the batch file that I created to execute the command is Y:\Temp\XCopyExport.bat):

Code: Select all

Y:\Temp\XCopyExport.bat "Y:\Temp\Folder A\Export.csv" "Y:\Temp\Folder B\"
The double quotes around the two paths are there because Windows, not TI needs them to overcome the fact that the paths have spaces in them. (And with apologies to my fellow admin Mr. Rowe, I still hate spaces in paths and would use underscores. But you go with what you've got.)

This means that you need to embed double quotes into the string that you pass to the ExecuteCommand function.

Now me, I don't like doing that using a literal string for the double quotes. I find that it makes the code too hard to read and debug. ("Is that a double quote and a single quote? Three single quotes, maybe?") So what I do instead is to assign the double quote character (drawn from the Char() function) to a variable and use that variable wherever I need a double quote. Like so:

Code: Select all

SC_QUOTE_DOUBLE = Char(34); 

Filepath = 'Y:\Temp\Folder A\';
Filename = 'Export.csv';
Filepathname = Filepath | Filename;
FilepathNew = 'Y:\Temp\Folder B\';

s_Command = 'Y:\Temp\XCopyExport.bat ' | SC_QUOTE_DOUBLE | Filepathname | SC_QUOTE_DOUBLE | ' ' | SC_QUOTE_DOUBLE | FilepathNew | SC_QUOTE_DOUBLE;

ExecuteCommand ( s_Command, 0 );
What you're essentially doing here is embedding double quote characters into the command string. They're embedded on either side of the FilePathName variable, and the FilePathNew variable. If you output the variable s_Command, you should see it match the code that I've quoted earlier. (Note the inclusion of spaces between the batch file name and the first argument, and between the first argument and the second one. These are as important as the double quotes.)

For the sake of completeness the batch file is:

Code: Select all

xcopy %1 %2
Parameter 1 will receive the string:

Code: Select all

"Y:\Temp\Folder A\Export.csv"
(Including the double quotes on either side)

Parameter 2 will receive:

Code: Select all

"Y:\Temp\Folder B\"

Re: When to use double and single quotes in TI?

Posted: Fri Jul 16, 2010 1:32 pm
by harrytm1
Oh Alan, I'm not worthy!!!!

Thank you so much for your help!