[英]Windows Batch to Overwrite Existing files in folder and subfolders
I am not good in this. 我不擅长这个。 I really need help.
我真的需要帮助。
I have searched a lot but no luck. 我搜索了很多但没有运气。
I want to create empty files and replace existing in a folder and its subfolders. 我想创建空文件并替换文件夹及其子文件夹中的现有文件。
From my search, I could find how to make a batch to delete. 从我的搜索,我可以找到如何删除批处理。
set folder="test"
cd /d %folder%
for /F "delims=" %%i in ('dir /b') do (rmdir "%%i" /s/q || del "%%i" /s/q)
However, I want to replace the files with empty one, I tried this: 但是,我想用空的文件替换文件,我试过这个:
set folder="test"
cd /d %folder%
for /F "delims=" %%i in ('dir /b') do (echo. 2>"%%i")
But it is not working. 但它没有用。 I need this to replace all my existing files so after delete it should not be recovered.
我需要这个来替换我现有的所有文件,所以删除后不应该恢复。
Better quote the whole set command and use always quotes: 更好地引用整个set命令并始终使用引号:
set "folder=x:\test"
cd /d "%folder%" ||(pause&Goto :Eof)
for /F "delims=" %%i in ('dir /b/A-D') do Type Nul >"%%i"
To not by mistake clear the current folder I added the ||(pause&Goto :Eof)
in case the cd didn't work. 为了不错误地清除当前文件夹,我添加了
||(pause&Goto :Eof)
,以防cd无效。 This is a conditional execution on fail of the previous command 这是上一个命令失败的条件执行
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.