script to move and rename sub directories !
Hi
I need to make some changes to a series of directories and sub directories and I need help ! I have a series of directories : "folder a", "folder b", "folder c", .... and in these directories there are sub directories "folder 1", "folder 2" ,.... I need to rename "folder 1" in "folder a" to "folder a -folder 1" and move it to main directory. so there wont be any sub directories . the directory tree is : Code:
main directory Code:
main directoy |
first, fix the file names so they don't have spaces in them---Windows somehow tolerates this, but in a real OS like Unix or Linux, spaces in file names = trouble.
Start by defining the individual commands---eg, if you are in "folder_a", you could issue: Code:
mv folder_1 ../folder_a-folder_1 Code:
mv folder_1 ../$(pwd)-folder_1 |
Thanks for your help !
I know how to manually use mv . the problem is that in the main folder there is over 500 folders where in each folder is some sub-folders with deferent names ! and do that manually takes lots of time . |
As I said, simply put the commands into a loop---for example, in a directory, you could do:
Code:
for filename in *; do |
PS;
If you know that directories and sub-directories contain only files (or only directories), then looping thru them is easier. Otherwise, the code will need to test each item to see what it is. |
thanks will test when I get home !
|
this script do the job for me
thanks to Paul Pedant Code:
AWK=''' For testing, just leave off the bash part and check the commands visually to ensure they do what you want. |
All times are GMT -5. The time now is 03:05 AM. |