如何将文本回显到文件前缀由一个或多个 env 组成的文件中。变量中有空格吗?

发布于 2024-11-02 07:48:26 字数 316 浏览 1 评论 0原文

2 环境。 vars set previous

overall_timestamp_first=2011-03-14 20:40:49
overall_timestamp_last=2011-03-15 02:55:20

我试图使用批处理文件中的命令来使用 env.vars 来创建文件。变量。

echo Application Error Event Analysis > "%overall_timestamp_first% - %overall_timestamp_last%.doc"

The 2 env. vars set previously

overall_timestamp_first=2011-03-14 20:40:49
overall_timestamp_last=2011-03-15 02:55:20

The command in a batch file I'm trying to get to use to create a file using the env. vars.

echo Application Error Event Analysis > "%overall_timestamp_first% - %overall_timestamp_last%.doc"

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

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

发布评论

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

评论(2

猫卆 2024-11-09 07:48:26

文件名中的冒号是问题所在。它们在 DOS/Windows 中的文件名不合法。

将时间戳格式更改为 hh.mm.ss 这将起作用:

set overall_timestamp_first=2011-03-14 20.40.49
set overall_timestamp_last=2011-03-14 21.00.00
set overall_filename="%overall_timestamp_first%-%overall_timestamp_last%.txt"
@echo Application Error Event Analysyis > %overall_filename%

在我的机器上输出:

D:\Temp>dir 2*
 Volume in drive D is Something
 Volume Serial Number is ABCD-DCBA

 Directory of D:\Temp

04/15/2011  09:03 PM                36 2011-03-14 20.40.49-2011-03-14 21.00.00.txt
               1 File(s)             36 bytes
               0 Dir(s)  204,289,437,696 bytes free

The colons in the filename are the problem. They're not legal in filenames in DOS/Windows.

Change your timestamp format to hh.mm.ss and this will work:

set overall_timestamp_first=2011-03-14 20.40.49
set overall_timestamp_last=2011-03-14 21.00.00
set overall_filename="%overall_timestamp_first%-%overall_timestamp_last%.txt"
@echo Application Error Event Analysyis > %overall_filename%

Output on my machine:

D:\Temp>dir 2*
 Volume in drive D is Something
 Volume Serial Number is ABCD-DCBA

 Directory of D:\Temp

04/15/2011  09:03 PM                36 2011-03-14 20.40.49-2011-03-14 21.00.00.txt
               1 File(s)             36 bytes
               0 Dir(s)  204,289,437,696 bytes free
烟若柳尘 2024-11-09 07:48:26

在 Windows 上,文件名不能包含 :。这与空格无关(您通过将文件名用引号引起来正确解决了空格)。

因此,从变量中删除冒号(或将其替换为另一个有效字符);无论是在设置它们时还是直接在后面的行中:

echo Application Error Event Analysis > "%overall_timestamp_first::=% - %overall_timestamp_last::=%.doc"

File names cannot contain : on Windows. This has nothing to do with the spaces (which you correctly solved by enclosing the file name in quotes).

So remove the colons (or replace them by another, valid character) from your variables; either when setting them or directly in your later line:

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