Can someone guide me how to write a code to open a 'new folders' in PERL from a drop down menu.
Creating new folder in PERL
Collapse
X
-
The PERL code:
[CODE=perl]
use Cwd;
$path = getcwd();
$path =~ s/\\/\//sg;
print "Enter the directory name\n";
$dir = <STDIN>;
mkdir($dir);
$new = $path."\/".$dir;
opendir(DIR, $new) || die ("cannot open the path");
mkdir("$new/hai");
[/CODE]
I'm trying to create a new folder in a 'Drop Down Menu', would I have to use 'JavaScript' to do this too?Comment
-
Hi patelxxx,
The code you posted does create a directory ("folder") based on the user's input and then creates another folder inside it called "hai". Is that not what you wanted it to do?
I should point out one, presumably unintended, effect of your current code: if someone runs this code and answers "foo" for the name of the directory to be created, your code as written includes the newline from <STDIN> in the variable $dir. Assuming you don't want the new directory to be called "foo\n" (displayed on my system and probably many others as "foo?") you should write:
[code=perl]$dir = <STDIN>;
chomp $dir;
mkdir($dir);[/code]
where chomp removes the newline from the end of $dir.
Otherwise, what is your question?
You say you're "trying to create a new folder in a 'Drop Down Menu'," What do you mean by that. If you're trying to create a web page that includes a drop-down menu, then it doesn't make sense to create directories in your local filesystem? If you are trying to include a function in a drop-down menu, then something like your current code works for that, but how you include it in what kind of menu is quite unclear. Why are you asking about JavaScript? JavaScript is used within a web page to control web browser activities and is not really supposed to allow your browser to modify your local filesystem. (That would be a terribly bad security hole.)
Overall, I get the feeling that you are trying to do something very different from what your posts actually say you are trying to do. This may be a language problem.
PaulComment
-
I have a "Dropdown Menu" on a website (not live yet) where users can select their folders to upload files on to, I would like an option for "New Folder" (i.e. add/creat a new folder) and once this option is selected a "new" folder is created. It's this part I assume is done in JavaScript.
The actual website has actual been written in PERL?Comment
-
Maybe this will help get you started:
I wouldn't use CWD and getcwd() unless you really know what you are doing. Instead hard code the value of the start directory like I did above. The CGI module is for parsing form data which is what I think you want to do, no javascript need be involved:Code:use CGI; use strict; use warnings; my $q = new CGI; print $q->header(),$q->start_html(); my $path = 'path/to/some/folder/'; $path =~ s|\|/|g; my $dir = $q->param('folder'); #vaildate the value of $dir to make sure the form has not been altered $path.=$dir; mkdir($path) or die "Unable to create folder: $!"; mkdir("$path/hai") or die "Unable to create folder: $!";
Comment
-
Comment
Comment