Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Cd or chdir problem
Message
From
02/12/2002 16:33:43
Dragan Nedeljkovich (Online)
Now officially retired
Zrenjanin, Serbia
 
General information
Forum:
Visual FoxPro
Category:
Coding, syntax & commands
Miscellaneous
Thread ID:
00728729
Message ID:
00728791
Views:
13
>Hi, I am having a problem with the commands cd or chdir as follows:
>
>I define a variable for the directory I want to go to as
>inputDir = "C:\Program Files\Quote.com\QCharts\Symbols\"
>
>but neither of the following will go to this directory
>
>chdir &inputDir
>chdir inputDir
>
>however, this does work
>
>cd "C:\Program Files\Quote.com\QCharts\Symbols\"

See FAQ #7841, and I've also written another one now (should be up in a few hours) about this specific problem. The others explained what and how, I tried to explain why. Until it gets published, here's the text:

Why doesn't this work:
cInputDir = "C:\Program Files\Quote.com\QCharts\Symbols\"
cd &cInputDir
Because it's a macro substitution of a filename with spaces. What Fox does when it sees the & sign, is to simply replace the value of the variable with its content, inline. So the command which it actually tries to execute is

cd C:\Program Files\Quote.com\QCharts\Symbols\

The runtime parses this until the first space in the file/directory name, and concludes that the command is "cd c:\Program" and that there's an extra string, "Files\Quote.com\QCharts\Symbols\" which means nothing to it, and errors out.

There are at least two ways out of this. The less good and the right way. The less good is to surround the macro with quotation marks:

cd "&cInputDir"

This works, but is not entirely elegant - we're using such a powerful thing as a macro, to convert string... into string. Since we already have that string in a variable, Fox can use it as a name expression:

cd (cInputDir)

This works with any situation where Fox needs a name of anything: in various Set ... to (cFilename) commands, in Use (cTable) alias (cAlias), in create table/cursor (cName), in Select .... from (cFromFile) into cursor/table (cToFile), in Set Printer to [name] (cPrinterName) etc etc. And it doesn't care if there are spaces in it or not, it simply works, and actually works faster than macro.

back to same old

the first online autobiography, unfinished by design
What, me reckless? I'm full of recks!
Balkans, eh? Count them.
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform