prad_intel has asked for the wisdom of the Perl Monks concerning the following question:

This node falls below the community's minimum standard of quality and will not be displayed.
  • Comment on The space between file names and folder names

Replies are listed 'Best First'.
Re: The space between file names and folder names
by gopalr (Priest) on Feb 25, 2005 at 05:47 UTC

    Hi Prad,

    Use File::Basename module to get the path andf file name.

    use File::Basename; $pathandfile='C:\temp\foo foo\foo foo.txt'; ($filename, $path)=fileparse($pathandfile); print "$path = $filename";

    Illustration the above code:

    fileparse - split a pathname into pieces filename - extract just the filename from a path path - extract just the directory from a path
Re: The space between file names and folder names
by blazar (Canon) on Feb 25, 2005 at 09:01 UTC
    I would like to know how to read the file names or folder names if there are spaces between them.

    Example->

    Folder name = foo goo

    IMHO it would have been sensible to give examples in terms of either single quotes or double quotes delimited strings...

    Said this, I think I can understand that you have some paths comprising directory and file names having spaces in them. So far, so fine! Then one should understand what you mean with "I would like to know how to read"...

    open shouldn't have any problem with such filenames, e.g.:

    open my $fh, '<', 'filename with spaces' or die $!;

    All in all experience shows that speaking Perl is more effective, communication-wise than speaking (a fuzzy) English.

    My code ( sorry cannot publish the code ) reads the file names and folder names when there is no space between them precisely.
    Again, it's a common practice to disambiguate what one really wants by means of minimal but complete snippets of code.
Re: The space between file names and folder names
by m-rau (Scribe) on Feb 25, 2005 at 09:11 UTC
    I am confused and therefore I simply tried it.
    #!/perl open( FILE, ">", "this is a test . txt" ); print FILE "yeah"; close( FILE ); open( FILE, "<", "this is a test . txt" ); while (my $line = <FILE>) { print $line; } close( FILE );
    Works out fine and prints the expected yeah. I am working on win32 with Activeperl. What are you working on? And I even went further and made a
    #!/perl mkdir( "another test" ); open( FILE, ">", "another test/this is a test . txt" ); print FILE "yes, yeah"; close( FILE ); open( FILE, "<", "another test/this is a test . txt" ); while (my $line = <FILE>) { print $line; } close( FILE );
    giving me the yes, yeah. What is your exact problem?