[OT] Win32 and forward/backslashes (was "The format of filename")

Tim Chase python.list at tim.thechases.com
Thu Oct 26 19:37:37 CEST 2006


Tim Roberts wrote:
>> C:\temp\foo\bar>cd ..
>> C:\temp\foo>cd ..
>> C:\temp>cd /foo/bar
> 
> This one does not work for me, but as long as the initial slash is back,
> the rest can be foreward:
> 
>     C:\tmp>cd /foo/bar
>     The system cannot find the path specified.
>     C:\tmp>cd \foo/bar
>     C:\foo\bar>
> 
> What OS are you running?  Do you have the shell extensions enabled?  The
> latest cd does take a parameter (/d), so I wouldn't expect it to work.

This is cmd.exe on XP (SP2) with shell extensions enabled.

Note the subtle difference though...your "foo" is in the root 
directory...mine is in the current directory.  My result of

C:\temp>cd /foo/bar

is

C:\temp\foo\bar>

not

C:\foo\bar>

>> C:\temp>cmd < foo/bar/pip
>> [directory listing within a subshell]
> 
> I'm also surprised by this one.  I'll file this away for my next NT
> trivia contest...

You're a sick, sick fellow. :)  I just stumbled across it while 
trying various shot-in-the-dark permutations of command calls 
with f-slashes and b-slashes in paths.

>> C:\temp>cmd < /foo/bar/pip
>> The system cannot find the path specified.

And strangely,

C:\temp>cmd < /temp/foo/bar/pip

fails as well.  In more misadventures:

C:\temp>echo dir > zip
C:\temp>move zip foo/bar
C:\temp>dir /b foo\bar
pip
zip
C:\temp>move foo/bar/zip .
The system cannot find the path specified.

Okay...MOVE likes it as a destination, but not as a source. 
Aaaggghh...If I had any hair, I'd be pulling it out.  Move and 
copy are similar options.  Let's try copy:

C:\temp>move foo\bar\zip .
C:\temp>copy zip foo/bar
         1 file(s) copied.
C:\temp>del zip
C:\temp>copy foo/bar/zip .
foo\zip
100% copied         1 file(s) copied.

<sarcasm>Of course!  MOVE only accepts forward slashes in 
destinations, not the source.  But COPY accepts either.</sarcasm> 
  Maybe?

C:\temp>md foo\baz
C:\temp>dir /s/b
c:\temp\foo
c:\temp\zip
c:\temp\foo\bar
c:\temp\foo\baz
c:\temp\foo\zip
c:\temp\foo\bar\pip
c:\temp\foo\bar\zip

There's no "zip" in the "baz" directory, so let's copy it there:

C:\temp>copy foo/bar/zip foo/baz
foo\zip
Overwrite foo\zip? (Yes/No/All): y
The file cannot be copied onto itself.
         0 file(s) copied.

What the [expletive]!?  Well, there's a "zip" in our temp 
directory, but no "pip".  How about we try copying "pip" to the 
"baz" directory instead while keeping the same syntax as above?

C:\temp>copy foo/bar/pip foo/baz
The syntax of the command is incorrect.

BLOODY MADNESS!

Some OS programmer doesn't seem to have graduated from their 
CompSci program...

-tkc






More information about the Python-list mailing list