in reply to Re^2: Trouble using a Win32 file path in an array
in thread Trouble using a Win32 file path in an array

Great info! On older versions of Windows, it didn't work that way, but you are correct on Win XP.

Update: not quite right...

C:\PROJECTS\xyz2009>cd c:/projects The system cannot find the path specified. C:\PROJECTS\xyz009>cd c:\projects C:\PROJECTS>
Another Update:
Revising my post in response to ikegami's post.
Apologize for being too cryptic.

1. First there are a whole lot of Windows things between Win 3.1 and Win XP: Win 98, WinNT, Win2K. I was thinking more about NT and 2K when I made the comment about previous versions of windows. At one time I had all 4 versions (98,NT,2K,XP) on my network for testing, but am down to just XP now. There are lots of quirks between these various versions.

2. I did some testing at the command prompt on XP and found:

C:\> C:\>cd projects/replyto C:\PROJECTS\replyto>
That was a "WOW" moment as I hadn't expected that forward slash to work with the cd command! But it did!

3. Then I found out that there is something special about the Drive: root- the forward slash doesn't work in this situation:

C:\PROJECTS\replyto>cd c:/projects The system cannot find the path specified. (didn't work) C:\PROJECTS\replyto>cd c:\projects (does work) C:\PROJECTS>
That little discovery is what prompted the update: "not quite right" comment.

4. More examples:

C:\PROJECTS>type testing/test.pl (doesn't work) The syntax of the command is incorrect. C:\PROJECTS>type "testing/test.pl" (doesn't work either) The system cannot find the file specified. C:\PROJECTS>type "testing\test.pl" (works) C:\PROJECTS>type testing\test.pl (works) C:\PROJECTS>cd ./testing (works) C:\PROJECTS\testing> C:\PROJECTS>cd /testing (works) C:\PROJECTS\testing>
Evidently sometimes the "forwards slash" works at the command line and sometimes it doesn't. There appears to be something special about drive root and I suppose some of these commands like "type" can get confused between path and "/" options.

5. In an attempt to try and avoid confusion, when writing Perl, I always use forward slash. That works with all Perl functions even with a path like c:/projects. As long as you don't go the the shell with say a command('blah'), forward slash is the way to go.

Replies are listed 'Best First'.
Re^4: Trouble using a Win32 file path in an array
by ikegami (Patriarch) on Sep 30, 2009 at 20:52 UTC
    [ In response to the update ]

    there are a whole lot of Windows things between Win 3.1 and Win XP: Win 98, WinNT, Win2K. I was thinking more about NT and 2K when I made the comment about previous versions of windows.

    Yes, except you talked of older versions where "/" wasn't accepted as a directory separator. I'm pretty sure none of those qualify.

    sometimes the "forwards slash" works at the command line and sometimes it doesn't.

    Yes, I mentioned that earlier in the thread, in addition to giving the reason and a workaround that works in most instances.

    In an attempt to try and avoid confusion, when writing Perl, I always use forward slash.

    Do you realize that Perl passes paths to Windows exactly as you provide them to Perl? It does NOT convert the slash first.

      Ikegami, I found your comments helpful.

      As far as WinNT and W2K, I will plead probably too ignorant to have even tried using forward slash on the command line. I don't remember forward slash working but that may be because I just never tried as part of usual practice.

      Maybe you can shed some light on the following...I am not sure why your "type" command works and mine doesn't! This doesn't appear to be a "syntax error". "cat" works on my system, but I have cygwin installed. I don't know why "type" can't find the file specified, but yet "cat" can.

      C:/TEMP/comment.txt #I know from experience that I can open this #filepath with Perl on Win XP and read it. C:\Projects>type C:/TEMP/comment.txt The syntax of the command is incorrect. C:\Projects>type "C:/TEMP/comment.txt" #doesn't work The system cannot find the file specified. #my command above looks similar to yours, but doesn't appear #to work for unknown reasons...your command works.... >type "c:/documents and settings/ikegami/bar.txt" foo C:\Projects>type 'C:/TEMP/comment.txt' #did work either The syntax of the command is incorrect. #but I didn't expect it to. C:\Projects>cat C:/TEMP/comment.txt (this works)

        Are you getting getting the builtin type or something else?

        Update: It's messed!

        C:\Documents and Settings\ikegami>copy nul "c:/documents and settings/ +ikegami/bar.txt" C:\Documents and Settings\ikegami>type "C:/documents and settings/ikeg +ami/bar.txt" C:\Documents and Settings\ikegami>cd\ C:\>type "C:/documents and settings/ikegami/bar.txt" The system cannot find the file specified.
Re^4: Trouble using a Win32 file path in an array
by ikegami (Patriarch) on Sep 28, 2009 at 18:27 UTC

    On older versions of Windows, it didn't work that way, but you are correct on Win XP.

    Honestly, Windows 3.1 is a whole other world. It wasn't even an OS.

    Not 100% sure, so prove me wrong if a newer Windows doesn't support "/" as the dir separator. Test code below.

    Update: not quite right...

    What isn't quite right? You (falsely) make it sound like something I said was wrong.


    Test to determine if your Windows supports "/" as the directory separator:

      ikegami meet Marshall, your long lost brother of the martalec tribe