Im trying to create a Bat(Batch) file but not working

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
chocolade
Posts: 10
Joined: 23 Jul 2013 23:38

Im trying to create a Bat(Batch) file but not working

#1 Post by chocolade » 23 Jul 2013 23:47

This is my script code inside the batch file:

Code: Select all

:: 13.08.2011
:: Dxdiag Miner 1.1 by Morrolan, made for #Minecrafthelp at EsperNet.
:: 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



Everything worked good untill i added the variable : today

Code: Select all

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



What i need is to create the dxdiag.txt file in this directory :

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

The problem is that sometimes the directory SF_24-07-13 will be change .
For example tommorow the directory will be :

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

Thats why i added the: today variable .
But when im running the bat file i cant find the dxdiag.txt file in this directory.
Before it was just :

%USERPROFILE%\Desktop

And i saw the file in the Desktop directory but now after the changes i did i cantsee the file its not created in the directory i wanted .

What did i do wrong ?

foxidrive
Expert
Posts: 6031
Joined: 10 Feb 2012 02:20

Re: Im trying to create a Bat(Batch) file but not working

#2 Post by foxidrive » 24 Jul 2013 01:57

dxdiag with /t at least doesn't accept path\filename or quoted terms. Tested in Win 8.

This should work:

Code: Select all

pushd "%USERPROFILE%\AppData\Local\Diagnostic_Tool_Blue_Screen\Diagnostic Tool Blue Screen\SF_%today%"
%systemroot%\system32\dxdiag.exe /t dxdiag.txt
popd

chocolade
Posts: 10
Joined: 23 Jul 2013 23:38

Re: Im trying to create a Bat(Batch) file but not working

#3 Post by chocolade » 24 Jul 2013 02:20

foxidrive i did this changed this lines :

Code: Select all

"%USERPROFILE%\AppData\Local\Diagnostic_Tool_Blue_Screen\Diagnostic Tool Blue Screen\SF_%today%"
%systemroot%\system32\dxdiag.exe /t dxdiag.txt


I also tried before to do it like this :

Code: Select all

pushd
"%USERPROFILE%\AppData\Local\Diagnostic_Tool_Blue_Screen\Diagnostic Tool Blue Screen\SF_%today%"
%systemroot%\system32\dxdiag.exe /t dxdiag.txt
popd


In both cases it didnt work in the first one im getting an error message while its creating the file :

Dxdiag Miner v1.1
Checking for dxdiag.exe...
Dxdiag.exe found.
Creating dxdiag file, please stand by...
24-07-2013
'"C:\Users\bout0_000\AppData\Local\Diagnostic_Tool_Blue_Screen\Diagnostic Tool B
lue Screen\SF_24-07-2013"' is not recognized as an internal or external command,

operable program or batch file.

foxidrive
Expert
Posts: 6031
Joined: 10 Feb 2012 02:20

Re: Im trying to create a Bat(Batch) file but not working

#4 Post by foxidrive » 24 Jul 2013 03:04

In the code I gave you PUSHD is followed by the path. You have it on a line by itself.

chocolade
Posts: 10
Joined: 23 Jul 2013 23:38

Re: Im trying to create a Bat(Batch) file but not working

#5 Post by chocolade » 24 Jul 2013 03:28

This is what i did now :

Code: Select all

pushd "%USERPROFILE%\AppData\Local\Diagnostic_Tool_Blue_Screen\Diagnostic Tool Blue Screen\SF_%today%"
%systemroot%\system32\dxdiag.exe /t dxdiag.txt popd


Once i added the popd in the end and next time i tried to add the popd in a new line:

Code: Select all

pushd "%USERPROFILE%\AppData\Local\Diagnostic_Tool_Blue_Screen\Diagnostic Tool Blue Screen\SF_%today%"
%systemroot%\system32\dxdiag.exe /t dxdiag.txt
popd


In both cases when running the bat file i see this : The system cannot find the path specified.

Dxdiag Miner v1.1
Checking for dxdiag.exe...
Dxdiag.exe found.
Creating dxdiag file, please stand by...
24-07-2013
The system cannot find the path specified.

foxidrive
Expert
Posts: 6031
Joined: 10 Feb 2012 02:20

Re: Im trying to create a Bat(Batch) file but not working

#6 Post by foxidrive » 24 Jul 2013 04:11

chocolade wrote:

Code: Select all

pushd "%USERPROFILE%\AppData\Local\Diagnostic_Tool_Blue_Screen\Diagnostic Tool Blue Screen\SF_%today%"
%systemroot%\system32\dxdiag.exe /t dxdiag.txt
popd


In both cases when running the bat file i see this : The system cannot find the path specified.


That is the correct syntax above - check the folder to see if it exists and see if there is a dxdiag.txt file in it.

And use this command because dxdiag.exe returns while the file is still being created:

Code: Select all

start /w "" %systemroot%\system32\dxdiag.exe /t dxdiag.txt 

chocolade
Posts: 10
Joined: 23 Jul 2013 23:38

Re: Im trying to create a Bat(Batch) file but not working

#7 Post by chocolade » 24 Jul 2013 05:29

The problem is something with the TODAY variable i tried to create .
I just created new empty bat file in notepad .
Inside i added :

Code: Select all

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_24-07-13\dxdiag.txt


And its working i see the new dxdiag.txt in the directory .
But once i changed the 24-07-13 to %today% its not working i didnt see any error messages but the file is not in the directory .

So something is wrong with the using with the today variable.
What could it be ?

I dont need the rest of the code for now as above only this code in my new bat file here .
I just cant figure out what is wrong with the today variable . Maybe the way i created the variable or maybe the way i try to use it as directory ?

chocolade
Posts: 10
Joined: 23 Jul 2013 23:38

Re: Im trying to create a Bat(Batch) file but not working

#8 Post by chocolade » 24 Jul 2013 05:38

Ok found the problem i think .
In the bat file in the new bat file i did:

Code: Select all

set today=%date:~7,2%-%date:~4,2%-%date:~10,4%
%systemroot%\system32\dxdiag.exe /t %USERPROFILE%\AppData\Local\Diagnostic_Tool_Blue_Screen\Diagnostic Tool Blue Screen\SF_24-07-13\dxdiag.txt


When i pause i see that the variable today is : 24-07-2013 but it should be 24-07-13
How can i change the variable format to be 24-07-13 and not 24-07-2013 ?

brinda
Posts: 78
Joined: 25 Apr 2012 23:51

Re: Im trying to create a Bat(Batch) file but not working

#9 Post by brinda » 24 Jul 2013 05:56

can put %date:~-2%

Code: Select all

set today=%date:~7,2%-%date:~4,2%-%date:~10,4%
set today=%date:~7,2%-%date:~4,2%-%date:~-2%


working

Code: Select all

D:\Documents\Downloads>set today=24-07-2013
D:\Documents\Downloads>set today=24-07-13

chocolade
Posts: 10
Joined: 23 Jul 2013 23:38

Re: Im trying to create a Bat(Batch) file but not working

#10 Post by chocolade » 24 Jul 2013 06:27

Working .

Thank you all.

Post Reply