在批处理文件中创建文件命令(* .bat)的形式 [英] Create File Command in Batch Files (*.bat)

查看:855
本文介绍了在批处理文件中创建文件命令(* .bat)的形式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我要创建文件夹%电视%使用批处理文件中命名的文件新建文本文档( *。蝙蝠)。这是我的批处理文件:

I want to create a file named "new text document.txt" in the folder %tv% using a batch file ( *.bat). This is my batch file:

set tv=D:\prog\arpack96\ARPACK\SRC
cd "%tv%"
@CON >> "new text document.txt"
set tv=

虽然我真的可以创造%电视%文件,但是当我运行上面的批处理文件,我会得到一个错误信息说

Although I can really create the file in %tv%, but when I run the above batch file, I will get an error message saying

没有被识别为一个内部
  或外部命令,可操作的程序
  或批处理文件。

' ' is not recognized as an internal or external command, operable program or batch file.

反正是有摆脱此错误消息的?或我使用了错误的命令创建文件?

Is there anyway to get rid of this error message? Or I am creating the file using the wrong command?

推荐答案

为了得到一个真正的空文件,而无需提供用户交互,你可以使用设置/ P 一个小诡计命令:

In order to get a truly empty file without having to provide user interaction, you can use the set /p command with a little trickery:

set tv=c:\documents and settings\administrator
cd "%tv%"
<nul >"new text document.txt" (set /p tv=)

设置/ P 要求用户输入到电视变量后,<$输出提示后C $ C> = 字符。

The set /p asks the user for input into the tv variable after outputting the prompt after the = character.

由于该提示是空的,不会显示任何提示。既然你从NUL读,它不会等待用户交互。并且可以将空字符串存储直冲电视从而不再需要取消它。

Since the prompt is empty, no prompt is shown. Since you're reading from nul, it doesn't wait for user interaction. And you can store the empty string straight into tv thus removing the need to unset it.

事实上,一些更多的思考之后,有一个更简单的方法。我使用了设置/ P 在过去的欺骗,因为这是我知道的添加(非常适合在控制台进度条)相呼应的文本,不换行的唯一途径。但是,如果你想要的是一个空文件,你也许可以蒙混过关:

Actually, after some more thought, there's an easier way. I've used that set /p trick in the past since it's the only way I know of echoing text without a newline being added (great for progress bars in the console). But if all you want is an empty file, you can probably get away with:

copy /y nul "new text document.txt"

复制简单地复制 NUL 装置(有效的空文件)到新的文件名的内容。在 / Y 是要确保它的覆盖,而不会打扰用户。

The copy simply copies the contents of the nul device (effectively an empty file) to your new file name. The /y is to ensure it's overwritten without bothering the user.

这篇关于在批处理文件中创建文件命令(* .bat)的形式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆