Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Shaun E on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Add files to a new directory in Perl?

Status
Not open for further replies.

StormMedic85

Programmer
Sep 7, 2007
20
US
I'm able to get the program to create the directory, but I can't get it to stick the files in it.

I have something like...

mkdir "dirname";
opendir (dir, dirname);
open (file, >'/dirname/filename.txt');
print file "testing 123";

That's off the top of my head so there may be a syntax error. Perl will create the directory, but all the files are still being written to the main directory from which the program is being ran.

Any suggestions?

thanks!
 
Add some error detection


$dirname = 'c:/test';
mkdir "$dirname" || die "can't mkdir $dirname\n";
open (file, >"$dirname/filename.txt") || die "can't open file $dirname/filename.txt";
print file "testing 123";
close file;



~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
[noevil]
Travis - Those who say it cannot be done are usually interrupted by someone else doing it; Give the wrong symptoms, get the wrong solutions;
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top