1
Suppose I have a directory structure organized as follows on my PC:
Diretorio 01
Arquivo 01.jpg
Arquivo 02.jpg
Arquivo 03.jpg
Arquivo 04.jpg
Diretorio 02
Arquivo 01.jpg
Arquivo 02.jpg
Diretorio 03
Arquivo 01.jpg
Arquivo 02.jpg
Arquivo 03.jpg
...
Diretorio n
Arquivo 01.jpg
Arquivo 02.jpg
Arquivo 03.jpg
Arquivo 04.jpg
Sane n
different directories. Within each of them I have a variable number of files .jpg. I would like to copy these files. jpg to another folder on my computer, placing them all in the same location and renaming them as follows in the process:
Diretorio 01 Arquivo 01.jpg
Diretorio 01 Arquivo 02.jpg
Diretorio 01 Arquivo 03.jpg
Diretorio 01 Arquivo 04.jpg
Diretorio 02 Arquivo 01.jpg
Diretorio 02 Arquivo 02.jpg
Diretorio 03 Arquivo 01.jpg
Diretorio 03 Arquivo 02.jpg
Diretorio 03 Arquivo 03.jpg
...
Diretorio n Arquivo 01.jpg
Diretorio n Arquivo 02.jpg
Diretorio n Arquivo 03.jpg
Diretorio n Arquivo 04.jpg
That is, each resulting file will be named according to the source directory and the original file name. Note that file names are repeated within source directories.
Originally my files have spaces in the names, but this space does not need to be present in the final result. I mean, names can be something on the line Diretorio_01_Arquivo_01.jpg
if this makes the algorithm easier to implement.
Just one question, the name of the directories can be random, only followed by the number? It can be something like
Foo 01
,Bar 100
, etc.?– Guilherme Nascimento
Actually directory names are random, but without numbers. Directories have people names, like
Joao da Silva
,Maria Oliveira
,Jose de Souza
and so on.– Marcus Nunes
Then just concatenate the name of the directory with that of the photo when moving the file to the destination folder, then a simple recursive function resolves, I will try to make a response :)
– Guilherme Nascimento
Dear Marcus, I reviewed the code of the answer, had some problems, but now I believe that it is working well, for trying and let me know any fault you find.
– Guilherme Nascimento