Linux - ServerThis forum is for the discussion of Linux Software used in a server related context.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
I want a perl script which can create folders structure recurssively and push some content in to the folders, i want to create some 10000 to 20000 folders using the script at one shot. Can any one help me in this regard.
Thanks...
Some info is missing:
the required structure of your directory tree
where does the content to be pushed come from
Hi,
Please find the attached JPEG file for the folders structure,i need to write a script which can create the structure in the attachement. Content should be pushed recursively to all the folders from some other location in the same system where we will execute the script.
Hmmmm, looks bit like homework from the picture.
However, as konsolebox hints, there doesn't seem to be a pattern there...
If that's the case, I'd prob just create a file with csv recs for each complete set of paths, then use Perl to read the csv file and create dirs by walking down each csv rec.
Is there a relation between the shown directory structure and content (structure). I mean, how do you know what to push where? You must have some idea and you should tell us (e.g. what the content directory looks like).
Please provide complete information.
As it stands now, you can follow chrism01's solution but you will have to enter 10000 or 20000 records in a csv file. It more or less defeats the onject of a script.
PS If you tried anything yourself, please provide the details.
Last edited by Wim Sturkenboom; 08-11-2009 at 02:49 AM.
Reason: Added PS
Is there a relation between the shown directory structure and content (structure). I mean, how do you know what to push where? You must have some idea and you should tell us (e.g. what the content directory looks like).
Please provide complete information.
As it stands now, you can follow chrism01's solution but you will have to enter 10000 or 20000 records in a csv file. It more or less defeats the onject of a script.
PS If you tried anything yourself, please provide the details.
Hi Wim,
My requirement is some thing like this,
I want a script which can help me in creating 10000 folders (structure shown in JPEG). I want to execute the script in below way,
script <No.of folders> <file to insert> <file No>
here $1 is the number of folders i want ot create, file to insert will be the file i would like to insert and it has to go in to each folder and file no is the number which i want to assign for the file.
I am looking for a perl script for this as i want to run this in both unix and windows.Is it possible to create such script??
The only difficulty I see is to determine what the last used directory is so one can continue from there when you run the next time.
Next you want to copy one specific file (the second argument) into each created directory. That is certainly possible.
Last you have fileno (the last argument) and I'm not quite sure what must happen with that? Does the copied file have to be renamed to that number (e.g. file3344)?
1)
Is that indeed what you need?
2)
What makes me curious is why you want to do something like that (what is the use). Can you explain that?
3)
I'm not a perl coder, so can't help with perl code.
The only difficulty I see is to determine what the last used directory is so one can continue from there when you run the next time.
Next you want to copy one specific file (the second argument) into each created directory. That is certainly possible.
Last you have fileno (the last argument) and I'm not quite sure what must happen with that? Does the copied file have to be renamed to that number (e.g. file3344)?
1)
Is that indeed what you need?
2)
What makes me curious is why you want to do something like that (what is the use). Can you explain that?
3)
I'm not a perl coder, so can't help with perl code.
Hi Wim,
The last argument file number is used to number the file across all the folders in ot which it is pushed, if enter 1 as a number it should cop the file with that number in all the folders.
Could you please pass me the script if you have any for such purpose. I will try to modify it as per my requirement and see if it works or not.
The last argument file number is used to number the file across all the folders in ot which it is pushed, if enter 1 as a number it should cop the file with that number in all the folders.
What is the difference between file_to_insert and file_no ?
Anyway
Maybe the below TCL script (as said, I'm not a perl coder) can get you on the way. Please note that it does not provide any error checking, validation or whatever. It has one extra command line argument indicating the number of the first directory to create.
Code:
#! /usr/bin/tcl
# extract the arguments from the command line
set no_of_dirs [lindex $argv 0]
set file [lindex $argv 1]
set file_no [lindex $argv 2]
set start_dir [lindex $argv 3]
# create directory structure
set path ""
for {set cnt $start_dir} {$cnt < [expr $no_of_dirs + $start_dir]} {incr cnt} {
append path "dir$cnt/"
}
file mkdir $path
# copy file to each folder; append file_no
unset path
for {set cnt $start_dir} {$cnt < [expr $no_of_dirs + $start_dir]} {incr cnt} {
append path "dir$cnt/"
set copy [format %s%s.%s $path $file $file_no]
file copy $file $copy
}
I've wrote a script which will create 10000 folders, below is the code
for fld in {1..10000};
do
mkdir Folder$fld
done
this creates the folders, but now i want to copy a file from some location to all these 10000 folders created. can any one help me with the code ...???
I've wrote a script which will create 10000 folders, below is the code
for fld in {1..10000};
do
mkdir Folder$fld
done
this creates the folders, but now i want to copy a file from some location to all these 10000 folders created. can any one help me with the code ...???
Hi,
I've modified my script little more and wrote it as below,
#!/bin/bash
if [[ $1 == "Folder" ]];
then
for i in {1..10};
do
mkdir $1$i
done
else
if [[ ! $# == 1 ]];
then
echo "Pass the commandline argument"
fi
fi
Now i want to include some code in the above line which would help me in copying a file to all the directories created which i will specify on the command line in place of shell 2nd argument.Also how do we write a code which will take input from command line.
Please find the attached JPEG file for the folders structure,i need to write a script which can create the structure in the attachement. Content should be pushed recursively to all the folders from some other location in the same system where we will execute the script.
Let me know if you need any more info.
Thanks
Hi,
I've modified my script little more and wrote it as below,
#!/bin/bash
if [[ $1 == "Folder" ]];
then
for i in {1..10};
do
mkdir $1$i
done
else
if [[ ! $# == 1 ]];
then
echo "Pass the commandline argument"
fi
fi
Now i want to include some code in the above line which would help me in copying a file to all the directories created which i will specify on the command line in place of shell 2nd argument.Also how do we write a code which will take input from command line.
That's sort of difficult. Do you know the pattern of how the folders are created?
Hi,
I've modified my script little more and wrote it as below,
#!/bin/bash
if [[ $1 == "Folder" ]];
then
for i in {1..10};
do
mkdir $1$i
done
else
if [[ ! $# == 1 ]];
then
echo "Pass the commandline argument"
fi
fi
Now i want to include some code in the above line which would help me in copying a file to all the directories created which i will specify on the command line in place of shell 2nd argument.Also how do we write a code which will take input from command line.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.