This topic has been archived. It cannot be replied.
-
工作学习 / IT技术讨论 / 有没有DOS 的大拿, 请教:在DOS Batch Program里面, %date%显示 '3/23/2005', 能不能转换成 20050323, 因为要输出一个'文件名_Date.txt" 的文件.
-1patrick(潜水中断);
2005-3-23
{115}
(#2198498@0)
-
给你Google了一个:
-xanada(㊣流水);
2005-3-23
(#2198574@0)
-
for /F "tokens=1-3 delims=/" %%A in ('date /T') do set dd=%%C%%A%%B
echo %dd%
-holdon(try again);
2005-3-23
(#2198611@0)
-
there are many ways...The most simple way is substring function, but it is system dependent.
echo %date%
if the output is " 03/23/2005 Wed" then
ren tmp.txt tem%date:~0,2%_%date:~3,2%_%date:~6,4%.txt
you will get a file named "tem03_23_2005.txt"
Note %date:~0,2%, this is the substring function, which gets 2 chars starting from 0 position.
-yuanzidan(原子弹);
2005-3-23
{338}
(#2198740@0)
-
这个办法好, 谢谢. :-)
-1patrick(潜水中断);
2005-3-24
(#2199880@0)
-
长痛不如短痛,我给你一个更好的招:使用Script, 例如Perl。这比DOS的Batch强无数倍。如果你经常需要使用命令行下的批处理作业的话,用了此类script后,你就再也不会用DOS的批处理了。到www.perl.com下载一个Perl for PC.
下面是例子batch.pl: 执行方式:perl batch.pl
use strict;
use POSIX qw(strftime);
my $file = "file.name.".strftime("%Y%m%d", localtime());
my $records;
$records = "This is a sample file\nThis is the second records\n";
print "The output file name is $file\n";
open(OUT, $file) or die "cannot open file $file\n";
print OUT $records;
close(OUT);
-unknown2me(行者);
2005-3-24
{406}
(#2199144@0)
-
如果你真有意,来看看Perl的简易中文教程。所有的都是免费的哦!
-unknown2me(行者);
2005-3-24
(#2199145@0)
-
这是两码事
-heian(黑暗㊣);
2005-3-24
(#2199149@0)
-
谢谢了,Perl 我会...不是还得装Perl吗? 只想在DOS下看看有没有办法, 就是一个小Log file. :-)
-1patrick(潜水中断);
2005-3-24
(#2199805@0)