473,385 Members | 1,732 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

Checking folder before creating the new folder [PERL].

135 100+
Checking the folder before actually creating the new folder [PERL].

Can someone guide me in what 'Checks' do I need to do before I create a new folder? I know that one of the checks will be to see if the file already exists or not. What other checks could I do?

See coding for Creating new folder

Expand|Select|Wrap|Line Numbers
  1. use CGI;
  2. use strict;
  3. use warnings;
  4.  
  5. my $q = new CGI;
  6. print $q->header(), $q->start_html();
  7. my $path = 'path/to/some/folder/';
  8. $path =~ s|\|/|g;
  9. my $dir = $q->param('folder');
  10. #vaildate the value of $dir to make sure the form has not been altered
  11. $path.=$dir;
  12. mkdir($path) or die "Unable to create folder: $!";
  13. mkdir("$path/hai") or die "Unable to create folder: $!";
  14.  
May 29 '07 #1
2 2575
miller
1,089 Expert 1GB
Hello Patel,

The quickest and best advice that I can give you is to simply not allow users to specify folders to be created. It's true that it can secured pretty well, but it's generally bad practice to let them manipulate the file system in so direct a way.

Instead, use a database. They can specify any folder name that they want, and you can create the navigation routines yourself.

Nevertheless, if you must do this, then use the file test functions.

perldoc -X

And make sure that they do not include any spaces or double dots in their folder names.

Expand|Select|Wrap|Line Numbers
  1. if ($filename =~ /\s|\.\./) {
  2.     print "Invalid filename\n";
  3. }
  4.  
- Miller
May 29 '07 #2
KevinADC
4,059 Expert 2GB
I agree with Miller. Allowing this much control by the user is something you have to take very seriously. You should be using taint mode and validating and filtering the user input before allowing the user input to be used as a folder name. Allow only a limited class of characters to be used for folder names: a-z A-Z 0-9 _- and a minimum and maximum number of characters. 3 is a good minimum and 20 ro 30 is a good maximum. There might be other concerns too.
May 29 '07 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

13
by: jenny | last post by:
Hi, I am trying to find a VB way that would create a folder on all existing drives - the folder name would be the same on each drive. ie c:\backup, d:\backup, etc. But the folders would only be...
2
by: Rich Bogle | last post by:
Does anyone have a good module or clean method for making sure file names do not have special charactes / illegal characters in them before attempting to save the file. I have a perl script that...
2
by: Brian Henry | last post by:
How with out creating a COM object, do you check in .NET to see if a folder exists? I found the check for a file but i need to check for a folder, and there does not seem to be on in the path class
2
by: Argonath | last post by:
Hi, I'm afraid this will no doubt horrendously basic as I'm a complete newbie to VB and have dived in without learning to do much... Start in the deep end and all. So if anyone could help, I'd...
1
by: halcyon943 | last post by:
have 4 folders that I watch and need to move files from to another location. Three constraints: -Finish time. Make sure the program stops transferring files at a specific time -Number of...
9
by: Zeba | last post by:
Hi , I'm having problems using Visual Source Safe with my Visual Studio 2005. I have correctly connected to the VSS database with userid and set up a project in VSS comprising mySite. I set the...
8
by: patelxxx | last post by:
Can someone guide me how to write a code to open a 'new folders' in PERL from a drop down menu.
4
by: mail2sanand | last post by:
Hi All, I am trying to create a folder with "&" in itz name (Ex: TS_&_ABC) with the help of perl's ssh command in another server. The exact command I am triggering in the code is ...
8
viktorijakup
by: viktorijakup | last post by:
Hi !!! This script must open folder, and I must view empty opened folder...!!! I work in "Far manager". Now this script only create folder... @rem = '--*-Perl-*--
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.