Gossamer Forum
Home : General : Perl Programming :

How to use Perl/shell script command to get directory property?

Quote Reply
How to use Perl/shell script command to get directory property?
Hi, I a piece of codes which is tring to read a directory on a Linux platform as following. The purpose is to check whether a particular directory is writable:

#!/usr/bin/perl
use File::Copy;
$ftp_path = "/image_1";
$result = "";
$result = system("ls -dl $ftp_path |cut -c1-10");
if($result eq 'drwxrwxrwx'){
print ("$ftp_path is writable\n");
}
else{
print ("$ftp_path is not writable\n");
}

However, this code will print out the mode of the directory, for example "drwxrwxrwx", on the screen without sending this string to the variable.

Thanks for taking your precious time to answer my question!

Unsure
Green Apple
[/email]
Quote Reply
Re: [Green Apple] How to use Perl/shell script command to get directory property? In reply to
You are using system() - you should use qx// to retrieve the output to a variable.

However, a better way would be:

Code:
if (-w $ftp_path) {
# writable
}

Last edited by:

Paul: Jul 9, 2003, 3:16 AM
Quote Reply
Re: [Paul] How to use Perl/shell script command to get directory property? In reply to
Hi, Paul:

Thanks for your reply. Sorry that I couldn't reply in time.

I have tried the method of "-w filepath" before, however it seems that this method is only working for file rather than directory.

Thanks
Green Apple