[Bash shell] 纯文本查看 复制代码@echo off
setlocal enabledelayedexpansion
:: 配置文件类型(可根据需要修改扩展名)
set "img_ext=*.jpg *.jpeg *.png *.gif *.bmp *.webp"
set "vid_ext=*.mp4 *.avi *.mov *.mkv *.flv *.wmv"
:: 请求用户输入目标文件夹路径
set /p target_dir="请输入目标文件夹路径(例如 D:\Code\1):"
if "%target_dir%"=="" (
echo 错误: 目标文件夹路径不能为空。默认为D:\Code\1
set "target_dir=D:\Code\1"
)
:: 日志文件路径
set "log_file=%target_dir%\file_mover_log.txt"
:: 创建目标目录(若不存在)
if not exist "%target_dir%" (
mkdir "%target_dir%" 2>&1 || (
echo 错误: 无法创建目标目录 "%target_dir%" >> "%log_file%"
echo 错误: 无法创建目标目录 "%target_dir%"
pause
exit /b 1
)
)
echo 正在扫描文件以计算总数... 请稍候
:: 初始化计数器
set /a total_files=0
for /r %%f in (*.*) do (
set /a total_files+=1
)
set /p check="是否继续移动 %total_files% 个文件?(Y/N): "
if /i not "!check!"=="Y"(
echo 操作已取消。
pause
)
echo -------------------------------
echo 源目录: %cd%
echo 目标目录: %target_dir%
echo -------------------------------
echo 总文件数量: %total_files%
echo -------------------------------
echo 开始移动文件...
:: 初始化计数器
set /a file_count=0
set /a processed_files=0
set /a batch_size=100 :: 每批处理的文件数量
:process_files
for /r %%f in (*.*) do (
set "filename=%%~nxf"
set "filepath=%%~dpf"
:: 显示进度
set /a processed_files+=1
if !processed_files! geq !batch_size! (
goto :prompt_continue
)
:: 排除脚本自身
if not "%%~nxi"=="%~nx0" (
:: 检查是否为图片或视频
echo !filename! | findstr /i /r /c:"%img_ext%" >nul && (
set "file_type=img"
) || echo !filename! | findstr /i /r /c:"%vid_ext%" >nul && (
set "file_type=vid"
) || (
goto :continue
)
:: 创建目标子目录(保留原始结构)
set "rel_path=!filepath:%cd%=!"
set "dest_dir=%target_dir%!rel_path:\=\!"
if not exist "!dest_dir!" (
mkdir "!dest_dir!" 2>&1 || (
echo 错误: 无法创建目标子目录 "!dest_dir!" >> "%log_file%"
goto :continue
)
)
:: 移动文件
move /y "%%f" "!dest_dir!" >nul 2>&1
if errorlevel 1 (
echo [!] 移动失败: "!filename!" >> "%log_file%"
echo [!] 移动失败: "!filename!"
echo 尝试以管理员身份运行脚本或检查文件是否被锁定。 >> "%log_file%"
) else (
set /a file_count+=1
echo [√] 已移动: "!filename!" >> "%log_file%"
echo [√] 已移动: "!filename!"
)
)
:continue
)
goto :end
:prompt_continue
set /p continue="已处理 %batch_size% 个文件,是否继续?(Y/N): "
if /i not "!continue!"=="Y" (
echo 操作已取消。
exit /b 0
)
set /a batch_size+=100
goto :process_files
:end
echo -------------------------------
echo 操作完成!共移动 %file_count% 个文件
echo 操作完成!共移动 %file_count% 个文件 >> "%log_file%"
pause
exit /b 0
或https://wwua.lanzouo.com/i3f5G2z23dcd密码:52pj
本人学生,可能回复不及时,见谅