![]() |
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 |
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.
|
:
cd progra~1Windows 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! |
>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: 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. |
Windows Xp still creates the 8.3-length names for backwards-compatibility. I think some of it is still based on them too.
|
| All times are GMT -5. The time now is 4:12 PM. |
Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC