1

Windows Server 2008 R2 を使用しています。

私のスクリプトは、入力したファイルが存在することを確認してから、移動するファイルが に存在しないことを確認しますrecycleBin.dir。ファイルを上書きするかどうかの選択もあります。「はい」を選択すると、スクリプトはそれらを移動します。

私の問題は、1 つだけでなく複数のファイルを入力できるようにする必要があることです。

私がやったこと:

@echo off
set param = "%*"
set corb_path=c:\corbeille.dir
set rep_courant = %cd%
:debut
if "%*" == "" goto error
goto path
goto end
:path
cd %corb_path%|| del %corb_path%
if not exist %corb_path%/nul mkdir %corb_path%
cd c:\
if exist %rep_courant%%* goto something 
  ) else ( 
goto end )
:something
if exist %corb_path%\"%*" goto choice
 ) else ( 
 goto 1 )
:choice 
choice /t 10 /d n /c on /cs /m "fichier "(%*)" file exist in corbeille.dir"
if errorlevel 2 goto 2
if errorlevel 1 goto 1 
:1
move %* %corb_path%
shift
goto debut 
:2
echo the file has beed deleted
goto end
:error
echo "You need to input something"
:end
4

1 に答える 1

1

コマンドラインパラメータとして渡された各ファイルをスクリプトで処理したいですか?

コウモリについて私が見たところ、いくつかの行を変更する必要があります。主な問題は、%*. これにより、一度に 1 つずつではなく、すべてのパラメーターが一度に取り込まれます。を使用したくなるでしょう%1

行 6 を変更します。

if "%1" == "" goto error

13 行目を変更します。

if exist %rep_courant%%1 goto something 

17 行目を次のように変更します。

if exist %corb_path%\"%1" goto choice

行 21 を変更します。

choice /t 10 /d n /c on /cs /m "fichier "(%1)" file exist in corbeille.dir"

行 25 を変更します。

move %1 %corb_path%

%1コマンドにより、常に次のアイテムがありますshift

文字列、引用符、およびスペースに関して、後で更新された回答で対処する可能性のある他の変更もいくつかありますが、上記の変更はあなたが望むことを行うはずです.

ところで: 2 行目と 8 行目は、スクリプトでは何も役に立ちません。それらは削除できます。

于 2013-01-21T03:38:28.703 に答える