简体   繁体   English

Windows批处理以覆盖文件夹和子文件夹中的现有文件

[英]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.

相关问题 将子文件夹中的文件移动到文件夹并重命名Windows提示符 - Move files in subfolders to a folder and rename windows prompt 如何批量复制源文件夹和子文件夹中的所有文件 - How do I copy all files in the source folder and in the subfolders in batch Mac OS - 批量重命名文件夹中的所有文件但忽略所有子文件夹 - Mac OS - Batch Rename All Files in Folder but Disregard All SubFolders 在文件夹和子文件夹中Py搜索文件 - Py Search files in Folder and Subfolders 批处理文件以列出文件夹内的子文件夹 - Batch file to list subfolders inside a folder 如何复制某些文件(没有文件夹层次结构),但不要覆盖现有文件? - How to copy certain files (w/o folder hierarchy), but do not overwrite existing files? 根据名称批量移动文件到新的子文件夹 - Batch move files to new subfolders based on name 从共享文件夹Windows批处理中删除X个较早的文件 - Delete X olderdays Files from Shared Folder windows batch 在批处理中播放Windows Media Player中光盘中的文件夹 - Playing folder full of files from Disc in Windows Media Player in Batch 在文件夹和子文件夹中查找所有文件的另一种方法 - Alternative way to find all files in a folder and subfolders
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM