path delimiter in windows platform("/" could change to "\"?)

Discussion in 'Perl Misc' started by Alont, Sep 26, 2004.

  1. Alont

    Alont Guest

    #!F:\Perl\bin\perl
    $specified_folder = 'D:\Inetpub\wwwroot';
    use File::Finder;
    @files =
    File::Finder->type('f')->name('*.html')->in($specified_folder);
    foreach(@files)
    {print $_, "\n";}

    the result:
    D:\Inetpub\wwwroot/article/layout/2004/csslayout/fourbox_touch.html
    D:\Inetpub\wwwroot/article/layout/2004/csslayout/onebox.html
    D:\Inetpub\wwwroot/article/layout/2004/3h2l.html

    there are possible to change the "/" to "\" in windows platform? I
    mean if there have a syntax switch to do this so I don't have to
    replace every "/".
    If this is a faq please tell me the perl document name, thank you.
    --
    Your fault as a Government is My failure as a Citizen.
     
    Alont, Sep 26, 2004
    #1
    1. Advertising

  2. Alont wrote:
    > #!F:\Perl\bin\perl
    > $specified_folder = 'D:\Inetpub\wwwroot';


    I suggest to use
    $specified_folder = 'D:/Inetpub/wwwroot';
    here.

    > use File::Finder;
    > @files =
    > File::Finder->type('f')->name('*.html')->in($specified_folder);
    > foreach(@files)
    > {print $_, "\n";}
    >
    > the result:
    > D:\Inetpub\wwwroot/article/layout/2004/csslayout/fourbox_touch.html
    > D:\Inetpub\wwwroot/article/layout/2004/csslayout/onebox.html
    > D:\Inetpub\wwwroot/article/layout/2004/3h2l.html


    So?

    > there are possible to change the "/" to "\" in windows platform? I
    > mean if there have a syntax switch to do this so I don't have to
    > replace every "/".


    Why do you want to replace the forward slash with a backslash? Did you
    encounter an _actual_ problem with forward slashes or do you just _perceive_
    them as a problem?

    jue
     
    Jürgen Exner, Sep 26, 2004
    #2
    1. Advertising

  3. Alont <> wrote in news:41563101.225947687@130.133.1.4:

    > #!F:\Perl\bin\perl


    You are missing:

    use strict;
    use warnings;

    > $specified_folder = 'D:\Inetpub\wwwroot';


    Windows can deal with / just fine. In fact, I would recommend sticking with
    / rather than \.

    > use File::Finder;
    > @files =
    > File::Finder->type('f')->name('*.html')->in($specified_folder);
    > foreach(@files)
    > {print $_, "\n";}
    >
    > the result:
    > D:\Inetpub\wwwroot/article/layout/2004/csslayout/fourbox_touch.html
    > D:\Inetpub\wwwroot/article/layout/2004/csslayout/onebox.html
    > D:\Inetpub\wwwroot/article/layout/2004/3h2l.html
    >
    > there are possible to change the "/" to "\" in windows platform? I
    > mean if there have a syntax switch to do this so I don't have to
    > replace every "/".
    > If this is a faq please tell me the perl document name, thank you.




    --
    A. Sinan Unur
    d
    (remove '.invalid' and reverse each component for email address)
     
    A. Sinan Unur, Sep 26, 2004
    #3
  4. Alont

    Alont Guest

    "Jürgen Exner" <>Wrote at Sun, 26 Sep 2004
    03:16:45 GMT:
    >Why do you want to replace the forward slash with a backslash? Did you
    >encounter an _actual_ problem with forward slashes or do you just _perceive_
    >them as a problem?
    >


    if the output string is "\", I can open the file by double-click the
    path in Editplus, "/" can't let me do that easy thing.
    --
    Your fault as a Government is My failure as a Citizen.
     
    Alont, Sep 26, 2004
    #4
  5. Alont

    Alont Guest

    "A. Sinan Unur" <>Wrote at 26 Sep 2004
    03:26:48 GMT:
    >Windows can deal with / just fine. In fact, I would recommend sticking with
    >/ rather than \.


    notepad can't open
    D:/Inetpub/wwwroot/article/layout/2004/csslayout/onebox_absolute.html
    EditPlus also can't,the "common dialog" box can't deal with "/" path
    --
    Your fault as a Government is My failure as a Citizen.
     
    Alont, Sep 26, 2004
    #5
  6. Alont <> wrote:

    > EditPlus also can't,the "common dialog" box can't deal with "/" path



    You should report that bug in EditPlus, maybe they will fix it...


    Until then:

    tr#/#\\#; # replace sensible slashes with silly slashes


    --
    Tad McClellan SGML consulting
    Perl programming
    Fort Worth, Texas
     
    Tad McClellan, Sep 26, 2004
    #6
  7. Alont

    Peter Scott Guest

    In article <41563101.225947687@130.133.1.4>,
    Alont <> writes:
    >the result:
    >D:\Inetpub\wwwroot/article/layout/2004/csslayout/fourbox_touch.html
    >D:\Inetpub\wwwroot/article/layout/2004/csslayout/onebox.html
    >D:\Inetpub\wwwroot/article/layout/2004/3h2l.html
    >
    >there are possible to change the "/" to "\" in windows platform?


    use File::Spec; # Core module
    $file = File::Spec->canonpath($file);

    --
    Peter Scott
    http://www.perldebugged.com/
    *** NEW *** http://www.perlmedic.com/
     
    Peter Scott, Sep 26, 2004
    #7
  8. W. Citoan <> wrote:
    > On 26 Sep 2004 03:26:48 GMT, A. Sinan Unur wrote:
    >> Alont <> wrote in news:41563101.225947687@130.133.1.4:
    >>
    >> > $specified_folder = 'D:\Inetpub\wwwroot';

    >>
    >> Windows can deal with / just fine. In fact, I would recommend
    >> sticking with / rather than \.

    >
    > Huh? Do you actually mean Perl on Windows?



    Yes.

    Have you tried using open() on a path that uses forward slashes?

    Didn't it work when you tried it?


    > Because Windows (at least
    > XP) cannot deal with / if there are spaces in the path.
    >
    > C:\>c:/Program Files/Internet Explorer/iexplore.exe
    > 'c:/Program' is not recognized as an internal or external command,
    > operable program or batch file.



    Windows can deal with / just fine.

    What you have shown is that the Windows _command interpreter_
    cannot deal with slash (because it is using it for something else).

    If the filespec is not destined for the command interpreter, then
    forward slashes will work just fine on Windows filesystems.


    > Perl hides you from this, but if you're outputting for external use,

    ^^^^^^^^^^^^^^^^
    > than you have to deal with it.



    If you are outputting for external use *in the command interpreter*.


    --
    Tad McClellan SGML consulting
    Perl programming
    Fort Worth, Texas
     
    Tad McClellan, Sep 26, 2004
    #8
  9. "W. Citoan" <> wrote in
    news::

    > On 26 Sep 2004 03:26:48 GMT, A. Sinan Unur wrote:
    >> Alont <> wrote in news:41563101.225947687@130.133.1.4:
    >>
    >> > $specified_folder = 'D:\Inetpub\wwwroot';

    >>
    >> Windows can deal with / just fine. In fact, I would recommend
    >> sticking with / rather than \.

    >
    > Huh? Do you actually mean Perl on Windows? Because Windows (at least
    > XP) cannot deal with / if there are spaces in the path.
    >
    > C:\>c:/Program Files/Internet Explorer/iexplore.exe
    > 'c:/Program' is not recognized as an internal or external command,
    > operable program or batch file.


    Huh? Do you realize that in the example you give, it does not matter what
    slash you are using? In the cmd.exe shell, regardless of the slash, you
    need to enclose file paths that include space in double quotation marks.
    On the other hand,

    "c:/Program Files/Internet Explorer/iexplore.exe"

    works just fine (i.e. runs Internet Explorer).

    > Perl hides you from this, but if you're outputting for external use,
    > than you have to deal with it.


    If the program you are dealing with is deficient in its handling of file
    names and paths. By the way, notepad can deal with these paths just fine:

    notepad "c:\www/unur/htdocs/index.html"

    works just fine (XPP).

    --
    A. Sinan Unur
    d
    (remove '.invalid' and reverse each component for email address)
     
    A. Sinan Unur, Sep 26, 2004
    #9
  10. (Peter Scott) wrote in news:tTA5d.114117$%S.21618
    @pd7tw2no:

    > In article <41563101.225947687@130.133.1.4>,
    > Alont <> writes:
    >>the result:
    >>D:\Inetpub\wwwroot/article/layout/2004/csslayout/fourbox_touch.html
    >>D:\Inetpub\wwwroot/article/layout/2004/csslayout/onebox.html
    >>D:\Inetpub\wwwroot/article/layout/2004/3h2l.html
    >>
    >>there are possible to change the "/" to "\" in windows platform?

    >
    > use File::Spec; # Core module
    > $file = File::Spec->canonpath($file);
    >


    That is good advice. However,

    #! perl

    use strict;
    use warnings;

    use File::Finder;
    use File::Spec::Functions qw( catfile );

    my $dir = catfile 'c:', 'www', 'unur', 'htdocs';
    my @html = File::Finder->type('f')->name('*.html')->in($dir);

    print "$_\n" for (@html);

    __END__

    This script will output:

    C:\www\unur\htdocs/index.html
    C:\www\unur\htdocs/comp/anti-spam-howto.html
    C:\www\unur\htdocs/comp/c-examples.html
    C:\www\unur\htdocs/comp/index.html

    so, the OP would still be asking the same question. (Note that I do not
    think the behavior above is a problem, but I _think_ it is caused by
    File::Find::pathCombine using / for both Unix and Win32 platforms).

    --
    A. Sinan Unur
    d
    (remove '.invalid' and reverse each component for email address)
     
    A. Sinan Unur, Sep 26, 2004
    #10
  11. Alont <> wrote in news:41584b6e.232712937@130.133.1.4:

    > "A. Sinan Unur" <>Wrote at 26 Sep 2004
    > 03:26:48 GMT:
    >>Windows can deal with / just fine. In fact, I would recommend sticking
    >>with / rather than \.

    >
    > notepad can't open
    > D:/Inetpub/wwwroot/article/layout/2004/csslayout/onebox_absolute.html
    > EditPlus also can't,the "common dialog" box can't deal with "/" path


    Are you sure? Notepad has no problem with such paths on my Win 98 or Win XP
    systems.

    --
    A. Sinan Unur
    d
    (remove '.invalid' and reverse each component for email address)
     
    A. Sinan Unur, Sep 26, 2004
    #11
  12. Alont

    Alont Guest

    "A. Sinan Unur" <>Wrote at 26 Sep 2004
    16:53:17 GMT:
    >
    >Huh? Do you realize that in the example you give, it does not matter what
    >slash you are using? In the cmd.exe shell, regardless of the slash, you
    >need to enclose file paths that include space in double quotation marks.
    >On the other hand,
    >
    >"c:/Program Files/Internet Explorer/iexplore.exe"
    >
    >works just fine (i.e. runs Internet Explorer).


    My question is "Windows" not "Dos", if you open a file from Windows
    "Common Dialog Box" it must fail
    --
    Your fault as a Government is My failure as a Citizen.
     
    Alont, Sep 27, 2004
    #12
  13. Alont <> wrote in news:4158670e.59929671@130.133.1.4:

    > "A. Sinan Unur" <>Wrote at 26 Sep 2004
    > 16:53:17 GMT:
    >>
    >>Huh? Do you realize that in the example you give, it does not matter
    >>what slash you are using? In the cmd.exe shell, regardless of the
    >>slash, you need to enclose file paths that include space in double
    >>quotation marks. On the other hand,
    >>
    >>"c:/Program Files/Internet Explorer/iexplore.exe"
    >>
    >>works just fine (i.e. runs Internet Explorer).

    >
    > My question is "Windows" not "Dos", if you open a file from Windows
    > "Common Dialog Box" it must fail


    1. Please quote properly. I did not write that message in response to your
    original post but in response to
    news:

    2. cmd.exe is not DOS

    3. Windows deals with / just fine

    4. Why 'must'? Notepad on Win98 seems not to mind / if it is specified on
    the command line whereas it fails to grok / if specified in the
    File->Open dialog. OTOH, Start->Run or Word's File->Open has no problems.
    On XP, I have not been able create a situation where / leads to problems.
    Specific applications may have bugs. In that case, you should demand that
    the bug be fixed. (By the way, I remember pointing out to you that EditPlus
    is a supported product: <Xns954B80344CE38asu1cornelledu@132.236.56.8>. You
    haven't avoided registering it, have you?)

    Sinan.
     
    A. Sinan Unur, Sep 27, 2004
    #13
  14. Alont wrote:
    > "A. Sinan Unur" <>Wrote at 26 Sep 2004
    > 16:53:17 GMT:
    >
    >>Huh? Do you realize that in the example you give, it does not matter what
    >>slash you are using? In the cmd.exe shell, regardless of the slash, you
    >>need to enclose file paths that include space in double quotation marks.
    >>On the other hand,
    >>
    >>"c:/Program Files/Internet Explorer/iexplore.exe"
    >>
    >>works just fine (i.e. runs Internet Explorer).

    >
    >
    > My question is "Windows" not "Dos", if you open a file from Windows
    > "Common Dialog Box" it must fail


    That is a "feature" of the dialog box itself. The basic, nitty-gritty
    file-opening code of Windows and DOS has accepted either "/" or "\" for
    over twenty years, and if the dialog box weren't deliberately (and, in
    my view, incorrectly) rejecting "/", it would work just fine.

    --
    John W. Kennedy
    "Sweet, was Christ crucified to create this chat?"
    -- Charles Williams. "Judgement at Chelmsford"
     
    John W. Kennedy, Sep 27, 2004
    #14
  15. Alont

    Alont Guest

    "John W. Kennedy" <>Wrote at Mon, 27 Sep 2004
    03:32:12 GMT:
    >That is a "feature" of the dialog box itself. The basic, nitty-gritty
    >file-opening code of Windows and DOS has accepted either "/" or "\" for
    >over twenty years, and if the dialog box weren't deliberately (and, in
    >my view, incorrectly) rejecting "/", it would work just fine.
    >


    Oh, I see, it's a problem about Common Dialog Box.
    My fault, sorry
    --
    Your fault as a Government is My failure as a Citizen.
     
    Alont, Sep 27, 2004
    #15
  16. Alont

    Alont Guest

    "A. Sinan Unur" <>Wrote at 27 Sep 2004
    03:09:06 GMT:
    >1. Please quote properly. I did not write that message in response to your
    >original post but in response to
    >news:
    >
    >2. cmd.exe is not DOS
    >
    >3. Windows deals with / just fine
    >
    >4. Why 'must'? Notepad on Win98 seems not to mind / if it is specified on
    >the command line whereas it fails to grok / if specified in the
    >File->Open dialog. OTOH, Start->Run or Word's File->Open has no problems.
    >On XP, I have not been able create a situation where / leads to problems.
    >Specific applications may have bugs. In that case, you should demand that
    >the bug be fixed. (By the way, I remember pointing out to you that EditPlus
    >is a supported product: <Xns954B80344CE38asu1cornelledu@132.236.56.8>. You
    >haven't avoided registering it, have you?)
    >
    >Sinan.


    I'm sorry, You are right, I've tried Word, it really works with "/"
    path in it's Common Dialog Box.
    and My EditPlus copy as you said: I haven't register it, so? you want
    point that you are more moral than me or what you want say?
    this topic far from "Perl", I'm sorry start this topic, it's time to
    stop.
    --
    Your fault as a Government is My failure as a Citizen.
     
    Alont, Sep 27, 2004
    #16
  17. Alont

    Peter Scott Guest

    In article <Xns957084A3D6E83asu1cornelledu@132.236.56.8>,
    "A. Sinan Unur" <> writes:
    > (Peter Scott) wrote in news:tTA5d.114117$%S.21618
    >@pd7tw2no:
    >
    >> In article <41563101.225947687@130.133.1.4>,
    >> Alont <> writes:
    >>>there are possible to change the "/" to "\" in windows platform?

    >>
    >> use File::Spec; # Core module
    >> $file = File::Spec->canonpath($file);
    >>

    >
    >That is good advice. However,
    >
    >#! perl
    >
    >use strict;
    >use warnings;
    >
    >use File::Finder;
    >use File::Spec::Functions qw( catfile );
    >
    >my $dir = catfile 'c:', 'www', 'unur', 'htdocs';
    >my @html = File::Finder->type('f')->name('*.html')->in($dir);
    >
    >print "$_\n" for (@html);
    >
    >__END__
    >
    >This script will output:
    >
    >C:\www\unur\htdocs/index.html
    >C:\www\unur\htdocs/comp/anti-spam-howto.html
    >C:\www\unur\htdocs/comp/c-examples.html
    >C:\www\unur\htdocs/comp/index.html
    >
    >so, the OP would still be asking the same question.


    My intended message was that the poster do something like:

    $_ = File::Spec->canonpath($_) for @html;

    before the penultimate line of your example above.

    --
    Peter Scott
    http://www.perldebugged.com/
    *** NEW *** http://www.perlmedic.com/
     
    Peter Scott, Sep 27, 2004
    #17
  18. Alont

    Peter Scott Guest

    Peter Scott, Sep 27, 2004
    #18
  19. (Peter Scott) wrote in news:hNU5d.545240$gE.234083@pd7tw3no:

    > My intended message was that the poster do something like:
    >
    > $_ = File::Spec->canonpath($_) for @html;
    >
    > before the penultimate line of your example above.


    Oooops! Sorry, I misunderstood your post.

    --
    A. Sinan Unur
    d
    (remove '.invalid' and reverse each component for email address)
     
    A. Sinan Unur, Sep 27, 2004
    #19
  20. Alont

    Joe Smith Guest

    A. Sinan Unur wrote:

    > Alont <> wrote in news:41584b6e.232712937@130.133.1.4:
    >
    >
    >>"A. Sinan Unur" <>Wrote at 26 Sep 2004
    >>03:26:48 GMT:
    >>
    >>>Windows can deal with / just fine. In fact, I would recommend sticking
    >>>with / rather than \.

    >>
    >>notepad can't open
    >>D:/Inetpub/wwwroot/article/layout/2004/csslayout/onebox_absolute.html
    >>EditPlus also can't,the "common dialog" box can't deal with "/" path

    >
    > Are you sure? Notepad has no problem with such paths on my Win 98 or Win XP
    > systems.


    Notepad's browse-for-file dialog treats / different than cmd.exe does.

    This works: C:\>notepad c:\cygwin\home\jms\.cshrc
    This works: C:\>notepad c:/cygwin/home/jms/.cshrc

    It does not work to type Control-O to Notepad and then copy-and-paste
    c:/cygwin/home/jms/.cshrc into the File Name field of the Open dialog.
    It pops up an error: The above file name is invalid"

    -Joe
     
    Joe Smith, Sep 28, 2004
    #20
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. jcc
    Replies:
    15
    Views:
    4,707
    Nigel Wade
    May 12, 2006
  2. Coca
    Replies:
    15
    Views:
    645
    Alan Balmer
    Jan 14, 2004
  3. Maciej Sobczak
    Replies:
    9
    Views:
    553
    Roger Binns
    Apr 25, 2004
  4. Replies:
    1
    Views:
    436
    Andrew Thompson
    Jul 24, 2006
  5. sonald
    Replies:
    13
    Views:
    839
    sonald
    Sep 4, 2006
Loading...

Share This Page