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 IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Creating a directory with Perl

Status
Not open for further replies.

c4n

Programmer
Mar 12, 2002
110
SI
Hi!

What command must I use to create a directory with a Perl script?

I tried

#!usr/bin/perl
...
mkdir "dirname";
mkdir("dirname");
...

but allways get an error. I'm quite sure it isn't a file permission problem though.

Thanks!
 
'mkdir' is the correct function to use.

USAGE:
mkdir new_dir_name, MODE;

Where:
new_dir_name is obviously the name for the new dir
MODE is a string defining the permissions for the new dir.

EXAMPLE:
mkdir this_dir, 777;

Note that the MODE is modified from what you ask for by the current UMASK. This enforces a security layer that can be used by the system to prevent the creation of wide-open permissions on everything you create. If your current umask is 011, then the 777 will turn into 766 when the dir is created.

All that having been said(typed), I'd bet your problem is insufficient permissions to create the new dir. Two cases usually show up. (1) You can't create the dir - you don't have permissions OR (2) you can create the dir but it shows up with permissions other that the MODE you requested - blame umask. If you are doing this with CGI, then make sure the parent directory you are trying to write (create a sub-dir) in has sufficiently loose permissions to let the web daemon to create the new dir. 'hope this helps

If you are new to Tek-Tips, please use descriptive titles, check the FAQs, and beware the evil typo.
 
Hi!

I got it working - it was the lack of "MODE" that caused the problem.

Now I use mkdir("dirname",MODE); and it works fine.

Thanks for the help!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top