Subfolders
tamaguchi
created: 2006-04-02 04:09:13
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.
Re: Subfolders
created: 2006-04-02 04:13:57

The [doc://mkdir] function creates directories (which I assume are what you mean by "subfolders"). The [doc://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 [cpan://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";
Re^2: How do I create subfolders?
created: 2006-04-02 06:47:32
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?
created: 2006-04-02 10:56:40
Hi tamaguchi,

Have a look at File:Path

Regards,
Murugesan Kandasamy
use perl for(;;);

Re: How do I create subfolders?
created: 2006-04-02 20:03:29

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.

perlmonks.org content © perlmonks.org and bart, Corion, kgraff, murugu, tamaguchi

prlmnks.org © 2006 edmund von der burg (eccles & toad)

v 0.03