入力文字列と同じ名前のファイルのすべてのパスを見つけるバッチスクリプトを作成しようとしました。今すぐ発見された最初のファイルのみを見つけることができ、複数のファイルの場所をリストする方法を考えることはできません。私は経験が豊富ではなく、助けが必要です。同じファイル名で複数のファイルのパスを見つける
これはスクリプトコードの一部です:
:start
cls
echo Enter file name with extension:
set /p filename=
echo Searching...
for %%a in (C D E F G H U W) do (
for /f "tokens=*" %%b in ('dir /s /b "%%a:\%filename%"') do (
set file=%%~nxb
set folderpath=%%~dpb\
::the path of the file without the filename included "C:\folder\folder\"
set fullpath=%%b
::the path of the file with the filename included "C:\folder\folder\file"
goto break
)
)
:notfound
cls
echo Enter file name with extension:
echo %filename%
echo File Not Found!
ping localhost -n 4 >nul
goto start
:break
if "%folderpath:~-1%"=="\" set folderpath=%folderpath:~,-1%
cls
echo ? %filename% found
echo %fullpath1%
echo %fullpath2%
echo %fullpath3%
--- || ---
私はスクリプトは、コンピュータを検索し、同じ名前を持つすべての遭遇ファイルをリストにしたいと私は違うの中にそれらのファイルのパスを置くことができるようにしたいです変数。 たとえば、readme.txtが入力の場合、その特定の名前(readme.txt)を持つすべてのファイルのすべてのパスのリストが必要です。そのあとで使用できるように、各パスに変数を設定します。
例:
input:
readme.txt
output:
3 files found
C:\folder\folder\readme.txt
C:\folder\folder\folder\readme.txt
D:\folder\readme.txt
variables:
path1 = C:\folder\folder\readme.txt
path2 = C:\folder\folder\folder\readme.txt
path3 = D:\folder\readme.txt
ご意見ありがとうございます。私はあなたの助言を取って、同時に複数のファイルを検索するのではなく、バッチファイルを一度に検索してすべての機能で実行した後、別のファイルを検索してファイルがなくなるまでもう一度やり直した。 –