Hmmm this question on stackoverflow.com would be reported, since it is not a doubt about a bug or something, you are simply asking someone to solve a problem for you. However, as said here , this site is not the stackoverflow.com. So I did a python script to help you since I was not even sleepy.
create the file copia.py with the following code:
import os
import sys
origem = sys.argv[1]
destino = sys.argv[2]
if not os.path.exists(destino):
os.makedirs(destino)
for raiz, subDiretorios, arquivos in os.walk(origem):
for arquivo in arquivos:
arqCaminho = os.path.join(raiz, arquivo)
novoArqNome = "%s/%s" % (destino, arqCaminho.replace('/', '_'))
os.rename(arqCaminho, novoArqNome)
I have created the following structure to test in dirA:
$ tree dirA/
dirA/
├── arq1.foo
├── subDir1
│ ├── arq1.foo
│ ├── arq2.foo
│ ├── arq3.foo
│ ├── arq4.foo
│ └── subSubDir1
│ ├── arq1.foo
│ └── arq2.foo
├── subDir2
│ └── arq1.foo
└── subDir3
├── arq1.foo
├── arq2.foo
└── arq3.foo
You run the script as follows:
$python copia.py dirA/ destino
and you will get the following result:
$ tree destino/
destino/
├── dirA_arq1.foo
├── dirA_subDir1_arq1.foo
├── dirA_subDir1_arq2.foo
├── dirA_subDir1_arq3.foo
├── dirA_subDir1_arq4.foo
├── dirA_subDir1_subSubDir1_arq1.foo
├── dirA_subDir1_subSubDir1_arq2.foo
├── dirA_subDir2_arq1.foo
├── dirA_subDir3_arq1.foo
├── dirA_subDir3_arq2.foo
└── dirA_subDir3_arq3.foo
Note that I renamed the file with the path + file name and replaced the /
with _
so that you can keep the files in order by name as if they were in the folder. note how in the tree
commands the files keep the same order even though they are no longer hierarchized by folders.