Beefy Boxes and Bandwidth Generously Provided by pair Networks
good chemistry is complicated,
and a little bit messy -LW
 
PerlMonks  

Making Directories

by Angel (Friar)
on May 28, 2003 at 13:42 UTC ( [id://261296]=perlquestion: print w/replies, xml ) Need Help??

Angel has asked for the wisdom of the Perl Monks concerning the following question:

I have to create a directory structure of HTML redirects. I am sure there are many much more efficent ways of doing this but we do not have control of the server and this is what they want. Each redirect points to a script on another site.

This said the resulting directory structure will be a directory with a name and the index.html file that points to the CGI Script. The problem is when I try to create the directories and then chmod them the file permissions are not set; and I get this error :

No such file or directory

I am trying for now to set the directory to ./ since it makes for easier testing but eventually it will go to another directory elsewhere. Thus I made it so that it takes in "directory path" of some sort and the name of the Directory. So what you should get is "path_from_root/directory_name" in my default case I get ./directory name. It makes the directory fine, it writes the Redirect fine but the permissions that are set will not let me read or write to the directory ( and I am chmodding to 755 ). Here is the code any ideas why it is not chmodding correctly?<\p>

sub make_alias( $ ) { my $self = shift; my $name = $_[0]; my $id = $_[1]; my $alias_data = "alias.db"; my $alias_directory = "./"; print "$name,$id \n"; #create directory for redirect to go into my $path = $alias_directory . $name; my $mode = "0755"; print "path = $path \n"; mkdir $path, $mode; print "x = $! , $path \n"; chmod( $mode, $path ); #add redirect file my $redirect = new Redirect(); $redirect->redirect_filename( $path . "\/index.html" ); $redirect->redirect_link( "http://www.nowhere.com/cgi/school_ +connection.cgi?id=$_[1]" ); $redirect->displayed_link( "" ); $redirect->redirect_template( "redirect_template.html" ); $redirect->redirect_delay( "0" ); $redirect->create_redirect; $redirect->save_redirect or die $!; print "After redirect saved \n"; #add to database my $db = new Database(); $db->file($alias_data); $db->delimiter("|"); $db->execute( "insert", "Name", $name, "ID", $id ); return 1; }

Replies are listed 'Best First'.
Re: Making Directories
by broquaint (Abbot) on May 28, 2003 at 13:51 UTC
    You want to set $mode to the octal 0755 which is quite different from the string "0755" e.g
    ## incorrect shell> perl -e 'mkdir "foo", "0755"' && ls -ld foo d-wxr----t 2 perl monks 1024 May 28 14:50 foo shell> rmdir foo ## correct shell> perl -e 'mkdir "foo", 0755' && ls -ld foo drwxr-xr-x 2 perl monks 1024 May 28 14:50 foo

    HTH

    _________
    broquaint

Re: Making Directories
by fglock (Vicar) on May 28, 2003 at 13:49 UTC

    Don't use a string there - it changes the meaning of 0755:

    H:\cvs>perl -e " print 0 + '0755', ' ', 0755 " 755 493
Re: Making Directories
by PodMaster (Abbot) on May 28, 2003 at 18:58 UTC
    I'd like to point out perldoc -f oct
    C:\>perl -e"die oct q,0755," 493 at -e line 1.


    MJD says you can't just make shit up and expect the computer to know what you mean, retardo!
    I run a Win32 PPM repository for perl 5.6x+5.8x. I take requests.
    ** The Third rule of perl club is a statement of fact: pod is sexy.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others sharing their wisdom with the Monastery: (3)
As of 2024-04-20 15:16 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found