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 Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Windows long directory names

Status
Not open for further replies.

williey

Technical User
Joined
Jan 21, 2004
Messages
242
I'm stump on this simple problem.. I need to change directory in perl. But the target directory has a long filename naming.

Here is the examples..None of them work.

Code:
system ("cd c:\\Program Files\\");

system ("cd c:\\Program\*");

------------------------------------------
There are 10 kinds of people in this world. One that understands binary and the other one that does not.
 
well if it's a longname problem "program files" in old school dos is "progra~1" - dunno if that's gonna help you though :-)

"In complete darkness we are all the same, only our knowledge and wisdom separates us, don't let your eyes deceive you.
 
Code:
my $Cmd = "cd \"c:\\Program Files\"";
system ($Cmd);
 
that's not a perl issue since you are using the operating system command, use the perl chdir() function:

Code:
chdir('c:/Program Files') or die "Can't change directory: $!";

but if you insist it might be:

Code:
system("cd c:/progra~1");
 
I tried them all and none of them works. Am I missing a library somewhere?

------------------------------------------
There are 10 kinds of people in this world. One that understands binary and the other one that does not.
 
You might need the /d switch:[tt]
system('cd /d "c:\\program files"')[/tt]
Without the /d, you can only cd within the current drive. (Yes, it is weird!)

I don't understand why [tt]chdir('c:/Program Files')[/tt] doesn't work for you; it would be a better option as it's platform-independent. Using "c:/progra~1" might seem attractive, but it's not very reliable, as "progra~1" might refer to some other directory.
 
Sorry, that should have been:[tt]
system('cd /d "c:\program files"')[/tt]
Backslashes within single-quotes don't need to be escaped.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top