CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
INDEX
Search Posts SEARCH
POSTS
Who's Online WHO'S
ONLINE
Log in LOG
IN

Home: Perl Programming Help: Beginner:
Setting directory and file permissions via ftp...

 



Tim
Deleted

Mar 8, 2000, 9:03 AM

Post #1 of 3 (863 views)
Setting directory and file permissions via ftp... Can't Post

Hi,

I want to write a cgi script that will open a directory and change the permissions to all the files it contains. I can get to work if I list each file name with the chmod command but I'm sure there's a way to do it without listing the individual directories.

For example, here's what I have now...

chdir("$db_script_path/templates");

chmod(0777,"add.html");
chmod(0777,"add_error.html");
chmod(0777,"add_success.html");

Any advise?

Thanks,

Tim


japhy
Enthusiast

Mar 8, 2000, 9:23 AM

Post #2 of 3 (863 views)
Re: Setting directory and file permissions via ftp... [In reply to] Can't Post

If you don't want to recurse down into directories that the directory contains, you can use:

<BLOCKQUOTE><font size="1" face="Arial,Helvetica,sans serif">code:</font><HR>


$path = "/path/to/dir";
$mode = 0777;
opendir DIR, $path or die "can't open $path: $!";
while (defined($file = readdir DIR)) {
chmod $mode, "$path/$file" or warn "can't chmod $mode $path/$file: $!";
}
closedir DIR;
</pre><HR></BLOCKQUOTE>

Or you can just use the glob() function (or the <...> operator):

<BLOCKQUOTE><font size="1" face="Arial,Helvetica,sans serif">code:</font><HR>


chmod $mode, glob("$path/*");
# or
chmod $mode, <$path/*>;
</pre><HR></BLOCKQUOTE>

[This message has been edited by japhy (edited 03-08-2000).]


Tim
Deleted

Mar 8, 2000, 9:32 AM

Post #3 of 3 (863 views)
Re: Setting directory and file permissions via ftp... [In reply to] Can't Post

COOL!

Thanks, I'll try it.

Tim

 
 


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives