@echo off set mypath=. rem cd /d "%mypath%" setlocal enableDelayedExpansion for %%f in…
- User
@echo off set mypath=. rem cd /d "%mypath%" setlocal enableDelayedExpansion for %%f in (.zip) do ( echo PROCESSING: %%~dpfnxf for /f "tokens=1 delims=- " %%S in ('md5sum ^< "%%~dpfnxf" ') do set "sum=%%S" echo SUM: !sum! :rm %mypath%%%f.tmp pause ) endlocal pause
- Assistant
This is a batch script that processes all the ".zip" files in the current directory and calculates their MD5 checksum using the "md5sum" utility. It then displays the checksum and pauses for user input.
The script starts by setting a variable "mypath" to the current directory (".") but this line is commented out.
The "setlocal enableDelayedExpansion" command enables delayed expansion of variables, which allows us to refer to the "sum" variable inside the inner loop.
The outer loop iterates over all ".zip" files using a "for" loop. Inside the loop, we first print a message indicating which file is being processed.
We then use another "for" loop with the "md5sum" command to calculate the MD5 checksum of the file. The output of "md5sum" is piped to the inner loop which extracts the first token (the checksum value) and stores it in the "sum" variable. Note that we use delayed expansion with the "!" syntax to refer to the variable inside the inner loop.
Once we have the checksum value, we display it using the "echo" command.
Finally, we delete a temporary file with the same name as the original file (but with a ".tmp" extension) and pause for user input before continuing to the next file in the outer loop.
- User
当前目录下的文件比较
- Assistant
您可以使用以下脚本进行文件比较:
@echo off setlocal enabledelayedexpansion set "dir1=input_dir1" set "dir2=input_dir2"
for %%a in ("%dir1%*.") do ( set "match=" for %%b in ("%dir2%*.") do ( if "%%~na%%~xa"=="%%~nb%%~xb" ( set "match=1" fc /b "%%a" "%%b" >nul if errorlevel 1 ( echo "%%~na%%~xa" is different copy "%%a" "output_dir%%~na%%~xa" copy "%%b" "output_dir%%~nb%%~xb" ) goto :exit_inner ) ) if not defined match ( echo "%%~na%%~xa" is only in %dir1% copy "%%a" "output_dir%%~na%%~xa" ) :exit_inner )
for %%b in ("%dir2%*.") do ( set "match=" for %%a in ("%dir1%*.") do ( if "%%~nb%%~xb"=="%%~na%%~xa" ( set "match=1" goto :exit_inner2 ) ) if not defined match ( echo "%%~nb%%~xb" is only in %dir2% copy "%%b" "output_dir%%~nb%%~xb" ) :exit_inner2 )
echo Done! pause
此脚本将比较两个目录中的所有文件并检查它们是否相同。如果文件不同,则将其复制到指定的输出目录中。
请注意,您需要将“input_dir1”和“input_dir2”替换为要比较的实际目录,并将“output_dir”替换为要将不同的文件复制到的实际目录。
- User
当前目录内的文件
- Assistant
您可以使用以下的脚本获取当前目录内的所有文件的列表:
@echo off setlocal EnableExtensions EnableDelayedExpansion
set "dir=%cd%" set "ext=."
for /r "%dir%" %%f in (%ext%) do ( echo %%~nxf )
请将上述脚本另存为一个批处理文件,然后双击运行它,将输出当前目录下的所有文件的名称和扩展名。您也可以修改“dir”和“ext”变量,以指定特定的目录和文件扩展名。
请注意,此脚本将递归遍历指定的目录和所有子目录中的所有文件,并输出它们的名称和扩展名。如果您只想获取当前目录中的文件列表,而不包括子目录中的文件,请删除“/r”选项。
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.