I am trying to write a piece of batch file to output stuff into log file daily with \"date\" as their file name...
I reference someone\'s answer and get a piece of code as
\"
@ECHO OFF
FOR /F \"TOKENS=1,2,3 DELIMS= \" %%I IN (\'DATE /T\') DO SET FILENAME=%%I_%%J%%K.log
echo %FILENAME%
\"
But in this case I could only get a variable %fileName%
How do I insert things into this file as:
dir >> %fileName%
--------------------------------
I am trying to do stuff like
dir >> Mon_07/31/2006.log
------------------------------
thanks...
P.S. Sorry I cant type this in Chinese, I am at work.. :(
2006-08-01 03:01:28 · 1 個解答 · 發問者 瑤瑤 1 in 社會與文化 ➔ 語言
The code you get is wrong!
It lacks to consider that both / and \ are directory separator in MS-DOS (Windows' OS command is still named DOS 7.x or 8.x).
Therefore, the error message you get is caused by that DOS considers the you want to dir a file named 2006.log under a 2-layer sub-directory named Mon_07/31.
To correct that problem, add ",4", "/", "_" and %%K as following:
FOR /F "TOKENS=1,2,3,4 DELIMS=/ " %%I IN ('DATE /T') DO Set FileName=%%I_%%J_%%K_%%L.log
Then, your %filename% will be something like
Mon_07_31_2006.log
Now, you "SHOULD" use dir >> %FileName%
But I don't know where comes a "1" before >>
I will keep trying to solve that.
If you, anyone or I can solve that, please post in this discussion.
P.S. use it like
dir >> %FileName%
or
dir / w>> %FileName%
It adds a "1" before >> automatically!!
Which means that dir 1 instead of dir *.*
That's the reason why it still not works.
Good Luck. ^_^
2006-08-01 07:57:02 補充:
Though there is an unknown extra 1 before the >>, it seems that it works fine!!You should success. ^_^
2006-08-01 03:40:55 · answer #1 · answered by ? 7 · 0⤊ 0⤋