Programming Forums
User Name Password Register
 

RSS Feed
FORUM INDEX | TODAY'S POSTS | UNANSWERED THREADS | ADVANCED SEARCH

Reply
 
Thread Tools Display Modes
Old Mar 1st, 2005, 4:50 PM   #1
noleander
Newbie
 
Join Date: Mar 2005
Posts: 5
Rep Power: 0 noleander is on a distinguished road
How cd to directory with space in name (Windows)?

I'm running a PC with Windows XP. I've been a Unix person for 20 years, but now find myself having to work on Windows :-( Fortunately, I found bash, so I installed win-bash on my computer (version 0.4.1, dated last month). I am not using bash with CygWin ... just bash by itself.

QUESTION: How do I use the bash "cd" command to change to a directory whose name has a space in it? For example, here is what I've tried (they all fail):

cd C:\Program Files
cd "C:\Program Files"
declare pf="C:\Program Files"; cd $pf [after setting cdable_vars]
... and so on ....

Thanks in advance for any help,
neal
noleander is offline   Reply With Quote
Old Mar 1st, 2005, 5:20 PM   #2
Ooble
I eat cake for breakfast.
 
Ooble's Avatar
 
Join Date: Jul 2004
Location: In my box.
Posts: 4,434
Rep Power: 9 Ooble is on a distinguished road
Keep the double quotes, but don't specify the drive letter. To change drives, simply type "C:" (replace "C" with the drive in question). And I wouldn't advise setting variables in the command prompt - it doesn't work.
__________________
Me :: You :: Them
Ooble is offline   Reply With Quote
Old May 1st, 2005, 6:39 PM   #3
mackenga
Professional Programmer
 
Join Date: Mar 2005
Location: Glasgow, Scotland
Posts: 317
Rep Power: 4 mackenga is on a distinguished road
cd progra~1

Windows always comes up with a contortion of the long filename that will work as an MSDOS 8.3 name, and when all else fails you can do that. The above changes to "Program Files" - assuming that's in the present working directory.

Basically the method is to take the first six letters of the name that are valid in MSDOS 8.3 names (letters, numbers (usually except in the first position - correct me if this is just CP/M or something equally demonstrative of my age), hyphens, underscores (I think)). Then add ~1 and usually you have the right 8.3 version of the name.

If I had two files that had the same first six letters; eg "Program Files" and "Program Eaters", then one of them would be Progra~1 and one would be Progra~2. Since DIR no longer tells you these shortened names, finding out which is which is guesswork, but it doesn't change, so if you do have a situation like this you just have to remember which is which after gaining that information experimentally once.

Finally, not all filenames are contorted like this because they're too long. Sometimes, they're short, but have an invalid character. Best way to demonstrate this is by example: "A B" is invalid because of its space; it would, if I'm not mistaken, be contorted to "AB~1" to make it valid 8.3.

A weird one is a file with no name, just an extension; e.g. ".BAT". This is contorted to BAT~1. Weird, eh? Under Win98, this can't be run from the command prompt, because it has no name, and although it gets the batch file icon in Windows, double-clicking it leads to confusion. I'm not sure if this is true for Win XP too, but it's just the sort of weird but irrelevant problem that MS wouldn't bother fixing so it might still work as a party trick.

Ho hum. Fascinating, eh?

--
PS I just tried out that "file called .BAT" thing on this XP box, and it seems it does cause some confusion, but can now be run from the command prompt by typing ".bat". So they /did/ improve something between Win3.1 and the present day, then!

Last edited by mackenga; May 1st, 2005 at 6:42 PM.
mackenga is offline   Reply With Quote
Old Jul 18th, 2005, 1:46 PM   #4
levk
Newbie
 
Join Date: Jul 2005
Posts: 7
Rep Power: 0 levk is on a distinguished road
>Windows always comes up with a contortion of the long filename that will work as an >MSDOS 8.3 name, and when all else fails you can do that. The above changes ?>to "Program Files" - assuming that's in the present working directory.

That was before 2000 and XP - the 95, 98, and Me which were based on DOS anyways
levk is offline   Reply With Quote
Old Jul 21st, 2005, 9:26 AM   #5
mackenga
Professional Programmer
 
Join Date: Mar 2005
Location: Glasgow, Scotland
Posts: 317
Rep Power: 4 mackenga is on a distinguished road
levk: I'm on a WinXP machine here (not mine, I hasten to add), and it works on this one. The shortened names don't show up in the response to the DIR command, but you can still use them in commands.

Maybe this is not the case on NTFS and this machine's C drive is using VFAT, but I don't think so.
mackenga is offline   Reply With Quote
Old Jul 21st, 2005, 12:57 PM   #6
Ooble
I eat cake for breakfast.
 
Ooble's Avatar
 
Join Date: Jul 2004
Location: In my box.
Posts: 4,434
Rep Power: 9 Ooble is on a distinguished road
Windows Xp still creates the 8.3-length names for backwards-compatibility. I think some of it is still based on them too.
__________________
Me :: You :: Them
Ooble is offline   Reply With Quote
Reply

Bookmarks

« Previous Thread in Forum | Next Thread in Forum »

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump




DaniWeb IT Discussion Community
All times are GMT -5. The time now is 12:48 PM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC