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

A

Alont

#!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.
 
J

Jürgen Exner

Alont said:
#!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
 
A

Alont

Jürgen Exner said:
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.
 
A

Alont

A. Sinan Unur said:
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
 
T

Tad McClellan

Alont said:
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
 
P

Peter Scott

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);
 
T

Tad McClellan

W. Citoan said:
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*.
 
A

A. Sinan Unur

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

A. Sinan Unur

(e-mail address removed) (Peter Scott) wrote in @pd7tw2no:
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

A. Sinan Unur

Alont said:
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

Alont

A. Sinan Unur said:
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
 
A

A. Sinan Unur

Alont said:
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

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: <[email protected]>. You
haven't avoided registering it, have you?)

Sinan.
 
J

John W. Kennedy

Alont said:
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.
 
A

Alont

John W. Kennedy said:
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
 
A

Alont

A. Sinan Unur said:
1. Please quote properly. I did not write that message in response to your
original post but in response to

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: <[email protected]>. 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.
 
P

Peter Scott

(e-mail address removed) (Peter Scott) wrote in @pd7tw2no:


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.
 
A

A. Sinan Unur

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.
 
J

Joe Smith

A. Sinan Unur said:
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
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,579
Members
45,053
Latest member
BrodieSola

Latest Threads

Top