batch-file - 通过批处理文件比较两个文件夹的内容而不是两个文件的内容
问题描述
我正在将位于共享网络文件夹中的特定文件夹的备份批处理文件写入我的个人 Windows 机器。
我想跟踪对此网络文件夹所做的更改,因此我保留了许多备份文件夹,它们的名称为日期戳+时间戳,例如在12 月 ( )日20181224145231
创建的备份文件夹,时间为h min sec。24
12
2018
14
52
31
我所有的 datestamp+timestamp 备份文件夹都位于一个单独的文件夹中。
为此,我提出了一个脚本,该脚本从系统中获取日期和时间,并检查原始文件夹中的特定文件是否与使用的最后一个备份文件夹中的文件不同,fc
并使用一个for
循环来获取创建的最后一个备份文件夹过去。
事情已经发展,我需要比较整个文件夹(与子文件夹)的内容,而不仅仅是一个文件。这就是我碰壁的地方。
我已经研究过comp
and fc
,但似乎找不到方法。Robocopy
同步文件夹,但我想在每次发生更改时创建一个新文件夹。我正在考虑的一件事是在两个文件夹中创建一个比较文件,如 7-zip 文件并在这两个文件夹上运行fc
,但这似乎相当极端。
所以总结我的问题是:
如何通过批处理文件检查最新备份是否与没有第三方工具的网络共享文件夹具有相同的文件?
解决方案
根据您的要求,在评论中指定,您可以尝试:
@echo off
rem Set variables for size count:
set total_size_backup=0
set total_size_origin=0
rem Find the most recent BACKUP folder:
for /F "delims=" %%A IN ('dir /b /AD /OD') do set "folder_to_search=%%~fA"
rem Find the size of all files inside the backup folder:
for /R "%folder_to_search%" %%B IN (*.*) do (
set /a "total_size_backup+=%%~zB"
)
rem Find the size of the original folder:
for /R "full_path_to_folder_with_original_files" %%C IN (*.*) do (
set /a "total_size_origin+=%%~zC"
)
rem Compare the two sizes from these two folders. If they are NOT the same include your code there.
if %total_size_backup% EQU %total_size_origin% (
echo Well Done! Your newest backup files and your original files are up-to-date!
pause>nul
exit /b 0
) else (
echo Ooops! Your newest backup files and your original files are out-of-date! Never worry! Running backup now, please wait...
start /min /wait your_backup_file.bat
echo Updated files successfully!
exit /b %errorlevel%
)
推荐阅读
- node.js - 在 MERN 应用程序中使用 Router.put 和 mongoDB 进行投射的问题
- css - 使用 CSS 定位特定链接
- mysql - 我在 mysql 中添加两个检查约束得到 3813 错误
- python - “此包不应在 Python 3 上访问”错误
- c# - 如何使用 Anglesharp 从 HTML 表中删除所有行?
- hangouts-api - Hangouts Chat:如何在传入事件请求中检索 project_id 或 client_id?
- android - 在android上的多个div上分割背景
- javascript - 如何在 react-material ui 中添加嵌套列表
- reactjs - 尽管有 polyfills 和浏览器列表,但默认的 create-react-app 在 IE 中不起作用
- macos - 如何安装 memcache 扩展(php72、macos Catalina)