2017-05-29 4 views
0

指定した日付の後にファイルをコピーしたくない場合は、誰かが私に教えてもらえますか? など。私が日付10-MAY-2017 & 11-MAY-2017を指定し、フォルダに10 & 11月2017のファイルがある場合、10-MAY-2017ファイルのみをコピーしたい場合。何か方法はありますか?当面の作業のためにXCOPYコマンドファイルをコピーする日付オプション

+0

は、ドキュメントを読んで(コマンドプロンプトに 'XCOPY /'と入力?)、その後、あなたは見つけるでしょう! ['robocopy'](http://ss64.com/nt/robocopy.html)に切り替えることを検討してください... – aschipfl

+0

' xcopy'を主張するなら、次のようにすることができます: 'xcopy/L/D: ... "source" "destination"> "tempfile.txt" '(リストファイルは日付以降に変更されます)、' xcopy/L "source" "destination" | findstr/V/X/L /G:"tempfile.txt ">" copylist.txt "(日付の前にリストファイルが変更されている)、次に' xcopy/T "source" "destination" '(ディレクトリを準備する) ( '[for/F'](http://ss64.com/nt/for_f.html)を参照してください)... – aschipfl

+0

申し訳ありませんがうまくいきませんでした。誰かが解決策を提供することができます –

答えて

0

robocopyはそれを行うための最も簡単な方法です:

robocopy D:\Source D:\Destination *.* /S /MINAGE:20170510 

スイッチ/MINAGEの名前にもかかわらず、ではないが、作成最終更新日時がみなされています。あなたはここで、xcopyを使う、という場合は


次の手順を行いxcopyに基づいたスクリプトは次のとおりです。彼らは上の変更されているので

  • は、コピーしてはいけないファイルのリストを作成します指定された日付以降。これはxcopy /L /F /D:が使用されます:/Lは、完全に解決された送信元と宛先のパスを出力するように/Fが定義していますが、コピーしないことを意味し、/D:は最後の変更日を定義します。
  • findstrを使用して、利用可能なすべてのファイル(xcopy /L /F)のリストから上記のすべてのファイルを除外します。
  • プレーンディレクトリツリー(xcopy /T)をコピーします。
  • フィルタリングされたファイルリストを参照し、すべての単一ファイルを個別にcopyでコピーします。

これはコードです:/ D

@echo off 
setlocal EnableExtensions DisableDelayedExpansion 

rem // Define constants here: 
set "SOURCE=D:\Source"  & rem // (source directory) 
set "DESTIN=D:\Destination" & rem // (target directory) 
set "PATTERN=*.*"   & rem // (file pattern) 
set "COPYDATE=05-11-2017" & rem /* (last modification date; only files are copied 
           rem  which are modified earlier; check format!) */ 
set "TEMPFILE=%TEMP%\%~n0_%RANDOM%.tmp" & rem // (list of source files not to copy) 
set "COPYLIST=%TEMP%\%~n0_%RANDOM%.lst" & rem // (full list of files to copy) 

rem // List files modified on or after given date: 
> "%TEMPFILE%" (
    for /F "tokens=1 delims=>" %%F in (' 
     xcopy /L /I /F /D:%COPYDATE% "%SOURCE%\%PATTERN%" "%DESTIN%" ^| find ":" 
    ') do (
     set "FILE=%%F" 
     rem /* Double every `\` as `findstr` uses such as escape character; 
     rem then append ` -> ` which is used by `xcopy /F` as separator: */ 
     setlocal EnableDelayedExpansion 
     (echo(!FILE:\=\\!^>) 
     endlocal 
    ) 
) 
rem /* List files modified before given date 
rem (actually the temporary `%COPYLIST%` file is not really necessary, 
rem  but it is quite convenient for understanding what is going on; instead 
rem  the below `for /F` loop could parse the output of this command line): */ 
xcopy /L /I /F "%SOURCE%\%PATTERN%" "%DESTIN%" | find ":"^
    | findstr /V /B /L /I /G:"%TEMPFILE%" > "%COPYLIST%" 
rem // Prepare directory tree as `copy` (below) cannot create directories: 
xcopy /I /T "%SOURCE%\%PATTERN%" "%DESTIN%" > nul 
rem // Copy files from list: 
for /F "usebackq tokens=1* delims=>" %%E in ("%COPYLIST%") do (
    set "LEFT=%%E" & set "RIGHT=%%F" 
    setlocal EnableDelayedExpansion 
    ECHO copy /Y "!LEFT:~,-2!" "!RIGHT:~1!" 
    endlocal 
) 
rem // Clean up temporary files: 
del "%TEMPFILE%" "%COPYLIST%" 

endlocal 
exit /B 
+0

RobCopyコマンドをお寄せいただきありがとうございます。しかし、ファイル9,10&11があれば、私は10日目にコピーしたいです。 10両方。 –

+0

特定の日付のファイルのみをコピーしたいのですか?これはあなたの質問が言うことではありません... – aschipfl

0

:MM-DD-YYYYのコピーファイルは、指定した日付以降に変更しました。日付が指定されていない場合は、ソースの日付/時刻が宛先の時刻よりも新しいファイルのみをコピーします。

例:XCOPY/D:MM-DD-YYY

関連する問題