我有一个.BAT文件,我称之为:DxDiag.BAT 这是内容:
:: 24.07.2013
:: Dxdiag Miner 1.1 by me .
:: Feel free to redistribute and/or modify the file at will, but it'd be nice if you were to give the author credit.
:: Turn off echoing commands to the console, set colour to light green.
@echo off
Color 0A
echo Dxdiag Miner v1.1
:: Check for dxdiag.exe, in case not found go to Dxdiag_Not_Found.
echo Checking for dxdiag.exe...
if not exist %systemroot%\system32\dxdiag.exe GOTO Dxdiag_Not_Found
echo Dxdiag.exe found.
:: Execute dxdiag.exe, pass the path to the file.
echo Creating dxdiag file, please stand by...
%systemroot%\system32\dxdiag.exe /t %USERPROFILE%\AppData\Local\testing\testing\SF_24-07-13\dxdiag.txt
echo Dxdiag file created under the name of "dxdiag.txt" at %USERPROFILE%\Desktop
:: Open the newly created file.
%USERPROFILE%\Desktop\dxdiag.txt
exit
:Dxdiag_Not_Found
echo Dxdiag.exe was not found. Please contact support for further help.
pause
exit
第一个问题是我希望它直接在特定目录中创建文本文件:
%systemroot%\system32\dxdiag.exe /t %USERPROFILE%\AppData\Local\testing\testing\SF_24-07-13\dxdiag.txt
问题是现在最终的目录是:SF_24-07-13 但有时它会是另一个日期,例如目录将是:SF_28-07-13
那么如何在BAT文件中更改/设置它以找到每次正确的目录?
我想在c#中做的每个用户在windows中如果它的xp vista 7或8将点击一个按钮它将运行BAT文件并创建包含所有信息的dxdiag文本文件。
这就是我现在所做的,但它不起作用:
:: 13.08.2011
:: Dxdiag
:: Feel free to redistribute and/or modify the file at will, but it'd be nice if you were to give the author credit.
:: Turn off echoing commands to the console, set colour to light green.
@echo off
Color 0A
echo Dxdiag Miner v1.1
:: Check for dxdiag.exe, in case not found go to Dxdiag_Not_Found.
echo Checking for dxdiag.exe...
if not exist %systemroot%\system32\dxdiag.exe GOTO Dxdiag_Not_Found
echo Dxdiag.exe found.
:: Execute dxdiag.exe, pass the path to the file.
echo Creating dxdiag file, please stand by...
echo off
set today=%date:~7,2%-%date:~4,2%-%date:~10,4%
echo %today%
%systemroot%\system32\dxdiag.exe /t %USERPROFILE%\AppData\Local\Diagnostic_Tool_Blue_Screen\Diagnostic Tool Blue Screen\SF_today\dxdiag.txt
echo Dxdiag file created under the name of "dxdiag.txt" at %USERPROFILE%\Desktop
:: Open the newly created file.
%USERPROFILE%\Desktop\dxdiag.txt
exit
:Dxdiag_Not_Found
echo Dxdiag.exe was not found. Please contact support for further help.
pause
exit
我添加的部分是:
echo off
set today=%date:~7,2%-%date:~4,2%-%date:~10,4%
echo %today%
%systemroot%\system32\dxdiag.exe /t %USERPROFILE%\AppData\Local\Diagnostic_Tool_Blue_Screen\Diagnostic Tool Blue Screen\SF_today\dxdiag.txt
我做了SF_today也尝试过SF_%今天% 我之前添加SF_的原因是目录是这样的:
C:\Users\bout0_000\AppData\Local\Diagnostic_Tool_Blue_Screen\Diagnostic Tool Blue Screen\SF_24-07-13
我做错了什么?
答案 0 :(得分:0)
这是一个Windows批处理脚本问题,要获取日期,可以使用以下命令
echo %date%
这会将输出生成为 Wed 07/24/2013 ,将日期转换为您想要的格式,您可以使用
%date:~i,n%
其中i是子字符串的起始索引,n是要获取的字符数。例如%date:~10,4%将获得2013年(年份4位数)
完整代码
echo off
set today=%date:~7,2%-%date:~4,2%-%date:~10,4%
echo %today%
这将获得今天的日期字符串,输出为24-07-2013,然后您可以将此字符串插入到您的脚本中。