-1

我有一个 .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_today我之前添加SF_的原因是目录是这样的:

C:\Users\bout0_000\AppData\Local\Diagnostic_Tool_Blue_Screen\Diagnostic Tool Blue Screen\SF_24-07-13

我究竟做错了什么 ?

4

1 回答 1

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,然后您可以将此字符串插入到您的脚本中。

于 2013-07-24T04:08:58.027 回答