Beefy Boxes and Bandwidth Generously Provided by pair Networks
Just another Perl shrine
 
PerlMonks  

How do I create subfolders?

by tamaguchi (Pilgrim)
on Apr 02, 2006 at 08:09 UTC ( #540715=perlquestion: print w/ replies, xml ) Need Help??
tamaguchi has asked for the wisdom of the Perl Monks concerning the following question:

When running a program I would like to store the various outfile sorted in subfoldes named according to which files are in the subfolder. So my question is basicly: How do I create subfolders and how do I print to subfolders? Thank you for any help.

2006-04-02 Retitled by planetscape, as per Monastery guidelines: one-word (or module-only) titles pose a hazard to site navigation
Original title: 'Subfolders'

Comment on How do I create subfolders?
Re: How do I create subfolders?
by Corion (Pope) on Apr 02, 2006 at 08:13 UTC

    The mkdir function creates directories (which I assume are what you mean by "subfolders"). The open function can open files even if you prepend a path to them. If you want to create multiple directories in one go, have a look at File::Path.

    use strict; use warnings; my $outdir = "output"; if (! -d $outdir) { warn "Creating '$outdir'"; mkdir $outdir or die "Couldn't create '$outdir': $!"; }; my $outname = "$outdir/test.txt"; open my $outfile, ">", $outname or die "Couldn't create '$outname' : $!"; print $outfile, "Hello World\n";
      If you want to create multiple directories in one go, have a look at File::Path.
      Corion is not saying it with so many words, but he is talking about the function mkpath(), in File::Path, which comes with Perl.
Re: How do I create subfolders?
by murugu (Curate) on Apr 02, 2006 at 14:56 UTC
Re: How do I create subfolders?
by kgraff (Monk) on Apr 03, 2006 at 00:03 UTC

    To answer the second part of your question, how to navigate the directories you create, the chdir command may be helpful to change your working directory.

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://540715]
Approved by Corion
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others contemplating the Monastery: (12)
As of 2014-12-26 07:20 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    Is guessing a good strategy for surviving in the IT business?





    Results (167 votes), past polls