473,799 Members | 2,772 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Checking folder before creating the new folder [PERL].

135 New Member
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 2602
miller
1,089 Recognized Expert Top Contributor
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 Recognized Expert Specialist
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
7212
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 created if they don't already exist, and if the drive happens to be one a folder cannot be created on (ie a cdrom drive) it would just be skipped without the code generating any errors. your help on this would be most appreciated. jenny
2
3524
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 archives data based upon information in a text file in each directory. The archive location is derived from that location and I need to make sure there are no illegal / special characters in the file name before creating it. Thanks
2
3392
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
6898
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 appreciate it; I've got this bit of code and I couldn't for the life of me tell you why it doesn't work, if anyone else can I'd appreciate it! Cheers
1
1916
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 files transferred. Can only move a certain amount of files per time period. -Folders have a priority. The files have to be moved based on the folder priority.
9
2036
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 working folder same as the place I copied the files from. I am able to check in / check out / edit / view correctly when I click the respective file from VSS. But is there no way that I can just start my Visual Studio, do any changes and then...
8
17585
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
1777
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 ssh("-i",$identity_file,"abc.abc.net","mkdir -p /opt/abc/mailboxes/mail/TS_&_ABC"); This creates a folder "TS_" but throws up an error sh: line 1: _ABC: command not found. We have already tried enclosing the folder name with single-quotes like ...
8
6381
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
9689
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9550
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10269
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
10032
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9085
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5469
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
4148
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3764
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2942
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.