batch-file - 如何使用bat脚本检查文件夹中文件的大小并移动它
问题描述
感谢任何人的帮助。我很坚持这一点。
我正在编写一个 bat 脚本来将文件从一个文件夹移动到另一个文件夹。(这部分很简单)
但是,在实际移动文件之前,我想检查文件的大小是否每 45 秒更改一次。如果文件的最后大小等于当前大小,则 finally 将移动它。(此检查的原因是源文件夹中的文件可能仍在写入中,我们不想在完成之前移动它)
请帮忙,我愿意接受建议
目前有这个代码,我卡住了:
for %%a in (%_fromFolder%\*%_fileName%*%_extension%) DO (
echo %%~za
set "fname=%~1"
set fSize = %%~za
timeout /t 45 /nobreak
:loop
if fSize == %%~za (
echo %fSize%
echo %%~za
goto :moveF
) else (
set fSize =%%~za
timeout /t 45 /nobreak
goto :loop
)
)
:moveF
move %~1 %_toFolder%
解决方案
我在代码中添加了注释来解释它在做什么。
REM Get list of files
for %%G in ("%_fromFolder%\*%_fileName%*%_extension%") DO (
REM Call function to check for the size of the file
CALL :CHECK "%%G"
REM Back from the Function. now move the file
move "%%~G" "%_toFolder%"
)
GOTO :EOF
:CHECK
REM set the size of the file to a variable
set "fsize=%~z1"
REM delay program
timeout /t 45 /nobreak
REM check to see if the file size is the same. IF it is then leave the function
if "%fSize%"=="%~z1" GOTO :EOF
REM Go back to the check if the file size is not the same
GOTO CHECK
推荐阅读
- python - Pyplot 没有为检测到的峰绘制标记
- visual-studio-code - vs-code 在 ubuntu 18.04 中使用了超过 2GB 的 RAM。有什么解决办法吗?
- javascript - 如何使用 reactjs 使用 scrollintoview 方法将列表项滚动到视图中?
- python - aiohttp : 有什么方法可以检测 aiohttp 中的用户名错误还是密码错误?
- javascript - 如何从 NOSQL 数据库中获取数据并在 React 中显示?
- python - 将数据帧转换为列表时,整数值被转换为长整数
- sql - 在 SQL MS Access 中连接两个相似的表
- javascript - 如何将角度数据转换为正确的张量格式?
- c++ - qt 给对象函数一个 ui 组件
- javascript - 媒体查询不适用于 React 中的 CSS 模块