从批处理文件创建空白文件

发布于 2024-10-03 20:04:04 字数 83 浏览 0 评论 0原文

我想从批处理文件创建一个文件。我可以使用 echo。 > donald.txt,但它使用初始空行创建它。对于从第一行开始的文件,我还可以使用什么?

I would like create a file from a batch file. I can use the echo. > donald.txt, but it creates it with an initial blank line. What else I can use to a file starting from the first line?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(5

怀里藏娇 2024-10-10 20:04:04

您只想创建一个完全空的文件?这样就可以了:

copy /y nul donald.txt

如果你想在第一行写一些东西,你想要这样的东西:

echo Hello, World > donald.txt

You just want to create a completely empty file? This will do it:

copy /y nul donald.txt

If you're looking to write something to first line, you want something like this:

echo Hello, World > donald.txt
零時差 2024-10-10 20:04:04

其中一个选项

@echo off
rem Don't destroy an existing file
if exist testfile goto _nocreate
:: Create the zero-byte file
type nul>testfile
:_nocreate

最初来自 http://www.netikka.net/tsneti/info/ tscmd041.htm 其中包含一些附加方法。

One of the options is

@echo off
rem Don't destroy an existing file
if exist testfile goto _nocreate
:: Create the zero-byte file
type nul>testfile
:_nocreate

Originally from http://www.netikka.net/tsneti/info/tscmd041.htm which contains some additional methods.

她比我温柔 2024-10-10 20:04:04

在旧的 MS-DOS 时代,我使用这种方法创建一个空文件:

rem > empty.txt

在新的 Windows 中,这不再有效,但 rem 可以被任何不显示任何内容的命令替换。例如:

cd . > empty.txt

In old MS-DOS days I used this method to create an empty file:

rem > empty.txt

In new Windows this no longer works, but rem may be replaced by any command that show nothing. For example:

cd . > empty.txt
饭团 2024-10-10 20:04:04

如果您使用的是 PowerShell:

function touch {set-content -Path ($args[0]) -Value ($null) } 
touch file-name

来源:http://blog.lab49.com/archives/249

If you're using PowerShell:

function touch {set-content -Path ($args[0]) -Value ($null) } 
touch file-name

Source: http://blog.lab49.com/archives/249.

花开浅夏 2024-10-10 20:04:04

这是因为 echo. 在文件中插入一个空行。

尝试使用相同的代码,但不要在 echo 语句末尾附加句点:

echo "Test string" > donald.txt

That's because echo. inserts a blank line in your file.

Try using the same code, but without the period appended to the end of the echo statement:

echo "Test string" > donald.txt
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文