13

これが私が作ったコードです:)

@echo off
set source="R:\Contracts\"
set destination="R:\Contracts\Sites\"
ROBOCOPY %source% %destination% *.srt *.pdf *.mp4 *.jpg /COPYALL /R:0 /S
for /r %source in (*) do @copy "%destination" .

R:\ Contracts \は、ファイルを含むフォルダーでいっぱいです。

すべてをR:\ Contracts \ Sites \にコピーして、フォルダー構造をフラットにします。

すべてがうまくコピーされますが、フォルダ構造もコピーされます。

ありがとうございました

4

5 に答える 5

1

私は最近この問題に取り組む必要があり、階層から単一のフォルダーに移動したい多くのファイルが互いに同じ名前であり、それらが上書きされることなく階層をフラットにしたいと考えていました。私がしたことは、ファイルを移動するスクリプトを作成することでしたが、名前に古い階層パスを使用して名前 を変更しました。たとえば、ソースファイル:

C:\files\somefiles\file.txt

C:\files\otherfiles\file.txt

宛先は C:\newdir\ ファイルは次のように作成されます

C:\newdir\somefiles-file.txt

C:\newdir\otherfiles-file.txt

これがコードです。バッチファイル1はファイルを通過し、バッチファイル2は名前を変更して移動します(ソースを保持したい場合は、代わりにコピーすることもできます:

@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%"
于 2014-09-12T09:45:35.983 に答える
0

現在のディレクトリとサブディレクトリで同じコマンドを実行できる Sweep.exe という古い PCMag ユーティリティがあります。宛先をソースディレクトリのサブディレクトリとして配置しません。目的地を別の場所に置きます。

http://www.rarewares.org/files/case/Sweep.zip

cd c:\contracts sweep copy *.* c:\sites

これにより、c:\contracts 以下のすべてが c:\sites にコピーされます。

同様のコマンドを使用して、ディレクトリの階層をフラット化します。

重複とその処理方法に注意してください。上書きするか、別の方法で処理しますか。

于 2015-08-22T22:10:09.483 に答える