2

ファイルが既に存在する場合、ファイルをあるフォルダーから別のフォルダーに移動し、新しいファイルを作成するスクリプトが必要です。

たとえば、ダウンロード フォルダーにファイル test.csv があります。以下のスクリプトを実行すると、downloads1 フォルダーに同じ名前のファイルが存在する場合にファイルが上書きされます。

しかし、私が望むのは、既存のファイルを上書きするべきではありませんが、両方のファイルがそこにあるはずです..名前が変更される可能性があります。

move C:\user\Downloads\*.csv C:\user\downloads1\

また、 /-Y を使用すると、上書きする必要があるかどうか尋ねられることもわかっています。しかし、私はこれを自動的に行いたいです。

move /-Y C:\user\Downloads\*.csv C:\user\downloads1\
4

2 に答える 2

1

最初に存在しないファイルを移動してから、ソース ディレクトリ内の残りのファイルの名前を変更してから、ターゲットにコピーできます。

@echo off
    setlocal enableextensions enabledelayedexpansion

    rem configure directories
    set "source=c:\user\Downloads"
    set "target=c:\user\Downloads1"

    rem move non existing files to target
    call :doMove    

    rem if we still have files
    if exist "%source%\*.csv" (

        rem generate a timestamp
        set timestamp=_%date:/=%_%time::=%
        set timestamp=!timestamp:,=!

        rem rename the remaining files with timestamp
        ren "%source%\*.csv" "*.!timestamp!.csv"

        rem and move the remainig files to target
        call :doMove
    )

    endlocal
    exit /b

:doMove
    robocopy "%source%" "%target%" "*.csv" /fp /njh /njs /ndl /xc /xn /xo /xx /mov
    goto :EOF
于 2013-10-31T09:34:22.973 に答える