简体   繁体   English

如何使用Windows批处理命令删除“没有扩展名的文件”的所有内容

[英]How to Delete all contents of a “File with no extension” using windows batch Command

I want to delete the contents of a file which has "FIlE" as extension ie with no extension. 我想删除文件的内容,其中“FIlE”作为扩展名,即没有扩展名。 I know how to delete the contents of a Text file, but not about the file which has "File" as extension. 我知道如何删除文本文件的内容,但不知道如何删除“文件”作为扩展名的文件。

I would appreciate your efforts. 我很感激你的努力。 Thanks in advance. 提前致谢。

Use Del *. 使用Del *. in batch file to remove files with no extension. 在批处理文件中删除没有扩展名的文件。

use Dir /AD *. 使用Dir /AD *. to list down all files with no extension. 列出所有没有扩展名的文件。

Use following command to clear the contents of a file 使用以下命令清除文件的内容

findstr "Any data that is not available in origfilename" origfilename > origfilename

Try this: 试试这个:

echo. 2>file.

It will basically overwrite the file with nothing, achieving the same goal as removing all the contents. 它基本上会覆盖整个文件,实现与删除所有内容相同的目标。 Just replace file. 只需替换file. with your file. 与您的文件。 To specify no extension just don't put anything after the . 要指定没有扩展名,请不要在之后放置任何内容.

Hope this helps. 希望这可以帮助。

copy nul YourFIlE
copy /y nul YourFIlE

In case you wonder, NUL is a special name (like /dev/null on UNIX), just as CON (which is the console). 如果您想知道, NUL是一个特殊名称(如UNIX上的/dev/null ),就像CON (它是控制台)一样。 I think this is the best way to clear the contents. 我认为这是清除内容的最佳方式。 The file will then have 0 bytes in it. 然后该文件将包含0个字节。 An echo plus output redirection will write one line to the file, so it does not completely clear the contents. echo plus输出重定向将向文件写入一行,因此不会完全清除内容。

How about 怎么样

del /s "*."

Worked well on the tests I did on windows 10. Test it of course in a safe directory. 我在Windows 10上进行的测试工作得很好。当然在安全目录中测试它。 You can of course put this into a batch. 你当然可以把它放到批处理中。 I do one for cleaning out annoying left overs like .txt with something like: 我做了一个用于清理像.txt这样烦人的遗留问题,例如:

echo off

del /s D:\FILES\completed\*.nfo

del /s D:\FILES\completed\*.wflow

del /s D:\FILES\completed\*.workflow

del /s "D:\FILES\completed\*."

echo complete

echo on

Will delete all files in the main directory and all sub directories. 将删除主目录和所有子目录中的所有文件。
Quotes were required as it would not work without them. 需要引用,因为没有它们就行不通。 Did not try it with 3 deep extenstions. 没有尝试过3次深度扩展。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何在 Windows 中使用 bat 文件删除文件夹和所有内容? - How to delete a folder and all contents using a bat file in windows? Windows批处理文件删除桌面上的所有文件 - Windows batch file to delete all files on desktop 使用批处理命令查找扩展名为 csv 的文件 - Find file with extension csv using batch command 如何删除带有cmd批处理的具有特定扩展名的所有文件(不包括2个特定单词)? 视窗 - How can delete all files with a specific extension with cmd batch, excluding 2 specific words? Windows 如何替换Windows批处理文件中的变量内容 - How to substitute variable contents in a Windows batch file 如何使用批处理文件在 Windows 10 中删除具有特定名称的文件? - How to delete files with specific names in windows 10 using batch file? 如何使用Windows命令提示符打开和列出zip文件的内容? - How to open and list contents of a zip file using windows command prompt? 如何使用带有空格的路径和命令的“start”在Windows中创建批处理文件 - How to create batch file in Windows using “start” with a path and command with spaces 如何使用批处理文件在Windows上复制open命令的功能? - How to replicate the functionality of the open command on Windows using a batch file? 使用批处理命令删除由已删除的Win​​dows服务的进程使用的文件 - delete file which is used by a process of deleted windows service using batch command
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM