Recentemente ho dovuto affrontare questo problema, e molti file che ho voluto spostarsi dalla gerarchia a una singola cartella aveva lo stesso nome di un l'altro, e volevo appiattire ancora la gerarchia senza di loro a essere sovrascritto Quello che ho fatto è stato scrivere uno script che sposta il file, ma rinomina con il vecchio percorso della gerarchia in nome ad esempio: file di origine:
C: \ files \ somefiles \ file.txt
C
: \ files \ otherfiles \ file.txt
destinazione è C: \ newdir \ file vengono creati come
C: \ newdir \ somefiles-file.txt
C: \ newdir \ otherfiles-file.txt
Ecco il codice, file batch 1 passa attraverso i file, file batch 2 rinomina e li (sposta potrebbe anche copiare, invece, se si desidera mantenere la fonte:
@echo off
for /r %%f in (*.*pr) do @renameandmovefilespart2.bat "%%f" "%%~ff" "%%~xf"
renameandmovefilespart2.bat
@echo off
Setlocal EnableDelayedExpansion
rem set the whole file path
set origWhole=%1
set origPathOnly=%2
set extension=%3
rem here you can set where the directory to hold the flattened hierarchy is
set destDir=c:\destinationDir\
rem set the directory to do a string replace
rem make this the starting directory, that you dont want in the newly renamed files
set startingDir=C:\starting\directory\
set nothing=
set slash=\
rem here you can set what the character to represent the directory indicator \ in the new files
set reaplcementDirectoryCharacter=--
set quote="
rem cut out the starting part of the directory
call set newname=%%origWhole:!startingDir!=!nothing!%%
rem replace slashes with new character
call set newname=%%newname:!slash!=!reaplcementDirectoryCharacter!%%
rem remove quotes
call set newname=%%newname:!quote!=!nothing!%%
rem @echo shortened: %newname%
rem @echo source path: %origPathOnly% newPath: %startingDir%
rem @echo extension: %extension%
rem rename the files
ren %origWhole% %newname%
rem prepare to move the file, clean up the source path
call set origPathOnly=%%origPathOnly:!quote!=!nothing!%%
move "%origPathOnly%%newname%" "%destDir%"
possibile duplicato di [Come copiare i file dall'albero delle cartelle lasciando cadere tutte le cartelle con Robocopy?] (Http://stackoverflow.com/questions/1502170/how-to-copy-files-from-folder-tree-dropping -all-the-folders-with-robocopy) –