Hi all,
I need a help in perl script.The basic idea is,it must have command line arguments for the user flexibility.the files are in the format as shown below.
MainFolder
Directory
Sub_directory
files
Sub_directory
files
Directory
Sub_Directory
files
Sub_directory
files
Directory
Sub_Directory
files
Sub_directory
files
and so on....
I need to do some manipulation on the files depending on the commandline arguments.
1.If i just give the Folder name,it should go recursively till the end of all files in all the sub_directories .
2.If i give the directory name,it should process it and remaining directories in the folder.
2.If I give a sub_directory name,I should also mention the Directory name(mandatory) then it should process all the files in that subdirectory and keep continuing till it processes the entire directories.
I need more help in processing of the command line arguments.
i.e, how to declare and use them etc..
Thanks in advance..
9 2410 eWish 971
Recognized Expert Contributor
Would you please show us the code that you have tried? Thank You!
I need some advice on this piece also.
In this way I can read complete folder and its contents... - opendir(dir, $FOLDER) or die "Can't open $FOLDER directory: $!\n";
-
@directory = sort readdir(dir) or die "Unable to read current dir:$!\n";
-
closedir(dir);
what I need is if I give the directory name,it has to start from that directory and continue till end....and also for the subdirectories. ...
Plzz can someone guide me
eWish 971
Recognized Expert Contributor
I agree with Kevin. I was going to suggest the same module. I just wanted to see some effort first.
I need advice on how to have the conditions for command line arguments.
The code which I placed in my above post goes for the entire folder.
What I want to do is depending on the commandline it has to go either for entire folder or from the directory I pass or from the sub-directory of a directory I pass.
How to use these condns for same piece of coding....
KevinADC 4,059
Recognized Expert Specialist
I need advice on how to have the conditions for command line arguments.
The code which I placed in my above post goes for the entire folder.
What I want to do is depending on the commandline it has to go either for entire folder or from the directory I pass or from the sub-directory of a directory I pass.
How to use these condns for same piece of coding....
You have not posted any code. Did you read the File::Find documentation I posted a link to?
As shown below it starts for a specific folder and keeps on going... - chdir($FOLDER);
-
opendir(dir, $FOLDER) or die "Can't open $FOLDER directory: $!\n";
-
@directory = sort readdir(dir) or die "Unable to read current dir:$!\n";
-
closedir(dir);
-
-
foreach $directory (@directory)
-
{
-
....
-
....
-
opendir (dir,$directory) or die "Can't open the current directory: $!\n";
-
@sub_directory = sort readdir(dir) or die "Unable to read current dir:$!\n";
-
closedir(dir);
-
chdir($directory)
-
-
foreach $sub_directory (@sub_directory)
-
{
-
....
-
opendir(dir, $sub_directory) or die "Can't open the current directory: $!\n";
-
@filename = sort readdir(dir) or die "Unable to read current dir:$!\n";
-
closedir(dir);
-
chdir($sub_directory) or die "Unable to enter dir $sub_directory:$!\n";
-
...
-
....
-
foreach $filename (@filename)
-
{
-
...
-
...
-
chdir($filename) or die "unable..."
-
-
}
-
-
}
-
}
I might be wrong someway above,but its just a sample I typed in...
The thing where I need a suggestion is
1.If I start with the main folder,its fine and gonna work good.
2.If i start with a directory(also be mentioning the folder name in the command line),it has to start from that directory and has to keep going for that and also the remaining directories in that folder.How to set a condn for that,so that it can start from there and go recursively...
if($directory), I mean if I entered a value for directory...How to start the for loops and so on...
3.Its a condn more than the above as I need to start from a sub_directory of a directory and has to go recursively till the end of all directories in the folder.
(I will be passing the sub_directory,d irectory and the folder in the command line)
I need some help to implement this logic...
Thanks
eWish 971
Recognized Expert Contributor
The File::Find module that Kevin suggested will be so much easier.
As like mentioned above will work perfectly.
use File::Find traversing module.
it will definitely help u.
Sign in to post your reply or Sign up for a free account.
Similar topics |
by: Max M |
last post by:
I guess that the best approach is calling a shell tool with something
like os.popen(). But I cannot seem to find any free tools.
Winzip has a command line option, but for registered users only. That is
bothersome if I want to install the script on other machines.
The same for pkwares zip. At least I cannot seem to find a free version
of it.
gzip seems able to do the trick, but I need to install Cygwin, that's
|
by: Trinity |
last post by:
Hi,
I want to delete a particular file in all the sub-directories. I am
using the SHFileOperation() API. But it is not deleting the files
recursively. Any sample code is appreciated.
TIA
|
by: Derek |
last post by:
Hi,
I've built a rather large CGI that dumps a lot of data and a fairly
complex javascript app out to the client's browser. Granted this may
be poor style according to someone web design philosophy but that is
the way things need to work for now here. The problem I'm having is
that it appears that the browsers (IE, mozilla and netscape) are
sometimes getting confused about wether the javascript code is
running. By this I mean when I...
|
by: rbt |
last post by:
What is the most efficient way to recursively remove files and directories?
Currently, I'm using os.walk() to unlink any files present, then I call
os.walk() again with the topdown=False option and get rid of diretories
with rmdir. This works well, but it seems that there should be a more
efficient way. Here are my function definitions:
def remove_files(target_dir):
# This attempts to remove _all_ files from a directory.
# Use with...
|
by: Kamen TOMOV |
last post by:
Hi,
Is uploading recursively directories to a web server possible with
JavaScript?
I mean is it possible read a directory recursively and dynamically
construct <input type="file"> with value - the path to the
corresponding file and call submit with the script.
Thank you.
| |
by: Peter Thorne |
last post by:
I am a perl newbie who is trying to write a script to automate a
task.
I have a large collection of compressed archives (mostly .tar.gz,
tar.bz2, tar.Z, .tgz etc). This are stored in a number of directories
/ sub-directories).
I am looking for a script that will recursively extract a single file
from each of these archives e.g. the file INSTALL, for the extracted
file to be moved to a different location and renamed to the name of
|
by: weird0 |
last post by:
Hi! I need answers to these questions that were given to me in a job
test.
1. What is IDisposable in .NET?
2.What is the base class of all the controls in .NET?
3.What is the difference betweeen HAVING and WHERE ? Never used
HAVing clauuse or seen it.
4.What is pre-emptive multitasking?
5.What is object serialization?
6.What is the difference between web.config and machine.config? Never
|
by: ArchanaAshok |
last post by:
Hi All,
I have done a script to compare 2 similar directories containing equal number of files, and to compare the content of those files in the directories.
But there is some problem in the recursion. Can anybody findout where I am going wrong?
Here is the code.
#!/usr/bin/perl
|
by: misceverything |
last post by:
I am writing a script that will backup specified folders from one hard
drive to another (for example, backup source "C:\DATA", destination "D:
\Backup"), and was thinking of using shutil. What I would like to do
is recursively backup the specified directories (which copytree will
do), but be able to specify exclusion directories (which copytree does
not appear to allow you to do). My initial thoughts were I'll
probably have to use...
|
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...
|
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it.
Here is my compilation command:
g++-12 -std=c++20 -Wnarrowing bit_field.cpp
Here is the code in...
| |
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...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
|
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...
|
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...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
|
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
| |
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...
| |