Beefy Boxes and Bandwidth Generously Provided by pair Networks
more useful options

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'

Replies are listed 'Best First'.
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?

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://540715]
Approved by Corion
[Cosmic37]: ta erix - this szabo geezer is pretty cool methinks and he writes about undef but I cannot see instructions for redefining the record separator after having undefined it
[Corion]: $/ = "wahtever";
[Corion]: (it's a magic variable)
[karlgoethebier]: BarApp: whoami
[Cosmic37]: ok fankyou - I was wondering about that but thought there might be a redefine command or something; peachy
[Lotus1]: Cosmic37 if you undef $/ in a local context to a block it won't affect the global version after the block finishes
[Lotus1]: or you can just do local $/ in a block
[erix]: cool

How do I use this? | Other CB clients
Other Users?
Others lurking in the Monastery: (7)
As of 2017-06-29 16:50 GMT
Find Nodes?
    Voting Booth?
    How many monitors do you use while coding?

    Results (673 votes). Check out past polls.