Script to create folders recurssively
Hi,
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 |
Quote:
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 |
Quote:
|
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. |
Quote:
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?? Please help me here. |
Hi Tekken,
it's still not quite clear to me how you visualize that it works. You pass no of folders to a script. Will that create one branch with subbranches like below where the number is 4? Code:
root Code:
root 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. |
Quote:
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. |
Quote:
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 |
Hi,
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 ...??? |
That does not create the same directory structure as you gave in the jpeg.
|
Quote:
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. ex: script <foldername> <file> Please help me here. Thanks, Tekken. |
Quote:
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. ex: script <foldername> <file> Please help me here. Thanks, Tekken. |
Quote:
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. ex: script <foldername> <file> Please help me here. Thanks, Tekken. |
All times are GMT -5. The time now is 08:25 PM. |