Explore topic-wise InterviewSolutions in .

This section includes InterviewSolutions, each offering curated multiple-choice questions to sharpen your knowledge and support exam preparation. Choose a topic below to get started.

851.

Solve : batch script to align the columns in a text file.?

Answer»

Hello, Below is my problem:

The data in my file is like this:

      98869        0000390.00 QRP
      178411        0000015.00 QRP


I need it like the below:

        96782        0000015.00 QRP
      100266        0000015.00 QRP

Below is the code currently I am using:

echo off
if exist c:\Newfile.dat del c:\Newfile.dat
for /F "skip=1 delims=" %%a in (C:\test\Bonus_File_Export.txt) do call :Sub %%a
goto :eof

:Sub
echo        %1        %2 %3>>c:\test\Newfile.dat

how to enhance this code to make SURE that, when there is a 5 digit value shows up, it will be like the one I need.

Do let me know if any information is needed from my side. Any help is highly appreciated. Thank you.
We have a FORMAT function over on DosTips.com.
Let me know if you don't understand how to use it.
http://www.dostips.com/DtCodeCmdLib.php#Function.FormatYes Sir, I've gone through this link a while ago. A tried a BIT but my code failed with syntax errors as I was not using them properly. Could you please guide me with this? Quote from: ssis_sql_dev on JANUARY 07, 2015, 03:26:36 PM

Yes Sir, I've gone through this link a while ago. A tried a bit but my code failed with syntax errors as I was not using them properly. Could you please guide me with this?
So you tried using this function already?  Why didn't you ask for help on the Dostips.com forum if you couldn't get it too work? Code: [Select]echo off &setlocal enabledelayedexpansion
if exist Newfile.txt del Newfile.txt
for /F "tokens=1-3" %%G in (file.txt) do (
call :Format "[-6][-18][-4]" %%G %%H %%I
>>Newfile.txt echo !line!
)
goto :eof

:Format fmt str1 str2 ... -- outputs columns of strings right or left aligned
::                        -- fmt [in] - format string specifying column width and alignment, i.e. "[-10][10][10]"
:$created 20060101 :$changed 20091130 :$categories Echo
:$source http://www.dostips.com
SETLOCAL
set "fmt=%~1"
set "line="
set "spac=                                                     "
set "i=1"
for /f "tokens=1,2 delims=[" %%a in ('"echo..%fmt:]=&echo..%"') do (
    set /a i+=1
    call call set "subst=%%%%~%%i%%%spac%%%%%~%%i%%"
    if %%b0 GEQ 0 (call set "subst=%%subst:~0,%%b%%"
    ) ELSE        (call set "subst=%%subst:~%%b%%")
    call set "const=%%a"
    call set "line=%%line%%%%const:~1%%%%subst%%"
)
endlocal&set "line=%line%"

GOTO :EOF
output
Code: [Select]C:\BatchFiles\Format>type file.txt
96782        0000015.00 QRP
100266        0000015.00 QRP

C:\BatchFiles\Format>format_SSIS.bat

C:\BatchFiles\Format>type newfile.txt
 96782        0000015.00 QRP
100266        0000015.00 QRP

C:\BatchFiles\Format> Quote from: ssis_sql_dev on January 07, 2015, 02:15:14 PM
Hello, Below is my problem:

The data in my file is like this:

      98869        0000390.00 QRP
      178411        0000015.00 QRP


I need it like the below:

        96782        0000015.00 QRP
      100266        0000015.00 QRP


The numbers are different - is that part of the task?

Quote from: ssis_sql_dev on January 07, 2015, 02:15:14 PM
how to enhance this code to make sure that, when there is a 5 digit value shows up, it will be like the one I need.

What do you mean by this?  Will there be 4 digit numbers for example? 
The task is not clear from what you have written.
852.

Solve : Run a batch recursively?

Answer»

Hello,

I want to run x.bat AUTOMATICALLY and recursively in:

Code: [Select]C:\test
|   
+---folder1
|      x.bat
|       
+---folder2
|      x.bat
|       
+---folder3
.      x.bat
.
.----foldern
       x.bat
Can be sequentially and simultaneously, no matter

I have this:

Code: [Select]echo off
for /r /d %%x in ("*") do (
pushd "%%x"   
call "x.bat"
popd
)
pause
But only runs x.bat for folder1 in a loop for the times.

Thank you very much.Try this:
Code: [Select]for /f "delims=" %%A in ('dir /b /a:d') do "%%A\x.bat"
Lemonilla you NEED to use CALL. It ALSO will not launch the batch file in the ACTUAL directory - which is often required.

This should work:

Code: [Select]echo off
for /r %%a in (x.bat?) do (
pushd "%%~dpa"   
if exist "x.bat" call "x.bat"
popd
)
pause

853.

Solve : Compare xml files with same name in 2 differnt folders?

Answer» HI every1  ,

Can some1 help me with a batch code for the description below:

Quote
==>I have many xml files in two different folders.
==>Some xml files are present in both the folders which are the same with same file name.
==> i need the dissimilar xml files from both the folders  to be moved to a different new folder.
==>These dissimilar xml files should be moved to new folder only if they are found in any one of the two folders .
ANY SUGGESTIONS?

THANKS IN ADVANCE Replace the variable values with the names of the folders you wish to compare and the destination.  IT WILL NOT PROMPT WHEN OVERRIDING FILES, so be careful.

Code: [Select]echo off
setlocal EnableDelayedExpansion
set folder1=Folder1
set folder2=Folder2
set folder3=Diff

if not exist %folder3% md %folder3%
cd %folder1%
for /f "delims=" %%A in ('dir /b') do (
cd ..\%folder2%

cls
echo Processing File "%%A", Please Wait . . .

if not exist %%A (
cd ..\%folder1%
move %%A "..\%folder3%\%%A" >nul 2>&1
) else (
fc %%A "..\%folder1%\%%A" >nul 2>&1
if "!errorlevel!"=="1" (
move %%A "..\%folder3%\%folder2% - %%A" >nul 2>&1
move "..\%folder1%\%%A" "..\%folder3%\%folder1% - %%A" >nul 2>&1
)
)
cd ..\%folder1%
)

pause
Lemonilla Thanks a lot This code works perfectly fine for me 

Quote
But this code moves only files from folder1 which are not in folder2 after comparison to folder3 ,Can u SUGGEST a code which will move the files in folder2 to folder3 at the same time which are not in folder1,I mean to ask u to perform the move operation in both the folders at the same time which are not same..
Not sure where to quote is from, but this should work as well.  I have not tested this.
Code: [Select]echo off
setlocal EnableDelayedExpansion
set folder1=Folder1
set folder2=Folder2
set folder3=Diff

if not exist %folder3% md %folder3%
cd %folder1%
for /f "delims=" %%A in ('dir /b') do (
cd ..\%folder2%

cls
echo Processing File "%%A", Please Wait . . .

if not exist %%A (
cd ..\%folder1%
move %%A "..\%folder3%\%%A" >nul 2>&1
) else (
fc %%A "..\%folder1%\%%A" >nul 2>&1
if "!errorlevel!"=="1" (
move %%A "..\%folder3%\%folder2% - %%A" >nul 2>&1
move "..\%folder1%\%%A" "..\%folder3%\%folder1% - %%A" >nul 2>&1
)
)
cd ..\%folder1%
)
cd ..\%foldere%
for /f "delims=" %%A in ('dir /b') do (
cd ..\%folder1%

cls
echo Processing File "%%A", Please Wait . . .

if not exist %%A (
cd ..\%folder2%
move %%A "..\%folder3%\%%A" >nul 2>&1
) else (
fc %%A "..\%folder2%\%%A" >nul 2>&1
if "!errorlevel!"=="1" (
move %%A "..\%folder3%\%folder1% - %%A" >nul 2>&1
move "..\%folder2%\%%A" "..\%folder3%\%folder2% - %%A" >nul 2>&1
)
)
cd ..\%folder2%
)

pause

It does a second pass though the files to make sure that all the files in the other folder exist in the first.   As I said, I have not tested it as I am not at home.  Hopefully it's what he wanted.hi thanks lemonilla:-) i had already tried the same way as yo MENTIONED , but it dint work properly i guess , i ll TRY tomorrow in office and let yo no,. . . . thanks again . . . There was a spelling mistake, fixed it:

Code: [Select]echo off
setlocal EnableDelayedExpansion
set folder1=Folder1
set folder2=Folder2
set folder3=Diff

if not exist %folder3% md %folder3%
cd %folder1%
for /f "delims=" %%A in ('dir /b') do (
cd ..\%folder2%

cls
echo Processing File "%%A", Please Wait . . .

if not exist %%A (
cd ..\%folder1%
move %%A "..\%folder3%\%folder1% - %%A" >nul 2>&1
) else (
fc %%A "..\%folder1%\%%A" >nul 2>&1
if "!errorlevel!"=="1" (
move %%A "..\%folder3%\%folder2% - %%A" >nul 2>&1
move "..\%folder1%\%%A" "..\%folder3%\%folder1% - %%A" >nul 2>&1
)
)
cd ..\%folder1%
)
cd ..\%foldere%
for /f "delims=" %%A in ('dir /b') do (
cd ..\%folder1%

cls
echo Processing File "%%A", Please Wait . . .

if not exist %%A (
cd ..\%folder2%
move %%A "..\%folder3%\%folder2% - %%A" >nul 2>&1
) else (
fc %%A "..\%folder2%\%%A" >nul 2>&1
if "!errorlevel!"=="1" (
move %%A "..\%folder3%\%folder1% - %%A" >nul 2>&1
move "..\%folder2%\%%A" "..\%folder3%\%folder2% - %%A" >nul 2>&1
)
)
cd ..\%folder2%
)

pause


)
    cd ..\%folder1%
)
Quote
cd ..\%foldere%
for /f "delims=" %%A in ('dir /b') do (
    cd ..\%folder1%

In the above quoted code u have written it as "foldere" ??  "folder2" to be specified there

This code also wont move file names with spaces in their names i believe? Pls correct me if i am wrong..Fixed, and Fixed.

Code: [Select]echo off
setlocal EnableDelayedExpansion
set folder1=Folder1
set folder2=Folder2
set folder3=Diff

if not exist %folder3% md %folder3%
cd %folder1%
for /f "delims=" %%A in ('dir /b') do (
   cd ..\%folder2%

   cls
   echo Processing File "%%A", Please Wait . . .

   if not exist "%%A" (
      cd ..\%folder1%
      move "%%A" "..\%folder3%\%folder1% - %%A" >nul 2>&1
   ) else (
      fc "%%A" "..\%folder1%\%%A" >nul 2>&1
      if "!errorlevel!"=="1" (
         move "%%A" "..\%folder3%\%folder2% - %%A" >nul 2>&1
         move "..\%folder1%\%%A" "..\%folder3%\%folder1% - %%A" >nul 2>&1
      )
   )
   cd ..\%folder1%
)
cd ..\%folder2%
for /f "delims=" %%A in ('dir /b') do (
   cd ..\%folder1%

   cls
   echo Processing File "%%A", Please Wait . . .

   if not exist "%%A" (
      cd ..\%folder2%
      move "%%A" "..\%folder3%\%folder2% - %%A" >nul 2>&1
   ) else (
      fc "%%A" "..\%folder2%\%%A" >nul 2>&1
      if "!errorlevel!"=="1" (
         move "%%A" "..\%folder3%\%folder1% - %%A" >nul 2>&1
         move "..\%folder2%\%%A" "..\%folder3%\%folder2% - %%A" >nul 2>&1
      )
   )
   cd ..\%folder2%
)

pause

I think this should solve the task in the first post:

Code: [Select]echo off
set "a=c:\folder1"
set "b=c:\folder2"
set "c=c:\folder3"

md "%c%" 2>nul

cd /d "%a%" & for %%z in (*.xml) do if not exist "%b%\%%z" move "%%z" "%c%"
cd /d "%b%" & for %%z in (*.xml) do if not exist "%a%\%%z" move "%%z" "%c%"
pause
Quote from: foxidrive on June 09, 2014, 08:54:24 AM
I think this should solve the task in the first post:

Code: [Select]echo off
set "a=c:\folder1"
set "b=c:\folder2"
set "c=c:\folder3"

md "%c%" 2>nul

cd /d "%a%" & for %%z in (*.xml) do if not exist "%b%\%%z" move "%%z" "%c%"
cd /d "%b%" & for %%z in (*.xml) do if not exist "%a%\%%z" move "%%z" "%c%"
pause

Not quite though, It should also compare the two if they do exist, so you'd need something like else fc "%%Z" "%a%\%%Z" || move "%%z" "%c%\%%z" at the end of your cd lines Quote from: Lemonilla on June 09, 2014, 01:15:12 PM
Not quite though, It should also compare the two if they do exist

The task is to move files if they don't exist in both folders, right? Quote from: foxidrive on June 09, 2014, 07:56:23 PM
The task is to move files if they don't exist in both folders, right?
Quote
==>Some xml files are present in both the folders which are the same with same file name.
==> i need the dissimilar xml files from both the folders  to be moved to a different new folder.
So if they exist in both, compare the two and move them if they are different.  Thus you need to use 'fc'.Thanks Lemonilla and foxi :)U both have done the right way as u have quoted .... and have done it at right time... all the codes wud b useful... Quote from: Lemonilla on June 09, 2014, 09:12:34 PM
So if they exist in both, compare the two and move them if they are different.  Thus you need to use 'fc'.

No need for that - no mention was MADE about comparing files.  I think we have different interpretations of the task.

Quote from: foxidrive on June 10, 2014, 05:52:34 AM
No need for that - no mention was made about comparing files.  I think we have different interpretations of the task.
I looked at it again, and can see where we interpreted things differently.
854.

Solve : DOS For Loop with Incorrect Number of Tokens?

Answer»

I have a script which is passed only one parameter, I am issuing the _PARM as I see it being passed by some application for testing.  I am expecting a total of 6 PARAMETERS to be passed.  Now if for some reason if there is no sixth parameter, the "if" code for %%F DOES NOT GET executed, and it just drops through.  Any ideas how to address this?  I cannot used IF DEFINED, it does not work....  The quotes are required as shown in _PARM:

Code: [Select]SET _PARM=parm1 parm2 "file_renamed" "windows_path" "filename"
for /f "tokens=1-6* delims= " %%a in ("%_parm%") do (
    if "%%a"=="" (
       echo VAR1 missing
       goto :ShowUsage
    ) ELSE (
       SET VAR1=%%a
       echo VAR1 Defined: %VAR1%             >> %MAILLOG%
    )

    if "%%b"=="" (
       echo VAR2 missing
       goto :ShowUsage
    ) ELSE (
       echo VAR2 Defined: %VAR2%           >> %MAILLOG%
       SET VAR2=%%b
    )

    if "%%C"=="" (
       echo VAR3 missing
       goto :ShowUsage
    ) ELSE (
       SET VAR3=%%c
       echo VAR3 Defined: %VAR3%           >> %MAILLOG%
    )

    if "%%d"=="" (
       echo VAR4 missing
       goto :ShowUsage
    ) ELSE (
       SET VAR4=%%d
       echo VAR4 Defined: %VAR4%         >> %MAILLOG%
    )

    if "%%e"=="" (
       echo VAR5 missing
       goto :ShowUsage
    ) ELSE (
       SET VAR5=%%e
       echo VAR5 Defined: %VAR5%   >> %MAILLOG%
    )

    if "%%f"=="" (
       echo VAR6 missing
       goto :ShowUsage
    ) ELSE (
       SET VAR6=%%f
       echo VAR6 Defined: %VAR6%     >> %MAILLOG%
    )
)
...........  do some other stuff
You need DELAYED expansion to change/create a variable AND to use it within the loop.Thank you, issue resolved.

855.

Solve : Changing suffix of filename?

Answer»

down vote

favorite


 


I've got a file that GETS copied daily from one sql system to the another sql server for restore purposes. The file name contains the name of the sql backup ALONG with the current date/time. I would like to strip out the date/time and rename as follows:

Typical File copied daily: Server100_PRD_FULL_20140530_000850.bak 

--But not SURE how to rename the suffix that contains the date.

Would like to rename copied files as above to:SPDBSPSFS100_FS84PRD_FULL.BAK

Appreciate help.

Thanks
 See if this helps:

Code: [Select]echo off
set "file=Server100_PRD_FULL_20140530_000850.bak"
for /f "tokens=1-3 delims_=" %%a in ("%file%") do set "file=%%a_%%b_%%c.bak"
echo("%file%"

It depends on how you get your file - you've stated that you want to strip out the date_time and also that you want to GIVE it a different filename.

I'm not sure exectly what you are after.Thanks....one NOTE the file name changes daily ( as per date/time file created) so today would be:

Server100_PRD_FULL_20140530_000850.bak

tomorrow

Server100_PRD_FULL_20140531_000850.bak

ThanksIt is not clear what you want to do, and how you go about doing it.

Which drive, folder, is it on a network and do you need to log into the LAN?The script Foxi gave you is the base code to remove the date. Pretty sure you can extrapolate from there on how to rename your file from there.
856.

Solve : malware scanner script?

Answer»

i needed a quick an easy way to upload a script to download several AV software and run them mostly without user input. My scripting abilities are amature, but i can usually botch something together and make it work.  My script is below i am having an issue on the Line :JRT right after the call for key.vbs i need it to wait until JRT.exe to finish before moving onto anything else.  Then once JRT.exe is done move on thru the script automatically.    Feel FREE to offer anything to clean this up to work better. 

Thanks for your time
Neil

echo off
echo YOU WILL HAVE TO ALLOW A FEW PROMPTS FOR THE PROGRAM TO RUN
pause
echo THE PROGRAM MAY APPEAR TO BE DOING NOTHING DO NOT CLOSE IT, IT'S WORKING
PAUSE
echo IF IT ASKS TO REBOOT ANYWHERE SAY NO
pause
echo THIS COULD TAKE AROUND 30+ MINUTES TO FINISH
pause
cd progs
start /wait wget http://thisisudax.org/downloads/JRT.exe
start /wait wget http://download.bleepingcomputer.com/grinler/rkill.scr
start /wait wget http://downloads.malwarebytes.org/file/chameleon/
start /wait wget http://media.kaspersky.com/utilities/VirusUtilities/EN/tdsskiller.exe
start /wait 7za e mbam-chameleon-*.zip

GOTO rkill

:rkill
start /wait rkill.scr -s
goto JRT

:JRT
start JRT.exe
call key.vbs
Taskkill /F /IM notepad.exe
goto tds

:tds
start /wait tdsskiller.exe -silent
goto mbam

:mbam
start firefox.scr
ping 192.0.2.2 -n 1 -w 180000 > nul
Taskkill /F /IM firefox.scr
Taskkill /F /IM mbam-killer.exe
cd C:\Program Files\Malwarebytes' Anti-Malware
start /wait mbam.exe /quickscan

goto END

:ENDTwo options.
See if JRT.exe will respect the /WAIT option with the START command.
Don't use the START command when starting JRT.exe.  Batch is sequential process.  If you just supply the name of the executable to run it will wait for that program to finish running before it moves onto the next command in the batch file.It does respect the /wait option the problem is i have to run a separate WSH SendKey script to make JRT.exe run without user input (it has a press any key to continue).  So then i basically need some way of waiting for JRT.exe to finish before moving forward with the script.  Like some kind of loop to wait for the process to finish then go forward. Anyone ?if JRT.exe terminates on exit you can use something like
Code: [Select]:l
tasklist | find "JRT.exe" || goto :l

or if you don't want the line to show up,
Code: [Select]:l
for /f "delims=" %%A in ('tasklist ^| find "JRT.exe"') do goto :l
It sounds like it doesn't terminate when it finishes so he is trying to use SendKeys in his vbscript to end the program when it is done.  Problem is how would we KNOW when it is really done.  I think you would have to MONITOR the cpu usage of the process.

857.

Solve : To search and send "Interpretation (Interpret) Passed" Exactly from Html files?

Answer»

Hi Friends,
 I want a batch code to  search a string exactly like "Interpretation (Interpret) Passed" from a set of HTML files locatind in folders and subfolders and send the files which contain that string to another FOLDER. similarly i wanna even search "Interpretation (Interpret) Failed" and "Interpretation (Interpret) Incomplete" from html files and send to specified folder.
i tried with the code mentioned below:

ECHO OFF
for /f "delims=" %%f in ('findstr /S/M /C:"Interpretation (Interpret) Failed" *.html') do copy "%%f" C:\\failedreports
for /f "delims=" %%f in ('findstr /S/M /C:"Interpretation (Interpret) Incomplete" *.html') do copy "%%f" C:\incompletereports
for /f "delims=" %%f in ('findstr /S/M "Interpretation (Interpret) Passed" *.html') do copy "%%f" C:\Passed

But this code doesn't work .... Any Help Pls??
 Its very urgent Pls help me out
Thanks in advance....Some1 pls help me out with this batch code pls,....

I am really in need .......

Thank you in advance.....When you request some help in future - post once in a new thread, don't post PMs asking for help, and when you do get some help - come back and let the people here know if it worked or not.  That'd be good.


Code: [Select]echo off
for /r %%a in (*.html) do findstr /C:"Interpretation (Interpret) Failed"     "%%a" >nul && copy "%%a" "C:\failedreports"
for /r %%a in (*.html) do findstr /C:"Interpretation (Interpret) Incomplete" "%%a" >nul && copy "%%a" "C:\incompletereports"
for /r %%a in (*.html) do findstr /C:"Interpretation (Interpret) Passed"     "%%a" >nul && copy "%%a" "C:\Passed"
Post your question ONCE and in your own thread.And stop PM'ing people for answers Please... Quote from: patio on May 28, 2014, 12:08:51 PM

And stop PM'ing people for answers Please...
+1
or maybe that is +2 or +3 already.Starting to sound alot more like Homework to me..... Sorry all for the troble and thanks for the help... will let you people no if its working in a while since my server is down..Hi Foxi,

The code that you suggested DOESNT work . Its not copying anything, Any other suggestions ?

Thanks in advance.Place pause as the last line.

Are there any messages on the screen?
I tried as yo you said Foxi and also i get  many lines as mentioned below on the screen ...

FINDSTR: Cannot open %


You pasted it into a CMD window, right? Quote from: Venkat on May 29, 2014, 04:06:48 AM
I tried as yo you said Foxi and also i get  many lines as mentioned below on the screen ...

FINDSTR: Cannot open %
I don't get that error when I run it.He's DONE his own editing....

Please post what you have so far... Quote from: patio on May 29, 2014, 07:26:47 AM
He's done his own editing....

Please post what you have so far...
Another +1 for you!
858.

Solve : How to make batch file do a random choice??

Answer» HEY, I'm trying to make a batch file that can randomly choose between TWO scripts.
For example, the first option can be 'echo you win', and the second can be 'echo you lose'.
Is it possible for the batch file to randomly choose on of them?
Thanks,
Whitebeard1See if this is the SORT of thing you need.

Code: [Select]echo off
:loop
set /a num=%random% %% 2
if %num% equ 0 (echo you win) else (echo you lose)
pause
goto :loop
Thanks a BUNCH! Exactly what I need.
859.

Solve : Creating a text-based game .bat?

Answer»

Hello all! I am new to these forums, and I thought this would be a great introduction for both parties. I am creating a text-based adventure game as a .bat file, just for fun, and would like to share. I am looking for constructive criticism and advice, as I hope that this little project gives me a more advanced knowledge of .bat scripting.

Here's what I have so far:

ECHO off
title Adventure Game

set manRoomVal= 0

:manRoom
echo;
echo Your BASIC controls are:
echo Enter L for Left
echo Enter R for Right
echo Enter F for Forward
echo Enter B for Backward
echo Enter S for Search
echo Enter H for Hear/Listen
if %manRoomVal% EQU 1 goto mainRoom
if %manRoomVal% EQU 0 goto introduction

:introduction
set manRoomVal= 1
echo;
echo You are standing in a cold hallway, wielding a gun. You're sweating and you don't recall much.
echo There is a door infront of you, a desk to the left, a dark opening to a CORRIDOR behind you, and nothing to your right. What do you do?
set mainRoomLeftVal= 0
set mainRoomSearchVal= 0
set mainRoomHearVal= 0
set mainRoomRightVal= 0
goto mainRoom

:mainRoom
echo;
set /p directionChoice= What will you do?
if %directionChoice% EQU L goto mainRoomLeft
if %directionChoice% EQU R goto mainRoomRight
if %directionChoice% EQU F goto mainRoomForward
if %directionChoice% EQU B goto mainRoomBackward
if %directionChoice% EQU S goto mainRoomSearch
if %directionChoice% EQU H goto mainRoomHear
if %directionChoice% EQU man goto manRoom
pause


:rejectionRoom
echo;
echo You've already done this!
goto mainRoom

:mainRoomLeft
if %mainRoomLeftVal% EQU 1 goto rejectionRoom
if %mainRoomLeftVal% EQU 0 echo;
echo You turn left and move towards the desk. You look it over. There some papers on it, and perhaps something in the drawer...
echo;
set /p deskChoice= (S)earch it or (L)eave it and turn back the way you were facing before?
if %deskChoice% EQU S goto deskSearch
if %deskChoice% EQU L goto mainRoom

:deskSearch
echo;
echo You examine the paperwork on the TOP of the desk more closely. It's all very official looking; long writing files with drab words.
echo You can't seem to focus on everything it says..
echo You open the drawer hoping something jumps out of at you in there.
echo There's another gun in there, as well as a set of keys, and a pack of cigarettes.
echo You pocket it all and then move back to the spot you were standing at before.
echo;
set mainRoomLeftVal= 1
goto mainRoom

:mainRoomRight
if %mainRoomRightVal% EQU 1 goto rejectionRoom
if %mainRoomRIghtVal% EQU 0 echo;
echo You turn to your right to move but there is nothing there besides a dull wall.
set mainRoomRightVal= 1
goto mainRoom

:mainRoomSearch
if %mainRoomSearchVal% EQU 1 goto rejectionRoom
if %mainRoomSearchVal% EQU 0 echo;
echo Frantically you try to look around the room and process everything. Your heart is beating so fast and your pupils are dancing with each beat.
echo You notice the walls are cold gray tile, kind of modern looking. There is a fading flourescent light fixture about your head.
echo There's nothing on the floor except garbage.
echo There's blood on your clothes.. Why is there blood on your clothes?
echo;
set mainRoomSearchVal= 1
goto mainRoom

:mainRoomHear
if %mainRoomHearVal% EQU 1 goto rejectionRoom
if %mainRoomHearVal% EQU 0 echo;
echo You try to listen to the noises of the room. It is difficult. Your heart is beating fast and heavily. You also hear yourself breathing.
echo A break in your body's noises let's you hear something deep and familiar in the distance.. Metal on metal.. tunneling through..
echo That's train noise.
echo;
set mainRoomHearVal= 1
goto mainRoom

:mainRoomBackward
echo backward
pause

:mainRoomForward
echo forward
pause

The end, so far. Please tell me what you all think and offer any advice/tips you can!
-Tim
I see you didn't take any of our advice on the dostips.com forum because I do not see any code changes.
http://www.dostips.com/forum/viewtopic.php?f=3&t=5648

860.

Solve : find replace a string with new line?

Answer»

Hi All,


I have a windows directory with files   file_835_2014_JULDAY_XXX.txt

C:\0001_krishna\file_835_2014_JULDAY_001.txt
C:\0001_krishna\file_835_2014_JULDAY_002.txt
C:\0001_krishna\file_835_2014_JULDAY_003.txt  and so on.

Now in each of this file, I have text as follows without linefeed (New line).
ISA*......~GS*.....~ST*....~BPR.....

I would like to have a BATCH file , which would convert all these files with line feed (new line)  for every TILDA (~)
ISA*......~
GS*.....~
ST*....~
BPR.....

Can you please help me , so that when I run that batch script, all the files in my folder C:\0001_krishna\*.txt  will convert to above new line format.

Thank you
KrishnaTest this on a folder with sample files inside:

Code: [SELECT]echo off
for %%a in (*.txt) do (
type "%%a"|repl "~" "~\r\n" x >"%%a.tmp"
)
del *.txt
ren *.tmp *.
echo done
pause

This uses a helper batch file called `repl.bat` (by dbenham) - download from:  https://www.dropbox.com/s/qidqwztmetbvklt/repl.bat

Place `repl.bat` in the same folder as the batch file or in a folder that is on the path.

861.

Solve : Batch code to find and replace strings in xml files and move them to new folder?

Answer» HI i need a BATCH CODE to find and replace the below two tasks(Task_RunOwt,Task_RunDbdIo)  if found with  another task(Task_RunGenericIo) in around 1500 xml files..is it possible???    The changed files should be moved to different folder after replacing the strings...

old tasks to be replaced:
1) Quote
<task>
      <uid>1T1I</uid>
      <name>Task_RunOwt</name>
      <params>
         <OrcIp>$ORC1IP$</OrcIp>
         <OrcUsername>$ORC1USERNAME$</OrcUsername>
         <OrcPassword>$ORC1PASSWORD$</OrcPassword>
         <VolumeNames>$VOLUME1NAME$,$VOLUME2NAME$</VolumeNames>
         <WriteToRawVolume>TRUE</WriteToRawVolume>
         <IoToolOptions>-b512 -n4194304 -o0 -t256 -c1 -r0 -l0 -w100 -s10 -p0 -g1 -v0 -d1 -z'' -q64 -f'' -i'' -U0</IoToolOptions>
      </params>
      <pass>1T3G</pass>
      <fail>abortfail</fail>
      <incomplete>abortfail</incomplete>
   </task>
2) Quote
<task>
      <uid>1T1I</uid>
      <name>Task_RunDbdIo</name>
      <params>
         <OrcIp>$ORC1IP$</OrcIp>
         <OrcUsername>$ORC1USERNAME$</OrcUsername>
         <OrcPassword>$ORC1PASSWORD$</OrcPassword>
         <VolumeNames>$VOLUME1NAME$,$VOLUME2NAME$</VolumeNames>
         <IOToolOptions>--queue 64 --seed --io_profile --trace STAT</IOToolOptions>
      </params>
      <pass>1T3G</pass>
      <fail>abortfail</fail>
      <incomplete>abortfail</incomplete>
   </task>
NEW Task Which has to be substituted in place of above two tasks if found in the xml files:
Quote
<task>
      <uid>1T1I</uid>
      <name>Task_RunGenericIo</name>
      <params>
         <GroupName>$GROUP1NAME$</GroupName>
         <ClusterName>$CLUSTER1NAME$</ClusterName>          
         <WriteToRawVolumeOrFile>raw</WriteToRawVolumeOrFile>
         <Client>
            <OrcIp>$ORC1IP$</OrcIp>
            <OrcUsername>$ORC1USERNAME$</OrcUsername>
            <OrcPassword>$ORC1PASSWORD$</OrcPassword>
            <Volume>
               <Names>$VOLUME1NAME$,$VOLUME2NAME$</Names>
            </Volume>
         </Client>
      </params>
      <pass>1T3G</pass>
      <fail>abortfail</fail>
      <incomplete>abortfail</incomplete>
   </task>

Points to be noted:
Quote
*uid,pass,fail and incomplete tags and its content in the xml code should remain unchanged,only the code in between the uid and pass tags should be replaced with following
*In RunOwt task,When WriteToRawVolume is mentioned true, in RungenericIo,WriteToRawVolumeOrFile should be= raw
*In RunOwt task,When WriteToRawVolume is mentioned FALSE, in RungenericIo,WriteToRawVolumeOrFile should be= file
*When RunDbdio task is found ,in RungenericIo,WriteToRawVolumeOrFile should always be =raw
*if only volume1name exists than only volume1name should be present(but not volume2name).
*IoToolOptions in above tasks is not required in RunGenericIo task.
*basically the xml code logic should be same after replacement


It would be of great help if this works out...Thanks in advance...Does it have to be in batch? I know repl.bat uses java script, and might be what you are looking for.
https://www.dropbox.com/s/qidqwztmetbvklt/repl.bat

You'll have to ask Squashman or Foxidrive for more info on it, as I haven't used it much. Quote from: Venkat on June 28, 2014, 04:36:52 PM
Hi i need a BATCH CODE to find and replace the below two tasks(Task_RunOwt,Task_RunDbdIo)  if found with  another task(Task_RunGenericIo) in around 1500 xml files.

I have a few questions:

Will any xml file contain both Task_RunOwt and Task_RunDbdIo tasks?
Will any xml file contain more than one of the tasks?
Are all 1500 xml files in a single folder?
Hi Lemonilla,
Quote
Does it have to be in batch?

It is not mandatory to be in a batch , Any code is fine which makes the replacement of 2 tasks task in xml file to RunGenericIo Task.i ll check that link which u sent and let u no if it works.Hi Foxi,

Quote
Will any xml file contain both Task_RunOwt and Task_RunDbdIo tasks?
Will any xml file contain more than one of the tasks?
Are all 1500 xml files in a single folder?

1)I dont think any Xml file contains both the tasks Task_RunOwt and Task_RunDbdIo in a single XML File , But even if thats the scenario ,replacement has to be done with Task_RunGenericIo since other two tasks are deprecated.
2)Yup every Xml file has many different tasks which has Task_RunOwt and Task_RunDbdIo repeated no. of times or  only once.
3)All 1500 xml files are not in single folder,they are in different folders of same directory.
4)Task_RunOwt and Task_RunDbdIo tasks are deprecated in the tool i work with, so i need them get replaced with Task_RunGenericIo which is used for writing data in volumes of Client Orcs mentioned..


Quote
https://www.dropbox.com/s/qidqwztmetbvklt/repl.bat

You'll have to ask Squashman or Foxidrive for more info on it, as I haven't used it much.

Will this code help me out Foxi/SquashMan??? Is so pls tell me..
862.

Solve : help installing gnu package linux in windows / DOS?

Answer»

Hi, I'm TRYING to install the package "myfitter" on windows, the DOCUMENTATION instructions are for linux i think? so if someone knows what the equivalent dos commands are thatd be super awesome.
To install i'm supposed to put:

cd myfitter-2.0
./configure --prefix=myprefix
make
make install

"myprefix" is the directory where i want to install it (I'm using mingw with codeblocks, so WOULD this be mingw, codeblocks, or the codeblocks project?)
THANKS for any help!!http://stackoverflow.com/questions/24274268/command-prompt-installing-c-package-on-windows-8-myfitter
Also posted on SO.

863.

Solve : Batch file find/replace text (allow user to enter data)?

Answer»

I am trying to create a batch file that will replace text within a text file.

I would like the batch file to prompt me to enter the text to search for, and enter what to replace that text with. If there are multiple instances of the text, I would like it to also replace all instances.

For example.... Say I wanted to replace the WORD "start" with the word "stop"
The batch file would prompt me to enter text to find, I would enter the word "start" and then it would prompt me to enter the text to replace the word "start" with and I would enter the word "stop"

And if the word "start" occurred 40 times in the text file, I would like it to replace all instances with the word "stop"


I would really APPRECIATE it if someone could HELP me.


Thank you!This uses a helper batch file called `repl.bat` (by dbenham) - download from:  https://www.dropbox.com/s/qidqwztmetbvklt/repl.bat

Place `repl.bat` in the same folder as the batch file or in a folder that is on the path.

It should be robust and also swift for large files.


Code: [Select]echo off
set /p "WORDA=Enter the word to find: "
set /p "WORDB=Enter the word to replace: "
type "file.txt" | repl "%wordA%" "%wordB%" LI >"newfile.txt"
This works perfectly.


Thank you so much!

864.

Solve : DOS - Find multiple strings in the same line?

Answer»

I have a file which I want to extract the LINE only if it contains two strings, any ideas how to do this?  If my file contains the following strings as an example:

Code: [Select]line1:    Testing the BROWN fox jumped over a dog
line2:    Testing the brown fox and the dog cannot read
line3:    Testing2 the dog cannot read a book
line4:    Testing3 the brown fox jumped over a dog house
I just want the string that would contain the string Testing [must be first string of the line] and dog on the same line, but only the first occurrence.  And how about if I just want the last occurrence?It can be done with a couple of findstr and find filters.

The exact code depends on the actual task. 
I'll just explain here that we often see example text and create some code, and it doesn't work because the actual text had aspects that MADE it require different code.

It helps enormously to see the actual task, and if there is private data then those characters can be replaced without changing the length or makeup of the words, or the spacing.OK, I'll bite. As was mentioned the regular expression (RegEx) feature of FINDSTR can be used if all you want to do is flag lines that meet your criteria. If you're looking to actually extract the matched patterns, you;ll need a more powerful RegEx engine (Powershell or VBScript are both installed on Win 7 machines)

I put your posted sample in a file called RegEx.txt. Note: line 1 has a trailing space which is accounted for in the RegEx.

Contents of RegEx.txt:

Code: [Select]Testing the brown fox jumped over a dog
Testing the brown fox and the dog cannot read
Testing2 the dog cannot read a book
Testing3 the brown fox jumped over a dog house

From the NT command line you can run:

Code: [Select]findstr /i /r /C:"^testing.* dog " regex.txt

As it turns out, all the lines meet your requirements. The Testing pattern is at the beginning of each line and the dog pattern is both the first and last occurrence found in each line. Real data would have been more of a challenge, however the RegEx engine found in batch language is well suited for the data provided.

It's a dog's life.  Thank you, I was going about it the wrong way... I was trying to do it in multiple steps...

865.

Solve : Variable outside of the for loop?

Answer»

I am trying to use the variable outside of the For loop. The echo inside the loop GIVES the result as expected. it is not working when i echo the variable outside of the loop. below is the script. Please let me know what am MISSING. THANK you!

Code: [Select]SETLOCAL ENABLEDELAYEDEXPANSION
SET x=0
FOR /f "tokens=*" %%a in ('dir "%INPATH%*_Out.txt" /b') DO (
SET /a x+=1& SET /a cnt+=1& SET Fname%x%=%%a& SET FDATE%x%=!Fname%x%:~0,8!
ECHO %x% !cnt! !Fname%x%! !Date%x%!
)

set z=3
ECHO !FDate%z%!Take out this line and try the code you have shown:

Code: [Select]set z=3
Copy what you see on the console into a reply.ECHO is on.0  20140609215426_Out.txt 20140609
0  20140610215426_Out.txt 20140610
0  20140614215426_Out.txt 20140614
0  20140617215426_Out.txt 20140617

modified the below line, now it seems fine. Thank you!


Code: [Select]SET /a x=!x!+1&
I missed that it was z instead of the x variable.

All occurrences  of %x% within the loop have to be !x! if you are changing the variable and using it within the loop.

866.

Solve : Fast countdown timer for a batch game... ??

Answer»

Hey guys! I was FINALLY able to get the save and load to function PROPERLY. Now, I need help making a quick countdown timer (quick as in wait time is no more than a minute(I'd prefer to have it in milliseconds, or something smaller than a second.))for when the player's character is mining. The wait time would decrease as they level up. Any thoughts?A plain BATCH solution - change the value of the delay variable

Code: [SELECT]echo off
echo %time%
SET delay=1500000
for /L %%a in (1,1,%delay%) do rem
echo %time%
pause

867.

Solve : How Create Formatted Output?

Answer»

How does one created a formatted output in DOS, that is, maintain the spaces and columns?  Not even sure if it is possible.An example of what you are trying to do and what code you have tried so far would probably help us help you.He's gonna GET an A+ in class at this rate... I discovered what the issue is, it seems to be a notepad thing.  Notepad is nicely formatting the alignment of the "echo" so I would think it is properly aligned.  Now when I tried to paste the code here, it is all misaligned.  So I guess my question is, is there a way to output a formatted report without using echo statements in DOS or some third-party product or writing a program to produce what I want?BB code tags should RETAIN any formatting but without seeing what your existing code is or what your input looks like and what you want the output to look like then this really becomes an exercise in futility.

When people ask for information to help you with a task it would be helpful to provide that information. If they have to ask two or three times then they are just not going to help you.3 unrelated questions in 2 days = homework...Not homework at all, I wish I was that young to go back to school :-)Well I am tapping out on this thread.  Someone else can take over. Quote from: et_phonehome_2 on June 12, 2014, 06:50:39 PM

Not homework at all, I wish I was that young to go back to school :-)

You're not old enough to know a proportional font from a monospaced font.I always want things to line up...  The new code will line things up...

Original code:
Code: [Select]echo [USAGE]: %~1 arg1 arg2 arg3 arg4 arg5 arg6                            >> %MAILLOG%
echo          arg1 : IDF               : %IDF%                            >> %MAILLOG%
echo          arg2 : PARTNER           : %PART%                            >> %MAILLOG%
echo          arg3 : PARM              : %PARM%                            >> %MAILLOG%
echo          arg4 : FNAME             : %FNAME%                    >> %MAILLOG%
echo          arg5 : FILENAME          : %FILENAME%                        >> %MAILLOG%
echo          arg6 : FACTION [Y^|N]    : %FACTION%                         >> %MAILLOG%

New Code:
Code: [Select]echo [USAGE]: %~1 arg1 arg2 arg3 arg4 arg5 arg6                            >> %MAILLOG%
echo          arg1 : IDF.....................: %IDF%                    >> %MAILLOG%
echo          arg2 : PARTNER............: %PART%                    >> %MAILLOG%
echo          arg3 : PARM.................: %PARM%                    >> %MAILLOG%
echo          arg4 : FNAME...............: %FNAME%                    >> %MAILLOG%
echo          arg5 : FILENAME...........: %FILENAME%                       >> %MAILLOG%
echo          arg6 : FACTION [Y^|N]....: %FACTION%                         >> %MAILLOG%
868.

Solve : Batch game save and load codes.?

Answer»

Hey guys!
I have created this game which is turning out to have amazing mechanics!
That is, except the saving and loading codes. Saving is easy, but the loading is the part that puts me off.
here they are, can any one tell me why they don't work? Besides the third one. I didn't change that yet.


:menu
cls
echo 1. start new game
echo 2. load
echo 3. exit

set /p start=%enter%

if %start% equ 1 GOTO preset
if %start% equ 2 goto whichload
if %start% equ 3 goto exit
goto menu


:exit
exit


:preset
cls
set /a playerhealth =100
set /a wholehealth =100
set /a attack =20
set /a Magicattack =15
set /a gold =10
set /a weapon =none
set /a wand =none
set /a defense =20
set /a exptill =300
set /a exp =0
set /a level =1
set /a HPpotions =0
set /a ordswo =0
set /a logswo =0
set /a firswo =0
set /a deadswo =0
set /a woodwand =0
set /a majwand =0
set /a maswand =0
set /a la =0
set /a ia =0
set /a ea =0
set /a da =0
set /a wizexp =5
set /a wizkn =0
set /a mana =50
set /a wholemana =50
set /a batexp =0
set /a accuracy =15
set /a evasion =15
set /a ordsworde =0
set /a longsworde =0
set /a firesworde =0
set /a deathsworde =0
set /a woodenwande =0
set /a majesticwande =0
set /a masterwande =0
cls
echo.
echo What is your name?

set /p name=%enter%

goto welcome


:whichsave
cls
echo.
echo Would you like to save in file 1,2 or 3?
echo.
echo (Type 1 or 2 or 3 or EXIT)
echo.
echo.
if EXIST LoBGameSave1.BAT echo File 1. Has data.
if NOT EXIST LoBGameSave1.bat echo File 1. Has no data.
if EXIST LoBGameSave2.bat echo File 2. Has data.
if NOT EXIST LoBGameSave2.bat echo File 2. Has no data.
if EXIST LoBGameSave3.bat echo File 3. Has data.
if NOT EXIST LoBGameSave3.bat echo File 3. Has no data.
echo.
echo.

set /p savean=%enter%

if %savean% equ 1 goto overwritestate1
if %savean% equ 2 goto overwritestate2
if %savean% equ 3 goto overwritestate3
if %savean% equ EXIT goto beginning
goto whichsave


:overwritestate1
cls
echo.
if EXIST LoBGameSave1.bat echo There is ALREADY save data.
if NOT EXIST LoBGameSave1.bat echo There is no save data.
echo.
echo Would you still like to save? Y/N/EXIT

set /p savean2=%enter%

if %savean2% equ Y goto save1
if %savean2% equ N goto whichsave
if %savean2% equ EXIT goto beginning
goto overwritestate1


:overwritestate2
cls
echo.
if EXIST LoBGameSave2.bat echo There is already save data.
if NOT EXIST LoBGameSave2.bat echo There is no save data.
echo.
echo Would you still like to save? Y/N/EXIT

set /p savean3=%enter%

if %savean3% equ Y goto save2
if %savean3% equ N goto whichsave
if %savean3% equ EXIT goto beginning
goto overwritestate2


:overwritestate3
cls
echo.
if EXIST LoBGameSave2.bat echo There is already save data.
if NOT EXIST LoBGameSave2.bat echo There is no save data.
echo.
echo Would you still like to save? Y/N/EXIT

set /p savean3=%enter%

if %savean3% equ Y goto save3
if %savean3% equ N goto whichsave
if %savean3% equ EXIT goto beginning
goto overwritestate3


:save1
(echo set /a name =%name%) >> LoBGameSave1.bat
(echo set /a playerhealth =%playerhealth%) >> LoBGameSave1.bat
(echo set /a wholehealth =%wholehealth) >> LoBGameSave1.bat
(echo set /a attack =%attack%) >> LoBGameSave1.bat
(echo set /a Magicattack =%Magicattack%) >> LoBGameSave1.bat
(echo set /a gold =%gold%) >> LoBGameSave1.bat
(echo set /a weapon =%weapon%) >> LoBGameSave1.bat
(echo set /a wand =%wand%) >> LoBGameSave1.bat
(echo set /a defense =%defense%) >> LoBGameSave1.bat
(echo set /a exptill =%exptill%) >> LoBGameSave1.bat
(echo set /a exp =%exp%) >> LoBGameSave1.bat
(echo set /a level =%level%) >> LoBGameSave1.bat
(echo set /a HPpotions =%HPpotions%) >> LoBGameSave1.bat
(echo set /a ordswo =%ordswo%) >> LoBGameSave1.bat
(echo set /a logswo =%logswo%) >> LoBGameSave1.bat
(echo set /a firswo =%firswo%) >> LoBGameSave1.bat
(echo set /a deadswo =%deadswo%) >> LoBGameSave1.bat
(echo set /a woodwand =%woodwand%) >> LoBGameSave1.bat
(echo set /a majwand =%majwand%) >> LoBGameSave1.bat
(echo set /a maswand =%maswand%) >> LoBGameSave1.bat
(echo set /a la =%la%) >> LoBGameSave1.bat
(echo set /a ia =%ia%) >> LoBGameSave1.bat
(echo set /a ea =%ea%) >> LoBGameSave1.bat
(echo set /a da =%da%) >> LoBGameSave1.bat
(echo set /a wizexp =%wizexp%) >> LoBGameSave1.bat
(echo set /a wizkn =%wizkn%) >> LoBGameSave1.bat
(echo set /a mana =%mana%) >> LoBGameSave1.bat
(echo set /a wholemana =%wholemana%) >> LoBGameSave1.bat
(echo set /a batexp =%batexp%) >> LoBGameSave1.bat
(echo set /a evasion =%evasion%) >> LoBGameSave1.bat
(echo set /a ordsworde =%ordsworde%) >> LoBGameSave1.bat
(echo set /a longsworde =%longsworde%) >> LoBGameSave1.bat
(echo set /a firesworde =%firesworde%) >> LoBGameSave1.bat
(echo set /a deathsworde =%ordsworde%) >> LoBGameSave1.bat
(echo set /a woodenwande =%woodenwande%) >> LoBGameSave1.bat
(echo set /a majesticwande =%majesticwande%) >> LoBGameSave1.bat
(echo set /a masterwande =%masterwande%) >> LoBGameSave1.bat
echo.
echo Game Saved!
pause
goto menu


:save2
(echo set /a name =%name%) >> LoBGameSave2.bat
(echo set /a playerhealth =%playerhealth%) >> LoBGameSave2.bat
(echo set /a wholehealth =%wholehealth) >> LoBGameSave2.bat
(echo set /a attack =%attack%) >> LoBGameSave2.bat
(echo set /a Magicattack =%Magicattack%) >> LoBGameSave2.bat
(echo set /a gold =%gold%) >> LoBGameSave2.bat
(echo set /a weapon =%weapon%) >> LoBGameSave2.bat
(echo set /a wand =%wand%) >> LoBGameSave2.bat
(echo set /a defense =%defense%) >> LoBGameSave2.bat
(echo set /a exptill =%exptill%) >> LoBGameSave2.bat
(echo set /a exp =%exp%) >> LoBGameSave2.bat
(echo set /a level =%level%) >> LoBGameSave2.bat
(echo set /a HPpotions =%HPpotions%) >> LoBGameSave2.bat
(echo set /a ordswo =%ordswo%) >> LoBGameSave2.bat
(echo set /a logswo =%logswo%) >> LoBGameSave2.bat
(echo set /a firswo =%firswo%) >> LoBGameSave2.bat
(echo set /a deadswo =%deadswo%) >> LoBGameSave2.bat
(echo set /a woodwand =%woodwand%) >> LoBGameSave2.bat
(echo set /a majwand =%majwand%) >> LoBGameSave2.bat
(echo set /a maswand =%maswand%) >> LoBGameSave2.bat
(echo set /a la =%la%) >> LoBGameSave2.bat
(echo set /a ia =%ia%) >> LoBGameSave2.bat
(echo set /a ea =%ea%) >> LoBGameSave2.bat
(echo set /a da =%da%) >> LoBGameSave2.bat
(echo set /a wizexp =%wizexp%) >> LoBGameSave2.bat
(echo set /a wizkn =%wizkn%) >> LoBGameSave2.bat
(echo set /a mana =%mana%) >> LoBGameSave2.bat
(echo set /a wholemana =%wholemana%) >> LoBGameSave2.bat
(echo set /a batexp =%batexp%) >> LoBGameSave2.bat
(echo set /a evasion =%evasion%) >> LoBGameSave2.bat
(echo set /a ordsworde =%ordsworde%) >> LoBGameSave2.bat
(echo set /a longsworde =%longsworde%) >> LoBGameSave2.bat
(echo set /a firesworde =%firesworde%) >> LoBGameSave2.bat
(echo set /a deathsworde =%ordsworde%) >> LoBGameSave2.bat
(echo set /a woodenwande =%woodenwande%) >> LoBGameSave2.bat
(echo set /a majesticwande =%majesticwande%) >> LoBGameSave2.bat
(echo set /a masterwande =%masterwande%) >> LoBGameSave2.bat
echo.
echo Game Saved!
pause
goto menu


:save3
(echo name =%name%) >> LoBGameSave3.bat
(echo playerhealth =%playerhealth%) >> LoBGameSave3.bat
(echo wholehealth =%wholehealth) >> LoBGameSave3.bat
(echo attack =%attack%) >> LoBGameSave3.bat
(echo Magicattack =%Magicattack%) >> LoBGameSave3.bat
(echo gold =%gold%) >> LoBGameSave3.bat
(echo weapon =%weapon%) >> LoBGameSave3.bat
(echo wand =%wand%) >> LoBGameSave3.bat
(echo defense =%defense%) >> LoBGameSave3.bat
(echo exptill =%exptill%) >> LoBGameSave3.bat
(echo exp =%exp%) >> LoBGameSave3.bat
(echo level =%level%) >> LoBGameSave3.bat
(echo HPpotions =%HPpotions%) >> LoBGameSave3.bat
(echo ordswo =%ordswo%) >> LoBGameSave3.bat
(echo logswo =%logswo%) >> LoBGameSave3.bat
(echo firswo =%firswo%) >> LoBGameSave3.bat
(echo deadswo =%deadswo%) >> LoBGameSave3.bat
(echo woodwand =%woodwand%) >> LoBGameSave3.bat
(echo majwand =%majwand%) >> LoBGameSave3.bat
(echo maswand =%maswand%) >> LoBGameSave3.bat
(echo la =%la%) >> LoBGameSave3.bat
(echo ia =%ia%) >> LoBGameSave3.bat
(echo ea =%ea%) >> LoBGameSave3.bat
(echo da =%da%) >> LoBGameSave3.bat
(echo wizexp =%wizexp%) >> LoBGameSave3.bat
(echo wizkn =%wizkn%) >> LoBGameSave3.bat
(echo mana =%mana%) >> LoBGameSave3.bat
(echo wholemana =%wholemana%) >> LoBGameSave3.bat
(echo batexp =%batexp%) >> LoBGameSave3.bat
(echo evasion =%evasion%) >> LoBGameSave3.bat
(echo ordsworde =%ordsworde%) >> LoBGameSave3.bat
(echo longsworde =%longsworde%) >> LoBGameSave3.bat
(echo firesworde =%firesworde%) >> LoBGameSave3.bat
(echo deathsworde =%ordsworde%) >> LoBGameSave3.bat
(echo woodenwande =%woodenwande%) >> LoBGameSave3.bat
(echo majesticwande =%majesticwande%) >> LoBGameSave3.bat
(echo masterwande =%masterwande%) >> LoBGameSave3.bat
echo.
echo Game Saved!
pause
goto menu


:whichload
cls
echo.
echo Would you like to load in file 1,2 or 3?
echo.
echo (Type 1 or 2 or 3 or EXIT)
echo.
echo.
if EXIST LoBGameSave1.bat echo File 1. Has data.
if NOT EXIST LoBGameSave1.bat echo File 1. Has no data.
if EXIST LoBGameSave2.bat echo File 2. Has data.
if NOT EXIST LoBGameSave2.bat echo File 2. Has no data.
if EXIST LoBGameSave3.bat echo File 3. Has data.
if NOT EXIST LoBGameSave3.bat echo File 3. Has no data.
echo.
echo.

set /p loadans1=%enter%

if %loadans1% equ 1 goto sureload1
if %loadans1% equ 2 goto sureload2
if %loadans1% equ 3 goto sureload3
goto whichload


:sureload1
if NOT EXIST LoBGameSave1.bat goto Nodata
cls
echo.
if EXIST LoBGameSave1.bat echo Load File 1? Y/N/EXIT
echo

set /p loadans2=%enter%

if %loadans2% Y goto load1
if %loadans2% N goto whichload
if %loadans2% EXIT goto menu
goto sureload1


:sureload2
if NOT EXIST LoBGameSave2.bat goto Nodata
cls
echo.
if EXIST LoBGameSave2.bat echo Load File 2? Y/N/EXIT
echo

set /p loadans3=%enter%

if %loadans3% Y goto load2
if %loadans3% N goto whichload
if %loadans3% EXIT goto menu
goto sureload2


:sureload3
if NOT EXIST LoBGameSave1.bat goto Nodata
cls
echo.
if EXIST LoBGameSave3.bat echo Load File 3? Y/N/EXIT
echo

set /p loadans4=%enter%

if %loadans4% Y goto load3
if %loadans4% N goto whichload
if %loadans4% EXIT goto menu
goto sureload1


:Nodata
cls
echo.
echo There is not data in that file!
echo.
pause
goto whichload


:load1
cls
for /f %%a in (LoBGameSave1.bat) do set %%a
echo.
echo Game Loaded!
pause
goto beginning


:load2
cls
for /f %%a in (LoBGameSave2.bat) do set %%a
echo.
echo Game Loaded!
pause
goto beginning


:load3
cls
for /f %%a in (LoBGameSave3.bat) do set %%a
echo.
echo Game Loaded!
pause
goto beginningNo need to Double Post...

I've removed your other one.1.) when you defined your VARIABLES, you use this: set /a Magicattack =15 which defines the variable %Magicattack % not %Magicattack%.  This could be causing some of your issues.  Oh, and you don't need the /a, that is used for arithmetic.

2.) Not sure how you are saving your game, but I usually use set >save1.txt. Then to load, you just go for /f "delims=" %%A in (save1.txt) do set %%A.  This will redefine all of your variables to what they were when you saved.  Be careful though, if you change an environment variable such as path between loads It will override those changes.

3.) I would RECOMMEND setting a variable for the save you are going to load from, and reduce the number of functions you have.
Code: (Example) [Select]:load
cls
for /f %%a in (LoBGameSave%Load_Num%.bat) do set %%a
echo.
echo Game Loaded!
pause
goto beginning
Quote from: Lemonilla on June 22, 2014, 07:41:36 AM

1.) when you defined your variables, you use this: set /a Magicattack =15 which defines the variable %Magicattack % not %Magicattack%.

Lemonilla, you will be surprised to find that set /a var =15 doesn't behave the same as set var =15
The code you've shown will work just fine and not introduce a space.

Thanks guys, but I found a different method which works consistently. \\m// (-_-) Quote from: Batch_gamer on June 23, 2014, 03:33:54 PM
Thanks guys, but I found a different method which works consistently. \\m// (-_-)


Pray tell us what it was... Quote from: patio on June 23, 2014, 04:18:26 PM

Pray tell us what it was...
You dont like passive aggressive responses.  Batch_gamer I have been writing a game and was wandering what was the way you figured out how to save the game?
Quote from: shiverbob on June 29, 2014, 09:41:57 AM
Batch_gamer I have been writing a game and was wandering what was the way you figured out how to save the game?

If you are holding all of your information in variables, I use:
set >save1.txt
and then to load I use:
For /f "delims=" %%A in (save1.txt) do set %%A

Also, next time either read through the whole thread, or make a new one. Quote from: Lemonilla on June 22, 2014, 07:41:36 AM
2.) Not sure how you are saving your game, but I usually use set >save1.txt. Then to load, you just go for /f "delims=" %%A in (save1.txt) do set %%A.  This will redefine all of your variables to what they were when you saved.  Be careful though, if you change an environment variable such as path between loads It will override those changes.

I did and that method didn't work and I was wandering what the way he found...

How are you holding the data? And what type of stuff do you want to carry over?  Seems to work fine for me.
Code: [Select]
C:\windows\system32>t:

T:\>set a=7

T:\>set b=17

T:\>set >log

T:\>
Code: [Select]
C:\windows\system32>set
AGSDESKTOPJAVA=C:\Program Files (x86)\ArcGIS\Desktop10.2\
ALLUSERSPROFILE=C:\ProgramData
APPDATA=C:\Users\Lemonilla\AppData\Roaming
asl.log=Destination=file
CommonProgramFiles=C:\Program Files (x86)\Common Files
CommonProgramFiles(x86)=C:\Program Files (x86)\Common Files
CommonProgramW6432=C:\Program Files\Common Files
COMPUTERNAME=LEMON
ComSpec=C:\Windows\system32\cmd.exe
FP_NO_HOST_CHECK=NO
HOMEDRIVE=C:
HOMEPATH=\Users\Lemonilla
LOCALAPPDATA=C:\Users\Lemonilla\AppData\Local
LOGONSERVER=\\LEMON
LUA_DEV=C:\Program Files (x86)\Lua\5.1
LUA_PATH=;;C:\Program Files (x86)\Lua\5.1\lua\?.luac
NUMBER_OF_PROCESSORS=4
OS=Windows_NT
PATHEXT=.COM;.EXE;.BAT;.CMD;.VBS;.VBE;.JS;.JSE;.WSF;.WSH;.MSC;.wlua;.lexe
PROCESSOR_ARCHITECTURE=x86
PROCESSOR_ARCHITEW6432=AMD64
PROCESSOR_IDENTIFIER=Intel64 Family 6 Model 58 Stepping 9, GenuineIntel
PROCESSOR_LEVEL=6
PROCESSOR_REVISION=3a09
ProgramData=C:\ProgramData
ProgramFiles=C:\Program Files (x86)
ProgramFiles(x86)=C:\Program Files (x86)
ProgramW6432=C:\Program Files
PROMPT=$P$G
PSModulePath=C:\Windows\system32\WindowsPowerShell\v1.0\Modules\
PUBLIC=C:\Users\Public
SESSIONNAME=Console
SystemDrive=C:
SystemRoot=C:\Windows
TEMP=C:\Users\LEMONI~1\AppData\Local\Temp
TMP=C:\Users\LEMONI~1\AppData\Local\Temp
USERDOMAIN=Lemon
USERNAME=Lemonilla
USERPROFILE=C:\Users\Lemonilla
VS120COMNTOOLS=C:\Program Files (x86)\Microsoft Visual Studio 12.0\Common7\Tools
\
windir=C:\Windows
windows_tracing_flags=3
windows_tracing_logfile=C:\BVTBin\Tests\installpackage\csilogfile.log

C:\windows\system32>t:

T:\>for /f "delims=" %A in (log) do set %A

T:\>set a=7

T:\>set AGSDESKTOPJAVA=C:\Program Files (x86)\ArcGIS\Desktop10.2\

T:\>set ALLUSERSPROFILE=C:\ProgramData

T:\>set APPDATA=C:\Users\Lemonilla\AppData\Roaming

T:\>set asl.log=Destination=file

T:\>set b=17

T:\>set CommonProgramFiles=C:\Program Files (x86)\Common Files

T:\>set CommonProgramFiles(x86)=C:\Program Files (x86)\Common Files

T:\>set CommonProgramW6432=C:\Program Files\Common Files

T:\>set COMPUTERNAME=LEMON

T:\>set ComSpec=C:\Windows\system32\cmd.exe

T:\>set FP_NO_HOST_CHECK=NO

T:\>set HOMEDRIVE=C:

T:\>set HOMEPATH=\Users\Lemonilla

T:\>set LOCALAPPDATA=C:\Users\Lemonilla\AppData\Local

T:\>set LOGONSERVER=\\LEMON

T:\>set LUA_DEV=C:\Program Files (x86)\Lua\5.1

T:\>set LUA_PATH=;;C:\Program Files (x86)\Lua\5.1\lua\?.luac

T:\>set NUMBER_OF_PROCESSORS=4

T:\>set OS=Windows_NT

T:\>set PATHEXT=.COM;.EXE;.BAT;.CMD;.VBS;.VBE;.JS;.JSE;.WSF;.WSH;.MSC;.wlua;.lex
e

T:\>set PROCESSOR_ARCHITECTURE=x86

T:\>set PROCESSOR_ARCHITEW6432=AMD64

T:\>set PROCESSOR_IDENTIFIER=Intel64 Family 6 Model 58 Stepping 9, GenuineIntel


T:\>set PROCESSOR_LEVEL=6

T:\>set PROCESSOR_REVISION=3a09

T:\>set ProgramData=C:\ProgramData

T:\>set ProgramFiles=C:\Program Files (x86)

T:\>set ProgramFiles(x86)=C:\Program Files (x86)

T:\>set ProgramW6432=C:\Program Files

T:\>set PROMPT=$P$G

T:\>set PSModulePath=C:\Windows\system32\WindowsPowerShell\v1.0\Modules\

T:\>set PUBLIC=C:\Users\Public

T:\>set SESSIONNAME=Console

T:\>set SystemDrive=C:

T:\>set SystemRoot=C:\Windows

T:\>set TEMP=C:\Users\LEMONI~1\AppData\Local\Temp

T:\>set TMP=C:\Users\LEMONI~1\AppData\Local\Temp

T:\>set USERDOMAIN=Lemon

T:\>set USERNAME=Lemonilla

T:\>set USERPROFILE=C:\Users\Lemonilla

T:\>set VS120COMNTOOLS=C:\Program Files (x86)\Microsoft Visual Studio 12.0\Commo
n7\Tools\

T:\>set windir=C:\Windows

T:\>set windows_tracing_flags=3

T:\>set windows_tracing_logfile=C:\BVTBin\Tests\installpackage\csilogfile.log

T:\>set
a=7
AGSDESKTOPJAVA=C:\Program Files (x86)\ArcGIS\Desktop10.2\
ALLUSERSPROFILE=C:\ProgramData
APPDATA=C:\Users\Lemonilla\AppData\Roaming
asl.log=Destination=file
b=17
CommonProgramFiles=C:\Program Files (x86)\Common Files
CommonProgramFiles(x86)=C:\Program Files (x86)\Common Files
CommonProgramW6432=C:\Program Files\Common Files
COMPUTERNAME=LEMON
ComSpec=C:\Windows\system32\cmd.exe
FP_NO_HOST_CHECK=NO
HOMEDRIVE=C:
HOMEPATH=\Users\Lemonilla
LOCALAPPDATA=C:\Users\Lemonilla\AppData\Local
LOGONSERVER=\\LEMON
LUA_DEV=C:\Program Files (x86)\Lua\5.1
LUA_PATH=;;C:\Program Files (x86)\Lua\5.1\lua\?.luac
NUMBER_OF_PROCESSORS=4
OS=Windows_NT
PATHEXT=.COM;.EXE;.BAT;.CMD;.VBS;.VBE;.JS;.JSE;.WSF;.WSH;.MSC;.wlua;.lexe
PROCESSOR_ARCHITECTURE=x86
PROCESSOR_ARCHITEW6432=AMD64
PROCESSOR_IDENTIFIER=Intel64 Family 6 Model 58 Stepping 9, GenuineIntel
PROCESSOR_LEVEL=6
PROCESSOR_REVISION=3a09
ProgramData=C:\ProgramData
ProgramFiles=C:\Program Files (x86)
ProgramFiles(x86)=C:\Program Files (x86)
ProgramW6432=C:\Program Files
PROMPT=$P$G
PSModulePath=C:\Windows\system32\WindowsPowerShell\v1.0\Modules\
PUBLIC=C:\Users\Public
SESSIONNAME=Console
SystemDrive=C:
SystemRoot=C:\Windows
TEMP=C:\Users\LEMONI~1\AppData\Local\Temp
TMP=C:\Users\LEMONI~1\AppData\Local\Temp
USERDOMAIN=Lemon
USERNAME=Lemonilla
USERPROFILE=C:\Users\Lemonilla
VS120COMNTOOLS=C:\Program Files (x86)\Microsoft Visual Studio 12.0\Common7\Tools
\
windir=C:\Windows
windows_tracing_flags=3
windows_tracing_logfile=C:\BVTBin\Tests\installpackage\csilogfile.log

T:\>

I have try a txt a dat a bat and it is about 6 virables that will be changed by buying stuff in game
But there is some words and that number will change
And the issue is not saving it loading
(I have know idea what dat is)
Fine you want a new thread you will get one

Can we see the files? It could be that it isn't writing it properly, or in the wrong place.

Try surrounding %%A in quotes like this: for /f "delims=" %%A in (save1.txt) do set "%%A"
That should help if there are spaces.Yea if you can figure a way to do that with a computer without internet
I am using a tablet
Quote from: shiverbob on June 30, 2014, 01:30:55 PM
Yea if you can figure a way to do that with a computer without internet
I am using a tablet
You are still able to connect here...run the above on a connected PC and see if it works.
869.

Solve : Space bar is permanently active?

Answer»

Hi,
I have a big problem and have no clue how to solve it.

Alright, so I restored my old Pentium II PC, installed Windows 98 on it and everything works great.
HOWEVER, when I reboot in MS-DOS and run any game, space bar is constantly active, like it's being pressed all the time. The keyboard is fine, because it works in Windows and DOS, just not in games. It is a normal PS/2 keyboard.

This is really weird... If someone can help me solve this, I'd be eternally grateful!Do you have another keyboard to swap this one out with?

ALSO odd that Windows and DOS are happy with it and its only when running DOS games that it becomes a problem.

I had a problem a ways back with a multifeatured PS2 keyboard and DOS where the Macro key kept acting up. I swapped it out with a normal 104 key keyboard and the problem was solved so that I could play Wolfenstein 3D. This was on an old Gateway 2000 486 DX2 66Mhz desktop computer that I was running Windows 95 on back around 1997.


BTW your system specs state Pentium II 533Mhz.....the fastest Pentium II I was aware of was the 450Mhz. The Pentium III's were 533Mhz. Is this a typo and really a Pentium III 533 or is this a Pentium II 333 etc?Thanks for quick reply.
I just tried switching keyboards, even plugged USB keyboard (yeah, motherboard has USB support).
However, the problem remained the same.
These are all normal keyboards, no special buttons or anything like that. It's really strange, it works in DOS, hence I can navigate to folders I want, but as soon as I run some game, space is literally locked.
Could there be some config file I should look at?The game(s) have yet to be mentioned...There use to be some annoying virus's back in the day that were TSR's that would cause people to want to throw their computers out the 2nd story window.

I'd run a scan on this system from Windows 98 to make sure everything is clean. If its a virus its an old one and probably a Windows 98 supported antivirus would pick up on it pretty quickly on the 20GB HDD with definitions from 2001 etc as for the virus if there is one is probably from almost 10 years or longer earlier when more people were on DOS.

Back 20+ years ago I got hit with some viruses as part of the shareware and otherware 720k and 1.44MB floppies that were shared among the 10 to 15 year old sneaker network computer geeks that I hung out with in the late 1980s early 1990s before the internet made everything so much more available for download etc. Back then sneaker network had 2 meanings the most common being a network of data that you walk around to computers, but also that we had to sneak the floppies into school to use them on the school computers and the panic button was turning the monitor off quickly and looking over the shoulder of a friend next to you as if your really helping them with their homework and then the teacher would leave and turn the CRT monitor back on and get back to playing the original Duke Nukem, Commander Keen, or Wolfenstein 3D, or some apogee shareware game etc. Quote from: patio on July 10, 2014, 03:49:16 PM

The game(s) have yet to be mentioned...

Well, one of them is Volfied.



After I run it, this intro screen disappears quickly as if I was pressing the space bar. When I start the game, (you should press space to cut these fields in the game), I can cut them freely without pressing the space bar. Also, when I press ESC to exit, I must keep pressing it really quickly a lot of times, because it skips the intro and SHOWS me the main main of the game.
Same happens in other games.

Quote from: DaveLembke on July 10, 2014, 03:52:02 PM
There use to be some annoying virus's back in the day that were TSR's that would cause people to want to throw their computers out the 2nd story window.

I'd run a scan on this system from Windows 98 to make sure everything is clean. If its a virus its an old one and probably a Windows 98 supported antivirus would pick up on it pretty quickly on the 20GB HDD with definitions from 2001 etc as for the virus if there is one is probably from almost 10 years or longer earlier when more people were on DOS.

Back 20+ years ago I got hit with some viruses as part of the shareware and otherware 720k and 1.44MB floppies that were shared among the 10 to 15 year old sneaker network computer geeks that I hung out with in the late 1980s early 1990s before the internet made everything so much more available for download etc.

I just formated my HDD and installed everything fresh.
Checking if it has some viruses is good idea, though. (Who knows what was on all these CD's and floppies)

Past few days I was messing with my sound card drivers, broke system 3 times already. Finally I found good drivers, set everything and now this!
I hope my Retro Gaming PC can be fully functional, because nothing beats original hardware. Quote
Checking if it has some viruses is good idea, though. (Who knows what was on all these CD's and floppies)

The last time I got bit by a DOS virus it was because I introduced a bunch of unknown content floppies from a yard sale computer I bought in which the seller sold the 286 computer with about 200 floppies and I was popping them in 1 by 1 and performing a DIR to see what was there and then if I saw anything interesting for EXE's I'd run them to see what they were etc. And if it was a cool game like Digger etc, I'd save it to my 320MB Connor HDD in a directory for DOS games etc.

When I got so far into the pile and then eventually the DIR info was showing strange sizes and random ascii characters like ♦♥♣ etc where Directory info should be, i figured I had a bad disk and went on to the other. Then the other did the same and so I put in a prior disk that worked ok and that also did the same. I then used a floppy drive cleaner with the alcohol and ran that to clean it and tried again and still same issue. Swapped out the floppy drive thinking it was messed up somehow. Same results with a known good drive. I then made the mistake of taking the floppy disk to another system I had and it started doing same thing on that one.

Nothing like unknowingly spreading a virus like fire among disks and systems. Now I had 2 infected systems and a pile of before problem happened disks and the unknown ones.

Full format and reinstall of OS for both systems and then instead of introducting the floppies to an unprotected system with no antivirus running I brought them over to my newest system at the time that had an antivirus on it and scanned through the small pile I had and they were clean and then when I got to the known trouble floppy disks, it immediately detected and told me what virus it had and I was able to clean them. I then continued to go through my entire collection of floppies to make sure the virus was killed off. What a Pain that was!!!!   The virus also corrupted some files on the floppies and so some data loss happened.   The good thing is that I had a backup on floppies of the DOS game collection I had, but then had to copy the 30+ disks back to the freshly clean installed HDD.DaveLembke
I completely understand you. These kind of problems made me switch to Linux. Back in the day (around 2000) I installed on this exact machine (see my specs for more info) Red Hat Linux 7.0 and everything worked great. After a month or so, I managed to set my modem as well! What a happiness that was. However, there were no my DOS games! So I constantly switched between Windows and Linux, just because of gaming, lol.
Few months ago, after I remembered having this PC, I installed Debian GNU/Linux 7 (prior to this there was Windows XP installed, which ran horribly) and I even managed to make USB WI-FI card working on this machine. Though this was perfectly usable machine, I still wanted my native DOS Box.

Wish Microsoft developed it's OS's more UNIX-like, hopefully these kind of problems wouldn't exist.

Anyway, I'll try installing Anti-Virus tomorrow on this machine and let you know how it went through. Quote from: georgiy on July 10, 2014, 04:14:13 PM
Well, one of them is Volfied.

This is an emulator by the look of it.
Does the problem occur in other games, like Doom and Duke Nukem that don't run in an emulator? Quote from: foxidrive on July 10, 2014, 08:08:10 PM
This is an emulator by the look of it.
What makes you say that?Eureka! I have found it.

So I reformatted my HDD yet again and installed Windows 98 SE this time. I loaded the game on HDD and rebooted in DOS. And everything worked, space bar wasn't "jammed". Then I installed Anti-Virus, graphic card and sound card drivers. I rebooted again in DOS and keyboard was malfunctioning again. I returned in Windows and disabled sound card drivers completely. Rebooted again in DOS and everything worked. So then I became suspicious and re-enabled sound card drivers, but disabled only Gameport Joystick.  It turned out that was the problem. I have no Joystick connected to my sound card, so that might be it, or the port itself might be damaged. Whatever it was, now it is working perfectly.



Thanks everyone for constructive discussion. Mystery solved! Quote from: DaveLembke on July 10, 2014, 03:21:24 PM
BTW your system specs state Pentium II 533Mhz.....the fastest Pentium II I was aware of was the 450Mhz. The Pentium III's were 533Mhz. Is this a typo and really a Pentium III 533 or is this a Pentium II 333 etc?

Oops, lol!
I mistyped it... twice!

Yes, it is Pentium III!
870.

Solve : [Batch script] How to locate an .ini file with a name which starts with "nsc"?

Answer»
My script:

Code: [Select]echo off
for %%f in ('dir /s /b H:\nsc*') do (
     set file=%%f
     set type=%file:~-3%
     if "%type%"=="ini"  echo good&%file% >> H:\allfinding.txt
)
WHY the cut string doesn't work??

as in the attachment implies, the code works seperately but not in a file batch?

can somebody tell me why???

or any solution for finding the path of a file called "nsc*.ini" in C:\, behind several folder perhaps,

thank you!!!


[recovering disk SPACE, attachment deleted by admin]If you want to set and use variables inside a bracket structure you need delayed expansion and use exclamation marks (!) instead of percent signs (%) when you expand them.

1. Study the parts in red

echo off
setlocal enabledelayedxpansion
for %%f in ('dir /s /b H:\nsc*') do (
     set file=%%f
     set type=!file:~-3!
     if "!type!"=="ini"  echo good&!file! >> H:\allfinding.txt
)

2. THIS IS IMPORTANT: what is the ampersand (&) doing here? Please explain what you think it will do.

Quote
good&%file%

Did you mean good%file% .... ? I assume in the next example you want to concatenate the string good and the file name variable.

3. You don't really need the intermediate variables (file and type). You can get the file extension directly like this

if %%f is a filename with extension, %%~xf is just the extension (with dot). Type FOR /? at the prompt to find out about the ~ variable modifiers.

echo off
for %%f in ('dir /s /b H:\nsc*') do (
     if "%%~xf"==".ini"  echo good%%f >> H:\allfinding.txt
)

In fact it will all go on one line

echo off
for %%f in ('dir /s /b H:\nsc*') do if "%%~xf"==".ini" echo good%%f >> H:\allfinding.txt

Finally, the script as it stands will ignore files whose extension is .INI or InI or .Ini or .iNi UNLESS you make the IF test case insenstive with the /i switch.

for %%f in ('dir /s /b H:\nsc*') do if /i "%%~xf"==".ini" echo good%%f >> H:\allfinding.txt

Anyhow why don't you just do this?

dir /s /b H:\nsc*.ini >> H:\allfinding.txt

Wow...that's what is said in a 2hour lecture  Quote from: shiverbob on July 09, 2014, 01:53:39 PM
Wow...that's what is said in a 2hour lecture 

No, a 1 minute brief explanation.
Quote from: mangolzy on July 09, 2014, 09:17:28 AM
or any solution for finding the path of a file called "nsc*.ini" in C:\

If the file is in C:\ or a folder under it, why does your script look in H:\ .... ?
Very glad with this reply so effective,

i am really a new hand, i try this to avoid some repetitive work.

1. once a variable is used twice, it should be !XXX!   ?

2. oh  that just my imagination of combine the string &...so it will be printed directly in fact

3. thank you for the improvement, but i have to find out all the file qualified, and make some modification in them, so it will be a simple batch... i think...


i suddenly found out a fact that you are the one who help me with the replacement of configuration file ...

u r really an expert!!

so what i am doing now is to find out the path of the file i am going to modify,

Code: [Select]echo off
setlocal Enabledelayedexpansion
set name=10.23.96.46
for /f "tokens=1* delims=:" %%a in ( ' findstr /n /r "^" "nsc.ini" ' ) do (
   set var=%%b
   set var=!var:10.23.96.98=%name%!
   echo !var!>>newnsc.ini
)
endlocal
of cause, it does the change as planned...yeah,, it still has the problem of blank line, it will put out 10.23.96.98=10.23.96.46 when come across a blank line, is it possible to improve this??

thank u very much!!

btw, how can you be so familiar with all these? Quote from: mangolzy on July 09, 2014, 03:08:16 PM
btw, how can you be so familiar with all these?
Practice makes perfect.
Quote from: shiverbob on July 09, 2014, 01:53:39 PM
Wow...that's what is said in a 2hour lecture 
I hope not, or I'll be really bored in class.Hello,

I still have a problem, with this command line,

Code: [Select]for %f in (dir /s /b H:\nsc*) do if /i "%~xf"==".ini" echo good%f >> H:\allfinding.txt

why it ignore those files in  a subfolder??

I mean with dir /s /b H:\nsc* itself, we have

Code: [Select]H:\nscini1019551.docx
H:\nsc.ini
H:\nscini101951151.docx
H:\NSClient++ REFERENCE Manual.pdf
H:\nsclient.ini
H:\nscnew.ini
H:\nsc.vbs
H:\nsc.exe
H:\nsclient.bat
H:\nscre.vbs
H:\nscre.exe
H:\nsclientpp.vbs
H:\nsclientpp.exe
H:\NSClient.txt
H:\NSC
H:\nscpplist.txt
H:\nsc.log
H:\nscfind.txt
H:\Script\nsc.ini
H:\Script\nsclient.ini
H:\Script\nsc.vbs
H:\Script\nsc.txt
H:\NSC\nsclient.ini
H:\NSC\nscnew.ini
H:\NSC\nsc.ini
H:\success_server_tse\nscpplist.txt
H:\success_server_tse\nsclient.bat


but with the for sentence, i got only
Code: [Select]goodH:\nsc.ini
goodH:\nsclient.ini
goodH:\nscnew.ini
 

I know it's a simple question ; but i have no experience at all..................

Thank you allTry this:

Code: [Select]dir /s /b /a-d h:\nsc* |findstr /i "\.ini$" >h:\nsc-ini-files.txt
and if you only want .ini files then this will work as well:

Code: [Select]dir /s /b /a-d h:\nsc*.ini >h:\nsc-ini-files.txt Quote from: foxidrive on July 10, 2014, 05:38:36 AM
Try this:

Code: [Select]dir /s /b /a-d h:\nsc* |findstr /i "\.ini$" >h:\nsc-ini-files.txt
and if you only want .ini files then this will work as well:

Code: [Select]dir /s /b /a-d h:\nsc*.ini >h:\nsc-ini-files.txt

Thank you for your reply first, but it doesn't match to my problem.

YES, they help to find out all the path I want to know,

but the problem lies in the for syntax, once i apply the dir.................... sentence in a for sentence, it returns only the files in H:\ BUT NOT IN H:\NSC by exemple.

WHY i want this effect?? because i want to know all these paths and then make modification to these files, their paths should be in a for loop~~

or perhaps there are other solutions

  Code: [Select]echo off
for /f "delims=" %%a in (' dir /s /b /a-d h:\nsc*.ini ') do (
   echo "%%a"
)
pause

Quote from: mangolzy on July 10, 2014, 07:50:19 AM
it returns only the files in H:\ BUT NOT IN H:\NSC by exemple.

What does this mean?  Did you mention H:\NSC in any of your posts?  Is this a folder?  Please explain.

The code above will show any file that starts with NSC and ends in .INI Quote from: foxidrive on July 10, 2014, 08:19:07 AM
Code: [Select]echo off
for /f "delims=" %%a in (' dir /s /b /a-d h:\nsc*.ini ') do (
   echo "%%a"
)
pause

What does this mean?  Did you mention H:\NSC in any of your posts?  Is this a folder?  Please explain.

The code above will show any file that starts with NSC and ends in .INI

thank you foxidrive!!

it works like this:

Code: [Select]echo off
setlocal enabledelayedexpansion
set newip=10.23.96.98
for /f "delims=" %%f in ('dir /s /b /a-d H:\nsc*.ini') do (
        echo %%f
pause
for /f "tokens=1* delims=:" %%a in (' findstr /n /r "^" "%%f" ') do (
set var=%%b
set var=!var:10.23.96.46=%newip%!
echo !var!>>sucess.txt
        )
echo *********************finish one*******************>>sucess.txt
echo good%%f>> H:\ok.txt
)
endlocal
i have the modification done in all the files concerned,

the only one problem that left is, they don't treat the blank line correctly as i have said before~~

can you help me with this delicate problem too?? It is a real problem in batch scripting when people don't describe what they are TRYING to do.

Run this and see if it is what you want to do, because I am guessing.

Code: [Select]echo off
setlocal enabledelayedexpansion
set newip=10.23.96.98
for /f "delims=" %%f in ('dir /s /b /a-d H:\nsc*.ini') do (
set "var=%%~nxf"
set "var=!var:10.23.96.46=%newip%!"
>>success.txt echo %%~dpf!var!
)
endlocal
pause
Quote from: foxidrive on July 10, 2014, 09:41:41 AM
It is a real problem in batch scripting when people don't describe what they are trying to do.

Run this and see if it is what you want to do, because I am guessing.

Code: [Select]echo off
setlocal enabledelayedexpansion
set newip=10.23.96.98
for /f "delims=" %%f in ('dir /s /b /a-d H:\nsc*.ini') do (
set "var=%%~nxf"
set "var=!var:10.23.96.46=%newip%!"
>>success.txt echo %%~dpf!var!
)
endlocal
pause

Let me make my problem clear:

I want to search in the whole system all the file begins with nsc and type of .ini;

once we found one path of this kind of file, we replace all the 10.23.96.46 with 10.23.96.98 in the file.

that's all the functionality that i want,

up to now with your help. there is no problem in locating all the files qualified,

1.   but still a little problem in the treatment of file, that's to say in the replacement when i try to read the file line by line, then when it comes to a blank line, the code i provided yesterday, will fill in the blank line with  "10.23.96.46=10.23.96.98"

2.   do you know how to get the folder where a file is in with a completed path of this file??

      that means:  for a file   H:\NSC\Test\nsc.ini, with the string "H:\NSC\Test\nsc.ini"  How can we return a string like this    "H:\NSC\Test\"??

Thank you again!There were 14 posts in this thread before you told US what you wanted.

871.

Solve : I need help appending preexisiting pdf file names with the current month, day?

Answer»

Below is the batch created...


echo off
set /P month="Enter the month to RENAME the texts ex.(01-12)?"

set /P day="Enter the day to rename the texts ex.(01-31)?"

set /P year="Enter the year to rename the texts ex.(2013 etc.)?"

ren for %%F in (*.pdf) do copy "%month%-%day%-%year%" "J:\Ownership\Star\2014\Current Files%%month%-%day%-%year%_%%F"

Below are the pdf file names I am trying to append (I would like to remove the numbers and add %%month%-%day%-%year% after the strings e.g. Las Vegas_, Orlando_)

Star - Las Vegas_29_73062435338
Star - Orlando_72_44867093663Do you have to do this in a folder tree or only one folder?

Do you want to PUT in the current date automatically?

Please show the filenames before and AFTERWARD, so that we don't misunderstand.Thank you for the reply.

No only one folder. I want the date values inputted based on the questions that are asked below.

echo off
set /P month="Enter the month to rename the texts ex.(01-12)?"

set /P day="Enter the day to rename the texts ex.(01-31)?"

set /P year="Enter the year to rename the texts ex.(2013 etc.)?"

Before

Star - Las Vegas_29_73062435338
Star - Orlando_72_44867093663

After

Star - Las Vegas 07-11-14
Star - Orlando 07-11-14Test this in a folder of copies of your PDF files:

Code: [Select]echo off
:loop
set /P "month=Enter the month to rename the texts ex.(01-12): "
set /P "day=Enter the day to rename the texts ex.(01-31): "
set /P "year=Enter the year to rename the texts ex.(2013 etc.): "
echo(
set "var="
set /p var=Is this correct? "%month%-%day%-%year%" Enter N for no or just press enter for yes:
if defined var goto :loop


for /f "delims=" %%a in ('dir *.pdf /b /a-d ') do (
   for /f "delims=_" %%b in ("%%a") do (
      ren "%%a" "%%b %month%-%day%-%year%%%~xa"
   )
)
echo done
pauseI tested it, but it seems that if there is a second or third underscore and strings afterwards then the batch leaves those file names alone.

Failed attempts

Star - TN_South Carolina_RM_120_186186107480

Star  - FL_Tennessee_109_8752148231853

Successful attempts

Star - FL 07-11-14

Star - SC 07-11-14

Any advice? Quote from: junior89 on July 11, 2014, 11:41:31 AM

I tested it, but it seems that if there is a second or third underscore and strings afterwards then the batch leaves those file names alone.

Failed attempts

Star - TN_South Carolina_RM_120_186186107480

Star  - FL_Tennessee_109_8752148231853

If they are PDF files then they will have been RENAMED to:

Star - TN 07-11-14

Star - FL 07-11-14

Your filenames have variations so this code REMOVES the text in a different way.


This uses a helper batch file called `repl.bat` (by dbenham) - download from:  https://www.dropbox.com/s/qidqwztmetbvklt/repl.bat

Place `repl.bat` in the same folder as the batch file or in a folder that is on the path.

Code: [Select]echo off
:loop
set /P "month=Enter the month to rename the texts ex.(01-12): "
set /P "day=Enter the day to rename the texts ex.(01-31): "
set /P "year=Enter the year to rename the texts ex.(2013 etc.): "
echo(
set "var="
set /p var=Is this correct? "%month%-%day%-%year%" Enter N for no or just press enter for yes:
if defined var goto :loop


dir *_*_*.pdf /b /a-d |repl "(.*)_.*_.*(\....)$" "ren \q$&\q \q$1 %month%-%day%-%year%$2\q" xi >renamepdf.bat
call renamepdf.bat
del renamepdf.bat

echo done
pause
Great! It works! Thank you so much!!!!!
872.

Solve : Saying HELLO?

Answer»

Hello, I am just new in this page, and also in MS_DOS study. My request: could you advise me a good study text or course learning MS_DOS..?

Thanks a LOT!There are a lot of videos and articles in the world wide web
I suggest a youtuber by the name of technologycrazy he has videos from which I kinda started from
I hope this helpsUse google for Prof Timo SALMI who maintains a FAQ list of batch file topics, and downloadable ZIP files for MSdos and Win9x and NT class batch file tips and tricks.

Code: [Select]echo hello Quote

echo hello

Was just waiting for someone to post that. I almost did, but didnt. The subject title was bait for that.  Look at a lot of EXAMPLES and figure out what they do and how they work.  Once you get a good grasp on the setup, USE the help command in cmd to get more specific information.  And as with learning everything, ask questions.Thanks after all.....similar when I got into word, I would like see and edit text documents, but can not. A lot of wierd signs appear on the screen.
Batch cannot edit .doc files, copy the text to a .txt and then edit it.
873.

Solve : VBScript: how to get the value from a function?

Answer»

Code: [Select]Dim datapath,filename,x,objFSO,myFile,objFile,strReadFile,outFile,objOutFile
datapath="C:\"
keyword="nsc"

Set objFSO = CreateObject("Scripting.FileSystemObject")

myFile = tempFilePath(datapath,keyword)

file = objFSO.GetFile(myFile)
path = file.Path

outFile = path&AMP;"nscnew.ini"
Set objFile=objFSO.OpenTextFile(myFile,1)
Set objoutFile=objFSO.OpenTextFile(outFile,2,True)
strReadFile=Replace(strReadFile, "10.23.96.46","10.23.96.98")
objoutFile.Write(strReadFile)
objoutFile.Close
file.Delete
objFSO.MoveFile outFile,myFile
Set objOutFile=Nothing
Set objFile=Nothing
Set objFSO=Nothing

Function tempFilePath(datapath,keyword)
On error resume next
  Set fso=createobject("scripting.filesystemobject")
  If fso.FolderExists(datapath) Then
     Set firstsub=fso.GetFolder(datapath)
     For each testfolder in firstsub.SubFolders
         If instr(1,testfolder.name,keyword,1)<>0 Then
            strpath=datapath&"\"&testfolder.name
            tempFilePath strpath,keyword
         End If
     Next
     For each testfile in firstsub.Files
         If instr(1,testfile.name,keyword,1)<>0 Then
            filetype=fso.GetExtensionName(testfile.path)
            If filetype="ini" Then
               tempFilePath=testfile.path
               wscript.echo tempFilePath
            End If
         End If
     Next
  End If
  Set firstsub=Nothing
  Set fso=Nothing
End Function

the function tempFilePath is for finding the path of an .ini file with the name started with 'nsc'

by the instruction wscript.echo tempFilePath, we know it return a correct result,

but no matter how many times i tried, i didn't get this value when I CALL this function in my "main" function..................

Can somebody find the problem?



[recovering disk space, attachment deleted by admin]This is the start of your script. Try it on your computer.

Code: [Select]Dim datapath,filename,x,objFSO,myFile,objFile,strReadFile,outFile,objOutFile
datapath="C:\"
keyword="nsc"

Set objFSO = CreateObject("Scripting.FileSystemObject")

myFile = tempFilePath(datapath,keyword)
Quote from: foxidrive on July 02, 2014, 04:36:15 AM

This is the start of your script. Try it on your computer.

Code: [Select]Dim datapath,filename,x,objFSO,myFile,objFile,strReadFile,outFile,objOutFile
datapath="C:\"
keyword="nsc"

Set objFSO = CreateObject("Scripting.FileSystemObject")

myFile = tempFilePath(datapath,keyword)

Excuse me?   What have  you changed??? How should i test, just with the codes you give?? Quote from: mangolzy on July 02, 2014, 06:28:22 AM
Excuse me?   What have  you changed??? How should i test, just with the codes you give??

I changed nothing.  It generates an error on my machine, which means your script won't even RUN past those lines.On line 32 tempFilePath is recursing on itself but doing nothing with the result. I suspect the line should be changed to:

Code: [Select]tempFilePath = tempFilePath(strpath,keyword)

It might also be desirable to have early exits within each if statement (Exit Function) IMMEDIATELY after setting the function result.



874.

Solve : batch file to search different OS on the network?

Answer»

Hi,

Can someone, guide me in creating batch file to search DIFFERENT OS on the network.

OS platforms : Windows XP, Windows 7, Ubuntu,

Is is possible to get the ip of same using the same batch file.

So you are asking for code that will check every computer on the network to see what OS it's running, and then organize them based on that?  I don't believe that is possible with batch, but someone might have more knowledge on networks than me.yes, exactly this am looking for....
If it is not possible via batch file, do we have any other method or tool , available in the industry to check the OS running on the network and sort them on the basis of OS.

It may help if the OP can explain why this is needed.
Would there be any issue of getting PERMISSION from other users to reveal their specs on the network?
we have around 3000+ system on the network.

This is required for audit porpose...

whether the data given is correct or now.

because, going manually with this will nesure data perfection and accuracy.

I hope things are little clear now..
is there any other WAY round.. Good. you need a special script. Somebody already did ot. You have to have some kind of permission to get the the computers on the network.
Look at this:
http://www.cyberciti.biz/networking/nmap-command-examples-tutorials/
Quote

Nmap is short for Network Mapper. It is an open source security tool for network exploration, security scanning and auditing. However, nmap command comes with lots of options that can make the utility more robust and difficult to follow for new users.

The purpose of this post is to introduce a user to the nmap command line tool to scan a host and/or network, so to find out the possible vulnerable points in the hosts. You will also learn how to use Nmap for offensive and defensive purposes.

You will need to look at the documentation to see how to go over network bridges or other things that may prevent cross over into another network on a different branch h of your network tree.

Quote
It was originally written by Gordon Lyon and it can answer the following questions easily:
    What computers did you find running on the local network?
    What IP addresses did you find running on the local network?
    What is the operating system of your target machine?
    Find out what ports are open on the machine that you just scanned?
    Find out if the system is infected with malware or virus.
    Search for unauthorized servers or network service on your network.
    Find and remove computers which don't meet the organization's minimum level of security.
Does that help? 


Quote from: Geek-9pm on June 25, 2014, 12:23:11 AM
Good. you need a special script. Somebody already did ot. You have to have some kind of permission to get the the computers on the network.
Look at this:
http://www.cyberciti.biz/networking/nmap-command-examples-tutorials/
You will need to look at the documentation to see how to go over network bridges or other things that may prevent cross over into another network on a different branch h of your network tree.
Does that help? 

Hi, do you think it's possible to connect to these machine on the network, and do some operations on it?

i have already the ip adress of these machines so i can login manuelly with a group of username and password.....

but for the moment, i have to do it repetetively .. that's why i am looking for the method to do it automatically

thx!.You have to go outside of pure  DOS. Network administrators use command line programs to get into other computers over the network.  To automatic the process requires a set of SCRIPTS suitable to the taks.  Such scripts can be extensions of NetBios or can be VBScript or even PowerShell applications. In any case, it is not called DOS. They are high-level programs that run from the command line. Or in Linux, we say from a console.

Please read over another definition of a high level network tools
http://www.darkreading.com/application-security/10-free-or-low-cost-network-discovery-and-mapping-tools/d/d-id/1141182?

Quote
One of the most useful adages for security professionals is "know thyself"--and when it comes to network security, the most fundamental task of knowing oneself is network discovery and mapping. Without up-to-date network diagrams and inventory lists, it is hard to even understand what you're protecting. The following tools can aid the process at little to no cost beyond man-hours.
 
Ericka Chickowski specializes in coverage of information technology and business innovation. She has focused on information security for the BETTER part of a decade and regularly writes about the security industry as a contributor to Dark Reading.  ...

You need to learn how to use the high level tools to gather information about your network. I do not have current knowledge about working in a huge network. But I am trying to  point you to the kind of tools needed  for that kind of work. IMHO your learning Network Mapping Tools is a start in the right direction.
Perhaps an IT person who is currently active can help you.   

EDIT: Had to replace a link.If one of these more learned options doesn't work, you could write a different script that runs on each OS to get the system data and copy it into a text file back to your computer.  Then use (I believe it's) robocopy to copy all the files over and run each of them in time.  The one that runs will allow you to tell which OS you have.I don't know about the op thing but I do know that you can get the ip through this in a command promt
Shutdown i
I am not sure of this works with a lot of computers
I hope this helps
requirement is IP corresponding to OS for around 3000 computers in the network.

This is required for audit porpose.

To check the no of OS and license.
875.

Solve : Alternative to SET /P on DOS 6.22?

Answer»

Hey GUYS,

Just for the giggles I'm running a Virtualbox on my PC with an emulated installation of DOS 6.22. I've made a couple minor TWEAKS to it from a 'clean' install, such as adding CD-ROM drivers (enabling it to use CD images) and I've introduced a more modern edit.com file, which has a few more features than the original had. Other than that, it's basically what you'd EXPECT in an install of DOS 6.22.

I've run into a bit of an issue, however, when it comes to writing batch files, as the methods I normally use for dealing with user input no longer work. As you probably can tell, the issue lies in my ability, or lack thereof, of handling user input. CHOICE EXISTS, but isn't flexible enough for what I WANT, and for the life of me, I'm having no luck either finding an alternative, or adapting a newer SET command to this installation.

So, if someone could point me in the right direction: How can I, in a pre-cmd.exe world, request input data from a user and store it in a variable during a batch file?Using a Qbasic script, writing a temporary batch file which you call, is one method that was used.http://www.robvanderwoude.com/userinput.php

876.

Solve : Any interest in a new DOS menu program??

Answer»

Is anybody out there interested in a *new* DOS menu program?  I'm planning the following features:

*   Use either text or graphics mode
*   Auto-run tools
*   Program or file mode
*   Create own icons
*   new colors
*   multiple color schemes
*   multiple menus

If you like this idea or have any suggestions, PLEASE post here.It sparked my curiosity ... what are you using to code these features?Cool!    I'm using Turbo C 3.0 with BGI.  I have a GUI library for both text and graphics modes but want to create my own.  Can anybody point me out to some DOS IRQ, EMS/XMS and mouse docs. on-line?  I could also use some help with BGI.Turbo C does mouse clicks.
But the mouse does not work in DOS.
This might help
http://cboard.cprogramming.com/cplusplus-programming/79474-can%27t-get-my-mouse-work-dos-borland-cplusplus-3-a.html
Quote

can't get my mouse to work on dos borland c++ 3
This is a discussion on can't get my mouse to work on dos borland c++ 3 within the C++ Programming forums, part of the General Programming Boards category; ... or any other DOS programs. Any ideas why?...
I don't UNDERSTAND why he mouse won't work in DOS, provided the drivers installed.   From what I saw there, DOS drivers are not 32 bit drivers. So they do not work.  That is what I think he said. The thread goes on to show some code in Turbo C that will FIX the problem. I have no idea if it is right. Sounds credible.XTRee Gold is fine for me...and i dont care about icons or color schemes etc...

It just works... Quote from: patio on December 25, 2014, 08:34:20 PM
XTRee Gold is fine for me...and i dont care about icons or color schemes etc...

It just works...
+1
877.

Solve : windows run -> command prompt?

Answer»

I have a command that I normally run manually in a Windows run (Windows Key + R). It starts the program and everything is fine.

Command:
Quote

"C:\Riot Games\League of Legends\RADS\solutions\lol_game_client_sln\releases\0.0.1.54\deploy\League of Legends.exe" "8394" "LoLLauncher.exe" "" "SPECTATOR 185.40.64.163:80 HePSGcqnkxXliRBtWvn7WuZKxxxspYw9 1680414939 EUW1"

I'm trying to make a program that does this for me (c++), cause I’m not sure how to make a windows run in c++ I’m trying to do this through the command prompt. When I enter:
Quote
start "C:\Riot Games\League of Legends\RADS\solutions\lol_game_client_sln\releases\0.0.1.54\deploy\League of Legends.exe" "8394" "LoLLauncher.exe" "" "spectator 185.40.64.163:80 HePSGcqnkxXliRBtWvn7WuZKxxxspYw9 1680414939 EUW1"

I get an ERROR (I translated it):
Quote
Cannot find the file 8394 Make sure you typed the name correctly, and try again

Does anyone see what I’m doing wrong? Or have a better solution.Read Start /?. The first argument is Title Text, so start with a dummy "" parameter.

You can use exec() to launch the program directly in C/C++. Quote from: BC_Programmer on September 12, 2014, 03:21:30 AM
Read Start /?. The first argument is Title Text, so start with a dummy "" parameter.

This is right - just adding that you can put it in a BATCH script.

Code: [Select]echo off
start "" "C:\Riot Games\League of Legends\RADS\solutions\lol_game_client_sln\releases\0.0.1.54\deploy\League of Legends.exe" "8394" "LoLLauncher.exe" "" "spectator 185.40.64.163:80 HePSGcqnkxXliRBtWvn7WuZKxxxspYw9 1680414939 EUW1"

I tried what you suggested Foxidrive. It does open the program, but just for a second and than returns an error. Should I change more things to the command or can I just COPY it from the Windows run box command? I'm not sure what the Windows run dialog exactly does. Quote from: cppeter on September 12, 2014, 05:23:28 AM
I tried what you suggested Foxidrive. It does open the program, but just for a second and than returns an error.

I don't know what error you saw, but try this in case the working directory needs to be set.

Code: [Select]echo off
start "" /D "C:\Riot Games\League of Legends\RADS\solutions\lol_game_client_sln\releases\0.0.1.54\deploy" "League of Legends.exe" "8394" "LoLLauncher.exe" "" "spectator 185.40.64.163:80 HePSGcqnkxXliRBtWvn7WuZKxxxspYw9 1680414939 EUW1"
It may be intentionally written into the game.  It says you aren't suppose to launch the game this way in the Terms of Use.  Getting past that, I would leave out the start command.  The script will not continue until after league of legends is closed out, but it should run the exact same as it did from run.exe
Code: [Select]"C:\Riot Games\League of Legends\RADS\solutions\lol_game_client_sln\releases\0.0.1.54\deploy\League of Legends.exe" "8394" "LoLLauncher.exe" "" "spectator 185.40.64.163:80 HePSGcqnkxXliRBtWvn7WuZKxxxspYw9 1680414939 EUW1"

Also, check to make sure that 0.0.1.54 is still the correct directory.  They like to change them up every once in a while.

If you don't mind me asking, where did you get the  "185.40.64.163:80 HePSGcqnkxXliRBtWvn7WuZKxxxspYw9 1680414939 EUW1" information?

EDIT: IT also might not be working DUE to riot disabling spectating.I got the command from lolnexus.com. You can also find it on http://quickfind.kassad.in/ Both under the spectate buttons. Thank you Foxidrive, it worked you are my hero!! I was ready to give up and then you came with your brilliant idea. Quote from: cppeter on September 12, 2014, 12:07:54 PM
Thank you Foxidrive, it worked

Thanks, I'm glad to hear that.

I've learned something new just now from your comment - the Run dialog sets the working directory to the path of the executable.
I just tested it with some sample files - and this is why your command worked in the Run dialog but failed in the first batch file I posted.


If anyone is interested you can create this batch file called one.bat in say c:\test and then in the Run dialog type c:\test\one.bat

If you open a cmd prompt in c:\ and execute c:\test\one.bat then you will get one line echoed and errors, but not from the Run dialog.

Code: [Select]echo off
>"%~dp0\batch2.bat" echo echo batch 2^&pause
echo batch 1
call "batch2.bat"
del "%~dp0\batch2.bat"
878.

Solve : batch command for different file type?

Answer»

Hello

i have thousands files in directory and different 3-5 file type...
i wanna execute diffrent profiles to file types...

EXAMPLE jobs...

if file_ext = *.txt
do
"c:\execute\vt.exe" "profiles\prf1.pf"  "*.txt"

if file_ext = *.xml
do
"c:\execute\vt.exe" "profiles\prf2.pf"  "*.xml"

if file_ext = *.xml
do
"c:\execute\vt.exe" "profiles\prf3.pf"  "*.XLS"

.................

i will start one job and will do different job for different file types

how i can do ?

thxIf vt.exe just MODIFIES the files then try this:


Code: [Select]echo off
for %%a in (*.txt) do "c:\execute\vt.exe" "profiles\prf1.pf"  "%%a"
for %%a in (*.xml) do "c:\execute\vt.exe" "profiles\prf2.pf"  "%%a"
for %%a in (*.xls) do "c:\execute\vt.exe" "profiles\prf3.pf"  "%%a"
pause
very NICE code

thank you bro

879.

Solve : delete some char on file name?

Answer»

Hello

some users using DONT accepted char on file names...

example :
Adam 11.01.2014.xls  or
Sunday, (11.01.2014).xls  or
London 11,01,2014.xls  or
Nuni.......05.05,2014......xls  or
Jane, 15,may,2014....sales!.doc


must be smilar file name
Adam 11-01-2014.xls

i will delete some chars, some chars will change new chars
i have rename program. but dont understand file-name or file-ext..  when i wanna change (.,!) smilar char, effecting with file-ext

what i wanna do on file names?
a) delete multi poins on files names with one point after i will change with [-]
b) change [, ]  with [ ]
c) delete [( ) !] and smilar chars on file-names
d) change [< > ] with [-]
e change [-- or more -] with [-] ones

but.. i must limit file-ext with :
[xls, xlsx, doc, docx, TXT, PDF, log, dat, ....]

time by time i can add new parameters

could you help me ?

thanksIt is hard to understand what your want to do.
Where did the files come from?
How many file do you  w ant to change?
hello

daily files on office
i change file names before backup
some days 10, some days +100 files changing with order

using fast file renamer program. but that program very simple. dont understand file-name and file-ext type

if possible, will be good before backup

thx
Test this: < and > are not legal in a filename so I ignored that.

Some lines are repeated to cater for MULTIPLE repeating . and - characters
It only shows the command on the screen, so remove the `echo` to make it work.

Code: [Select]echo off
for /f "DELIMS=" %%a in ('dir *.xls *.xlsx *.doc *.docx *.txt *.pdf *.log *.dat /a:-d /o:n /b') do call :next "%%a"
pause
GOTO:EOF
:next
set "newname=%~nx1"

set "newname=%newname:,= %"
set "newname=%newname:)=%"
set "newname=%newname:(=%"
set "newname=%newname:!=%"
set "newname=%newname:..=.%"
set "newname=%newname:..=.%"
set "newname=%newname:..=.%"
set "newname=%newname:..=.%"
set "newname=%newname:..=.%"
set "newname=%newname:--=-%"
set "newname=%newname:--=-%"
set "newname=%newname:--=-%"
set "newname=%newname:--=-%"
set "newname=%newname:--=-%"

echo ren %1 "%newname%

thank you very much

i will try tomorrow...

you are and your excellent codes.....   

thx

880.

Solve : Reading docx files on MS-DOS?

Answer»

Hello everybody!
How is possible reading docx files in MS-DOS..?
The way should be extensive or similar for any windows office...?
Thanks.
Nice day! Quote from: TRUCUTU on July 15, 2014, 10:13:37 AM

How is possible reading docx files in MS-DOS..?

Explain the task further.

MS-DOS and plain CMD in Windows has no way of opening encoded files the same way that Word does in MSOffice.

You can't read a Word File with a .BAT file but you can with a VBscript but without KNOWING what your intended task is it makes it KIND of HARD to help.
http://lmgtfy.com/?q=vbscript+read+word+document
881.

Solve : Why does Ms DOS only use 640k ram??

Answer»

It will not run PROGRAMS because it doesn't have enough memory, PLEASE HELP!!!!!What Programs are you trying to run?Falcon3Is that the max ram you can use? Or can I use more of what I have installed on the machine? Quote from: Extrememan321 on July 15, 2014, 06:26:44 PM

Is that the max ram you can use? Or can I use more of what I have installed on the machine?

How are you RUNNING it? How are you booting DOS? Do you have any memory managers installed (himem.sys, emm386.exe)?
Quote from: BC_Programmer on July 15, 2014, 08:00:10 PM
Do you have any memory managers installed (himem.sys, emm386.exe)?

As mentioned you need to create high memory, XMS, EMS etc.MS-DOS was created to run on the 8088 CPU in the original IBM PC. The CPU only can address one mega byte. of memory. The upper area of memory was reserved for BIOS and memory mapped video. The design allowed a maximum of 640K of RAM for DOS.

Now those limits have little meaning. With the introduction of the Intel 386 chip much larger memory was available. And by the way, the introduction of the 386 was vital to the birth of the Linux system.




Quote from: Geek-9pm on July 15, 2014, 09:16:37 PM
And by the way, the introduction of the 386 was vital to the birth of the Linux system.
Well considering that was the most prominent chip in use at the time I guess you could say it was vital. Quote from: Squashman on July 16, 2014, 06:58:52 AM
Well considering that was the most prominent chip in use at the time I guess you could say it was vital.
The 286 was a dud.  It piratically destroyed Digital Research.
 Intel changed  the design in mid-stream. But The 386 was developed to be areal 32 bit CPU and backward compatible with the original 8086 instruction set.
The History of the i386 CPU.

It is working now thanksHow ? Quote from: Extrememan321 on July 16, 2014, 09:09:46 AM
It is working now thanks
Quote from: patio on July 16, 2014, 09:13:46 AM
How ?
As my Mother likes to say, "The Little Green Men inside fixed it!" Quote from: Extrememan321 on July 16, 2014, 09:09:46 AM
It is working now thanks

As the guys comment - it would be nice to see your solution as a forum like this is dedicated to provide an answer for a problem, and then OTHERS in the future can get help to similar ISSUES merely by searching.

By providing your solution you will repay the forum and the helpers.
882.

Solve : Help needed - batch file that increments a number in a file?

Answer»

Hi,

Hope someone can help me with this:
having a bit of an issue trying to create a batch file for XP that INCREMENTS a number in a file named properties.p:
the batchnumber will START from 100 and increment+1 everytime batch file is run.
example of properties.p files CONTENTS:

#
#Tue Jul 08 14:58:54 BST 2014
BatchNumber=100

Thanks in advance
Kev Code: [Select]#
#Tue Jul 08 14:58:54 BST 2014
BatchNumber=100
Do you need the first two lines?  Do they have to CHANGE at all?Hi,

Thanks for the reply,
yes i will need the first two lines,
the first two lines will remain the same, its just the third line that i will need to increment by 1,

thanksThis works here:

Code: [Select]echo off

<properties.p (
set /p a=
set /p b=
set /p c=
)

for /f "tokens=1,* delims==" %%a in ("%c%") do set c=%%a&set d=%%b

set /a d=d+1

(
echo %a%
echo %b%
echo %c%=%d%
)>properties.p
Excellent thanks very much that worked for me

now say if i have a LIST of files like below that are created already and will match the batch number:
LR0100*.*
LR0101*.*
LR0102*.*
LR0103*.*
....
....

how could I in a batch file copy one file at a time from a folder into another so that the next time i run the batch file it copies LR0101 and next time LR0102 and so on...


Hope I am clear
Thanks a million

Explain a little more clearly.

When you click the batch file above, what do you want copied from where and to where?
ok so in a folder c:\kevin\ i will have individual files named LR0100*.*,  LR0101*.*, LR0102*.* and so on (could be 80 files) ...
in the batch file i would like it to COPY LR0100*.* to c:\kevin\archive\ then using your previous script increment the batch number file + 1 and end the batch file.
then when i run the batch file again this time it would copy LR0101*.* to c:\kevin\archive\ and increment the batch number file + 1,
and so on.

EDIT: the files that i will have in C:\Kevin\ will be all the same filename except incremented by 1 like above for each file.This assumes that the folders already exist:

Code: [Select]echo off

<properties.p (
set /p a=
set /p b=
set /p c=
)

for /f "tokens=1,* delims==" %%a in ("%c%") do set "c=%%a"&set "d=%%b"

copy "c:\kevin\LR0%d%*.*"  "c:\kevin\archive\"

set /a d=d+1

(
echo %a%
echo %b%
echo %c%=%d%
)>properties.p

Excellent stuff that worked like a charm!!

thanks for all your help!

883.

Solve : A beginner question?

Answer»

Please, answer this question for a dummy: I can see the different directories in a given POSITION, but once I type cd some directory I get :" the system can not find the specified route"... some time: "the system can not find specified FILE"
Thanks a LOT in advance!Your question isn't clear but use double quotes around the path, or path and filename.

For a folder:

cd "my folder"

cd /d "e:\books\my author"

To launch a file:

"c:\my folder\vt.exe"

Thanks for your answer. I am going try be clear on my question. Please be patience.
I have this picture on the ms-dos screen:
C:\users\public\documents>
Typing “dir” and enter I can see a file : 12.503 The Fed is joining forces with the big… (it is a .docx)
I would like change this file name, then I write : rename space and that long title…. Two answers: the system can not find the specified file
The SINTAXIS of the command is not correct
I thnk is not fair have a wierd name for that file , (I see several ones like that), then I have tried to change its name, also I have tried to see ist content using “type” command, but  I can have had success anyway.
I appreciate your comments. Thanks, and have a very nice rest of the day!
Have you tried using quotes as foxidrive mentioned?

Thanks again! I have used quotes and it works!. I mean I can get the file, but looking for it content I only get a lot of wierd signs...I was looking at ASCII table but I could not find all of them...can you help me?
Nice dayA plain text file has only the text you see,
while a DOC and docx file has invisible formatting and container characters at the start and throughout the file, along with the text that you see.

That is why when you type many files that you see odd characters, and don't always see all the file, sometimes also hearing a beep.

Basically there are plain text files and there are binary format files, and the binary format files will also contain all sorts of odd characters above ascii value 127 and below ascii value 32 amongst the regular keyboard characters.  See http://www.asciitable.com/

A useful type of program is a Hex Editor and viewer - which will open any file and show you the ascii characters and HEX values for each character, from 00 to FF in a table. 
With a program like this (WinHex is a free one) you can see the makeup of files including invisible characters that you don't usually see.

884.

Solve : Trim char on file names?

Answer»

Hello

i have much files in directory and i wanna trim file name
---------------------------------------------------------
Ali_Veli_05_02_02_00001.log
Ali_Veli_06_04_75_00002.log
Ali_Veli_08_05_53_00003.log
Ali_Veli_11_07_16_00010.log
Ali_Veli_14_11_96_00012.log
Ali_Veli_23_18_00_00034.log
---------------------------------------------------------


to.....

---------------------------------------------------------
exam 1:
Ali_Veli_00001.log
Ali_Veli_00002.log
Ali_Veli_00003.log
Ali_Veli_00010.log
Ali_Veli_00012.log
Ali_Veli_00034.log
---------------------------------------------------------

exam 2:

Ali_Veli_1.log
Ali_Veli_2.log
Ali_Veli_3.log
Ali_Veli_10.log
Ali_Veli_12.log
Ali_Veli_34.log
---------------------------------------------------------

2 exam different work for me

could you help me ?

thxHere's one way: there are two different scripts to rename the files.  You can't rename the same set of files TWICE though.

This uses a helper batch file called `repl.bat` (by dbenham) - download from:  https://www.dropbox.com/s/qidqwztmetbvklt/repl.bat

Place `repl.bat` in the same folder as the batch file or in a folder that is on the path.


CODE: [Select]echo off
dir Ali_Veli_*.log /b /a-d |repl "(.*?_.*?_).*?_.*?_.*?_(.*\....)" "ren \q$&\q \q$1$2\q" x >renfiles.bat
call renfiles.bat
del renfiles.bat
pause

Code: [Select]echo off
dir Ali_Veli_*.log /b /a-d |repl "(.*?_.*?_).*?_.*?_.*?_[0]*(.*\....)" "ren \q$&\q \q$1$2\q" x >renfiles.bat
call renfiles.bat
del renfiles.bat
pause

This will merely display the changes to the screen:

Code: [Select]echo off
dir Ali_Veli_*.log /b /a-d |repl "(.*?_.*?_).*?_.*?_.*?_(.*\....)" "$1$2"
dir Ali_Veli_*.log /b /a-d |repl "(.*?_.*?_).*?_.*?_.*?_[0]*(.*\....)" "$1$2"
pause
sorry.. my mistake for file names

Ali_Veli not standart on file name.. so sorry for it

different file names...
Ali_Veli_05_02_02_00001.log
HAsaOsman_Nejat_Bekir_Selim_08_09_02_00 001.log
Cilek_a_06_02_01_00005.log
a_99_11_74_10562.log
akhkas_jhdk jhkj ha'skjhdkjah_cht_div_bat_08_09_02_00001.lo g


standart just right char count

all file name included  this style  "_xx_yy_zz_abcde"

i wanna modify _xx_yy_zz_abcde   this number line


so sorry for my mistakeShow what you want to rename them to...

Your original post shows two different formats.wanna change  file names  with 2 FORMAT

mean.. i will use 2 batch file  on my files for different works

---------------------------------------------------------
Ali_Veli_05_02_02_00001.log   ===>    format_1=  Ali_Veli_00001.log    ===>  format_2 = Ali_Veli_1.log
Hasan_06_04_75_00002.log   ===>    format_1=  Hasan_00002.log    ===>  format_2 = Hasan_1.log
Cilek_yesim_nihale_08_05_53_00003.log   ===>    format_1=  Cilek_yesim_nihale_00003.log    ===>  format_2 = Cilek_yesim_nihale_3.log
aa_11_07_16_00010.log   ===>    format_1=  aa_00010.log     ===>  format_2 = aa_10.log
Zeli_14_11_96_00012.log   ===>    format_1=  Zeli_00012.log     ===>  format_2 = Zeli_12.log
Bilal_23_18_00_00034.log   ===>    format_1=  Bilal_00034.log    ===>  format_2 = Bilal_34.log
---------------------------------------------------------


sorry for mistake...

thxTest this - it should create two sets of files with the format you need=:

Code: [Select]echo off
dir *.log /b /a-d |repl "(.*_).*_.*_.*_(.*\....)" "copy \q$&\q \q$1$2\q" xa >renfiles.bat
dir *.log /b /a-d |repl "(.*_).*_.*_.*_[0]*(.*\....)" "copy \q$&\q \q$1$2\q" xa >>renfiles.bat
call renfiles.bat
del renfiles.bat
pause

thank you very much

i am free now from  tools

this files will work on auto

thats all working with repl.bat file.. i copy repl.bat file to windows directory


thank you very much for everythings
sorry i will disturb you

this batch file creating NEW files for new (formated) file name

but... i dont need old file

just need NEW file names

how can do ?its true ?

------------------------------------------------------------------------------------------------------
dir *.log /b /a-d |repl "(.*_).*_.*_.*_(.*\....)" "ren $& $1$2" xa>renfiles.bat
------------------------------------------------------------------------------------------------------Try this: I change the copy to REN in the second repl command.

Code: [Select]echo off
dir *.log /b /a-d |repl "(.*_).*_.*_.*_(.*\....)" "copy \q$&\q \q$1$2\q" xa >renfiles.bat
dir *.log /b /a-d |repl "(.*_).*_.*_.*_[0]*(.*\....)" "ren \q$&\q \q$1$2\q" xa >>renfiles.bat
call renfiles.bat
del renfiles.bat
pauseworking

thank you very much

885.

Solve : Bat script Delete any File Not Created Today?

Answer»

I'm having difficulty removing the time from the date modified date. The date modified displays like so... 07/12/2014 03:27 PM. I tried numerous things but no LUCK any help would be great.

Its currently showing...
07/17/2014 03:27 PM NEQ 07/17/2014
but i need it to be this...
07/17/2014 NEQ 07/17/2014

thanks!

Code: [Select]ECHO On
set currentDate=%date:~4,2%/%date:~7,2%/%date:~10,4%
set File="C:\TEST\*.txt"


FOR %%? IN (%File%) DO (
ECHO Last-Modified Date : %%~t?
echo FileName : %%?
echo %currentDate%
ECHO %%~t?
IF %%~t? NEQ %currentDate% DEL "%%?"
)
PAUSE


Your explanation SAYS date modified but the title implies CREATION date

Which is it?  And are the files in a single folder?  Is it for more than say 50 files at a time?  Which OS is it for?try this:
Code: [Select]ECHO On
set currentDate=%date:~4,2%/%date:~7,2%/%date:~10,4%
set File="C:\Test\*.txt"


FOR %%? IN (%File%) DO (
ECHO Last-Modified Date : %%~t?
echo FileName : %%?
echo %currentDate%
ECHO %%~t?
for /f "tokens=1 delims= " %%A in ("%%~t?") do (
IF %%A NEQ %currentDate% DEL "%%?"
)
)
PAUSEThat worked  Lemonilla thank you very MUCH

886.

Solve : CALLed Function not returning values?

Answer»

I have a FOR LOOP which calls a FUNCTION with passed parameters.  The parameters set inside the function is not being returned [see Resultant Output] when I echo var1 / var4 / var5, any ideas how to fix this?

Code: [Select]setlocal enabledelayedexpansion
echo off

for /f "tokens=*" %%X in (c:\temp\keys.txt) do (
    set "work=%%X"
    :: echo %%X
    :: fill empty fields with "#NUL#" ...
    :: but do it twice, just in case CONSECUTIVE fields are empty
    for /l %%i in (1,1,2) do set "work=!work:;;=;#NUL#;!"
    for /F "tokens=1,2,3,4* delims=;" %%i in ("!work!") do (
        echo first is:  %%i
        echo second is: %%j
        echo third is:  %%k
        echo fourth is: %%l
        echo rest is:   %%m
        echo ----------------------------------- 
        CALL :func1 %%i %%j %%k %%l whatthe
        echo var1 : %var1%
        echo var4 : %var4%
        echo var5 : %var5%
))

goto :EOF

:func1
set "var1=%~1"
set "var2=%~2"
set "var3=%~3"
set "var4=%~4"
set "var5=%~5"
echo func values:
echo 1 %var1%
echo 2 %var2%
echo 3 %var3%
echo 4 %var4%
echo 5 %var5%
goto :EOF

Contents of c:\temp\keys.txt:
Code: [Select]this;is;a;test;file           
this;is also; a;;test file   
this file;has;;;;nul;;;data 
new:datafile;with;;;null_data;;Y

Resultant output:
Code: [Select]C:\Users\Anonymous\Downloads\DOS&GT;setlocal enabledelayedexpansion
The system cannot find the drive specified.
first is:  this
second is: is
third is:  a
fourth is: test
rest is:   file
-----------------------------------
func values:
1 this
2 is
3 a
4 test
5 whatthe
var1 :
var4 :
var5 :
The system cannot find the drive specified.
first is:  this
second is: is also
third is:   a
fourth is: #NUL#
rest is:   test file
-----------------------------------
func values:
1 this
2 is
3 also
4 a
5 #NUL#
var1 :
var4 :
var5 :
The system cannot find the drive specified.
first is:  this file
second is: has
third is:  #NUL#
fourth is: #NUL#
rest is:   #NUL#;nul;#NUL#;#NUL#;data
-----------------------------------
func values:
1 this
2 file
3 has
4 #NUL#
5 #NUL#
var1 :
var4 :
var5 :
The system cannot find the drive specified.
first is:  new:datafile
second is: with
third is:  #NUL#
fourth is: #NUL#
rest is:   null_data;#NUL#;Y
-----------------------------------
func values:
1 new:datafile
2 with
3 #NUL#
4 #NUL#
5 whatthe
var1 :
var4 :
var5 :
Replace this:

Code: [Select]        echo var1 : %var1%
        echo var4 : %var4%
        echo var5 : %var5%

with this:

Code: [Select]        echo var1 : !var1!
        echo var4 : !var4!
        echo var5 : !var5!
Thanks a million for the fix.

887.

Solve : Insert text to a new last line?

Answer»

Hi,

I am using the following code to insert the filename to the last line.
FOR %G in (*.txt) do echo.>>file.txt %~NG>>%G

However sometime it gets appended to the EXISTING last line.
I want just the filename to be in the last line. How do we insert a CRLF in DOS and add a text?

Thankyou
Atturhari

Quote from: atturhari on July 17, 2014, 06:17:05 AM

Hi,

I am using the following code to insert the filename to the last line.
FOR %G in (*.txt) do echo.>>file.txt %~nG>>%G

However sometime it gets appended to the existing last line.
I want just the filename to be in the last line. How do we insert a CRLF in DOS and add a text?

Thankyou
Atturhari

I have almost no idea what you mean, but I think you want the text ">>file.txt %~nG" At the end of the file %G.  In that case, you need to escape the first two '>'.  To do this simply prefix them with a carrot '^>'.Your problem seems to be that the last line doesn't always have a trailing CF/LF

This is a solution to that - test it on some sample .txt files:
remove - This is the last line as it's just to help see where it echos

Code: [Select]echo off
for /f "delims=" %%a in ('dir *.txt /a:-d /b') do (
   findstr /v ".*$" "%%a" >nul && (>>"%%a" echo()
   >>"%%a" echo(%%a - This is the last line
)As pointed out, the problem is the last line doesn't always have a trailing CF/LF causing the text (or filename) to be appended to the same line.

I tried foxidrive's code, unfortunately it does not work.
Also my files are on a network, so want to know if it is POSSIBLE to tweak the below line of code to add a CF/LF

FOR %G in (*.fex) do echo FILENAME:%~nG>>%G

Thankyou Quote from: atturhari on July 17, 2014, 10:47:08 PM
I tried foxidrive's code, unfortunately it does not work.

It works fine here.  How does it fail for you? Quote from: foxidrive on July 18, 2014, 01:27:21 AM
It works fine here.  How does it fail for you?

Was executing your program in CMD and just realized that i should use a single % instead of %%.

Your program does the job perfectly. Thank you very very much  Quote from: atturhari on July 18, 2014, 04:06:50 AM
Was executing your program in CMD and just realized that i should use a single % instead of %%.

You have to be kidding me... 

Who taught you to paste batch files into a cmd prompt? Quote from: foxidrive on July 17, 2014, 08:19:47 AM
Your problem seems to be that the last line doesn't always have a trailing CF/LF

This is a solution to that - test it on some sample .txt files:
remove - This is the last line as it's just to help see where it echos

Code: [Select]echo off
for /f "delims=" %%a in ('dir *.txt /a:-d /b') do (
   findstr /v ".*$" "%%a" >nul && (>>"%%a" echo()
   >>"%%a" echo(%%a - This is the last line
)
Quote from: foxidrive on July 18, 2014, 04:22:58 AM
You have to be kidding me... 

Who taught you to paste batch files into a cmd prompt?

Hmm.. my honest answer,
In cmd prompt, the code can be edited quickly and best for trail and error.
Running as .bat file is TIME consuming involving multiple steps  Quote from: atturhari on July 22, 2014, 05:50:33 AM
Hmm.. my honest answer,
In cmd prompt, the code can be edited quickly and best for trail and error.
Running as .bat file is time consuming involving multiple steps 
You should TRY using Notepad++.  You can edit and run your batch files within Notepad++. Quote from: atturhari on July 22, 2014, 05:50:33 AM
Hmm.. my honest answer,
In cmd prompt, the code can be edited quickly and best for trail and error.
Running as .bat file is time consuming involving multiple steps 
Or you could always just not maximize everything.
888.

Solve : Write Command line to mapped network printer?

Answer»

Hello All,
Could you let me know that,
1-Can we WRITE Command line to mapped network printer ?Could you let me know how?

2-I wrote a batch file to mapped network drive for folder and file like this:
Net use H: \\server\Acount

   -The result i will get mapped "account" and "H:" drive in windows explorer like this:
Account (\\abc\Account) (H:)
But i dont want to show the PATH like that, just only showing account folder and drive..

  - Also Can you show me that when i press my bath file containing by Net use H: \\Server\account, And after that, it will ASK me do you want to mapped "Accounting" and i have option to press Yes or No"? and if i hit "No" , it's will proceed to the next line or what ever...

THANKS you so much and i am SORRY for my english.
Best Regards,


889.

Solve : I need help loading?

Answer»

I can save perfectly but I can't load and have the variables CHANGE with it any help I will try.
My code looks like this:
echo off
Setlocal enabledelayedexpasion
Set var1=3
Set var2=7
Set var3=4
Set var4=4
Set var1_wieght=6
Set var1_value=4
Stuff like that
I am writing this on a tablet because my computer has an internet issue
But my computer is an windowns xp and is an hp computer.
Thanks
Batch code:

echo off
set val1=32
set val2=54
set val3=69

echo these are values we will save:
echo val1=%val1%
echo val2=%val2%
echo val3=%val3%

if exist values.dat del values.dat
echo val1=%val1% >> values.dat
echo val2=%val2% >> values.dat
echo val3=%val3% >> values.dat

echo reset values:
set val1=0
set val2=0
set val3=0
echo val1=%val1%
echo val2=%val2%
echo val3=%val3%

echo load values:
for /f "delims=" %%A in (values.dat) do set %%A
echo val1=%val1%
echo val2=%val2%
echo val3=%val3%

Batch output:

these are values we will save:
val1=32
val2=54
val3=69
reset values:
val1=0
val2=0
val3=0
load values:
val1=32
val2=54
val3=69Thanks
 But sadly that for some unknown reason won't work i t just shuts down
Quote from: shiverbob on June 30, 2014, 02:48:22 PM

i t just shuts down

What, the PC shuts down?
Connect your tablet to the computer, and post the whole code.  It is most likely be a directory discrepancy. Quote from: shiverbob on June 30, 2014, 02:48:22 PM
Thanks
 But sadly that for some unknown reason won't work i t just shuts down

Put a pause command as the last line.When I conect to thhe computer it wants me to install mpt and my tablet is a nook
 How are you running a batch file on a nook?  It uses android.  I'll work on a adb solution.  Where is your file saved on the nook?

something like this:
Code: [Select]adb pull "%loc%" "%cd%\BatchFile.bat"
I am not running the file through a nook I can but I USE a windows xp.
It is a hp tower
I don't know if that helps
So if you are not running the batch file on the nook, but when you run it it doesn't work, and you cannot transfer it off the nook, what is it doing on the nook to begin with?

If the file is actually on the hp tower and not the nook, then can't you move it over via flash drive to the computer you are posting from and then post the code?No the tower doesn't have internet this does and the file was never on the nook
If it helps it is and hp tower with operating system of window xp home edition
And I have no other computer that works right now I am in the middle of building one
I am posting from the nook
I tried the code and it says envirment VARIBLE not set?
You aren't overriding %path% are you?  If not, check to make sure that C:\windows\system32 is somewhere in that.  It should be easy to do with
Code: [Select]echo %path% | find "system32"
if something shows up, you have it in there.I just TOOK away echo off and it says what it is supposed to say
This weekend I will try UPDATING it to vista and see if that helps
It is all saved to my desktop and I have know idea why its not working.
It work on my friends computer and his was a  windows 7
I will upload the code tomorrow I am going to be out of town
890.

Solve : Robocopy GUI download source?

Answer»

Hello,
I am looking for a reliable download site for the ROBOCOPY GUI that is COMPATIBLE with my version.
I have Robocopy.exe  5.1.10.1027 dated 1/20/2008 in C:\Windows\System32.
Does someone have a suggestion?
Thanks
Frank CAKIAK this is the only official download link for the Robocopy GUI TOOL.
http://download.microsoft.com/download/f/d/0/fd05def7-68a1-4f71-8546-25c359cc0842/UtilitySpotlight2006_11.exeYou can ALSO use L0NG PATH TOOL, it works perfectly...

891.

Solve : Create batch file to insert text into multiple txt files??

Answer»

Hi All!!

Newb here with another newb question 

I have been at this for the last 10 hours. It's 4:38am Hawaii time and I am not going to sleep till I figure this out :-)

I have 4,000 dummy files in one of my pc folders that I need to add text to. They are all empty txt files right now and I just need to insert text that says "This is a placeholder file. You may delete this file if you wish."

I tried creating a run.cmd file.........but I don't know what the heck I am doing :-) I started doing it by hand and by the time I got 700......I was like "this is stupid, there has to be an easier way."

So here I am!

Any help would be greatly appreciated!!!!1

Thanks!!

CourtneyDo you need 700 files with the same text but unique files names?
Does each file have to have a variation fro the text?
You can do it in batch, but using almost any script language other than batch is easier fro most people.
It can be done with a FOR loop, but the syntax of batch FOR loops is HARD to remember, unless you do it every day.
Do you use any script language? JavaScript, VBScript
Here is a short list.
http://isystemadmin.com/list-of-popular-scripting-languages-for-linux-and-windows
That site happens to mention SED, a program that has been  ported to Windows and can be used with DOS commands to manipulate text and file names.
But if you really want the DOS only batch file, just want as few minuets.
The EXPERT is coming. Just wait.if you have a list of the files :
Code: [Select]for /f "delims=" %%A in ('type "ListOfLocations.txt"') do (

cd %%A
for /f "delims=" %%B in ('type "ListOfFileNames.txt"') do (
if exist %%B ECHO This is a placeholder file. You may delete this file if you wish. &GT;>%%B
echo Wrote to %%A\%%B.
)
)

if they are all in the same place:
Code: [Select]for /f "delims=" %%A in ('dir /b *.txt') do (
echo This is a placeholder file. You may delete this file if you wish. >>%%A
)

I hope this helps.for /f "delims=" %%A in ('dir /b *.txt') do (
echo This is a placeholder file. You may delete this file if you wish. >>%%A
)

I am accessing files on the network path and DIR command causes some issues.
Can anyone rewrite the program replacing DIR?

ThankyouI don't do much with NETWORKS, but try looking into the command 'pushd'.

892.

Solve : Move end of line marker in every line to a specific column?

Answer»

Hello,

Could you please give me pointers on how to code a batch script to read every line in a text file and move the end of line marker to a SPECIFIC column? I have hundreds of files which require this formatting.

Input: ABCDEFGHI
Output: ABCDEFGHI

Appreciate your inputs.

Thanks. Code: [SELECT]type "file.txt" |repl "(.*)" "$1                          " |repl "^(.{22}).*" "$1"
This uses a helper batch file called `repl.bat` (by dbenham) - download from:  https://www.dropbox.com/s/qidqwztmetbvklt/repl.bat

Place `repl.bat` in the same FOLDER as the batch file or in a folder that is on the path.


In the command line above the number 22 in the last term tells it where to put the new line - here it is after the 22nd character on each line.
If you need more than the 25th column then add more spaces after the first $1 (there are 25 spaces there at the MOMENT).

Thank you. I will try this.

One more question. In CASE of a varying column (say the new line is present in column 10 on line 1 and column 15 on line 2)
How do i capture the current position/column of the new line character? I can insert the appropriate no of spaces in between and move the new line character to the specific column.

Thanks.The code moves it to the end of the 22nd column in all lines, and pads the lines with spaces if needed.

893.

Solve : rename images in specified directory?

Answer»

Hi,

I'm trying to create a BATCH file to rename all jpg images in a specified directory and add NEW names in file. new NAME should be the path for the image (with replacing each \ by $) concatenated with image name.

this is the command I added and save in test.cmd, but it is not working

echo off & for /R "C:\Users\pc\Desktop\testing" %%A in (*.jpg) do set name2=%%A & set %name2:\=$% & rename %%A %name2%GIVE this a burl:

Code: [SELECT]echo off
setlocal enabledelayedexpansion
for /R "C:\Users\pc\Desktop\testing" %%A in (*.jpg) do (
   set "name2=%%~pnxA"
   ren "%%A" "!name2:\=$!"
)

894.

Solve : repl help?

Answer»

So I started to really use repl, and It's made quite a few of my scripts run infinitely smoother.  I'm running into some issues though.  I'm attempting to gather Lat / Long coordinates from a .kml file (looks quite a lot like html to me).  The issue that I've run into is that all the data in the kml is on the first line.  to correct this, I was trying to use repl to add new line characters at specific places to allow me to gather the necessary information using a for loop.  But for some reason, repl is erroring when I try.

Code: [Select]T:\job>type "Cars French 1.kml" | repl X I "<address^>" "\n<address^>" >[f].txt
The syntax of the command is incorrect.
The syntax of the command is incorrect.
C:\cmdPlugins\repl.bat(191, 1) Microsoft JScript runtime error: Syntax error in
regular expression

The process tried to write to a nonexistent pipe.

T:\job>type "Cars French 1.kml" | repl X I "<address>" "\n<address>" >[f].txt
| was unexpected at this time.
The process tried to write to a nonexistent pipe.

Code: (Example kml) [Select]<?xml version="1.0"?><kml xmlns="http://earth.google.com/kml/2.0"><Document><name>Stuff</name><description> | Created with http://batchgeo.com</description><style id="0"><BalloonStyle><text><![CDATA[ <b>$[name]</b><br />$[address]<br />$[description]<br/><br/>$[geDirections] ]]></text></BalloonStyle></style><Placemark><name>Amerya (3S)</name><description>&lt;div&gt;&lt;span class=&quot;l&quot;&gt;Phone:&lt;/span&gt;&amp;nbsp;(+2)034700165 &lt;/div&gt;</description><Point><coordinates>29.918739595939,31.20009469878,0</coordinates></Point><address>24kM Cairo-Alex Desert Road Alexandria Egypt</address><styleUrl>#0</styleUrl></Placemark><Placemark><name>Amex Ragheb</name><description>&lt;div&gt;&lt;span class=&quot;l&quot;&gt;Phone:&lt;/span&gt;&amp;nbsp;(+2)01222101673 &lt;/div&gt;</description><Point><coordinates>32.687635261674,25.680906223415,0</coordinates></Point><address>Airport Road Luxor Egypt</address><styleUrl>#0</styleUrl></Placemark><Placemark><name>Anas lel Sayarat</name><description>&lt;div&gt;&lt;span class=&quot;l&quot;&gt;Phone:&lt;/span&gt;&amp;nbsp;(+2)01003422839&lt;/div&gt;</description><Point><coordinates>32.899830632474,24.088942749132,0</coordinates></Point><address>El Mante 2a El Senaeya El gedida Aswan Egypt</address><styleUrl>#0</styleUrl></Placemark><Placemark><name>Ara Mechanics</name><description>&lt;div&gt;&lt;span class=&quot;l&quot;&gt;Phone:&lt;/span&gt;&amp;nbsp;(+2)01111099909&lt;/div&gt;</description><Point><coordinates>31.340403435549,30.089174843937,0</coordinates></Point><address>48 Abdel Razik El Sanhory St. From Makram Ebid Madinet Nasr Egypt</address><styleUrl>#0</styleUrl></Placemark><Placemark><name>Arish (2S)</name><description>&lt;div&gt;&lt;span class=&quot;l&quot;&gt;Phone:&lt;/span&gt;&amp;nbsp;(+2)0683353853&lt;/div&gt;</description><Point><coordinates>33.80327807662,31.132096531236,0</coordinates></Point><address>El Farik Bahary Fouad Zikry St. Behind Samiramis Hotel Arish Egypt</address><styleUrl>#0</styleUrl></Placemark><Placemark><name>Asyut (Service Center)</name><description>&lt;div&gt;&lt;span class=&quot;l&quot;&gt;Phone:&lt;/span&gt;&amp;nbsp;(+2)0882289663&lt;/div&gt;</description><Point><coordinates>31.185925714141,27.178313572373,0</coordinates></Point><address>El Wady El Gedeed Desert Road Infront of El Manteaa El Ganobeya el askareya Asyut Egypt</address><styleUrl>#0</styleUrl></Placemark><Placemark><name>Asyut (2S)</name><description>&lt;div&gt;&lt;span class=&quot;l&quot;&gt;Phone:&lt;/span&gt;&amp;nbsp;(+2)0882289663&lt;/div&gt;</description><Point><coordinates>31.174390102815,27.195572765047,0</coordinates></Point><address>55 ElHelaly St. Asyut Egypt</address><styleUrl>#0</styleUrl></Placemark><Placemark><name>Auto Group</name><description>&lt;div&gt;&lt;span class=&quot;l&quot;&gt;Phone:&lt;/span&gt;&amp;nbsp;(+2)16441&lt;/div&gt;</description><Point><coordinates>31.205026080241,30.050752011337,0</coordinates></Point><address>26 El Nakhil Street Mohandsein Egypt</address><styleUrl>#0</styleUrl></Placemark><Placemark><name>Auto Group</name><description>&lt;div&gt;&lt;span class=&quot;l&quot;&gt;Phone:&lt;/span&gt;&amp;nbsp;(+2)16441&lt;/div&gt;</description><Point><coordinates>29.926686437909,31.198941618085,0</coordinates></Point><address>27 Hassan lbn Thabet Tanta Egypt</address><styleUrl>#0</styleUrl></Placemark><Placemark><name>Dokki Showroom</name><description>&lt;div&gt;&lt;span class=&quot;l&quot;&gt;Area:&lt;/span&gt;&amp;nbsp;Dokki&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;l&quot;&gt;Short Number:&lt;/span&gt;&amp;nbsp;12311&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;l&quot;&gt;Phone:&lt;/span&gt;&amp;nbsp;(+2)33388463/7&lt;/div&gt;</description><Point><coordinates>31.204727306108,30.043222977757,0</coordinates></Point><address>40 Nadi EL Sayd St Giza Egypt</address><styleUrl>#0</styleUrl></Placemark><Placemark><name>Dokki Spareparts</name><description>&lt;div&gt;&lt;span class=&quot;l&quot;&gt;Short Number:&lt;/span&gt;&amp;nbsp;12311&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;l&quot;&gt;Phone:&lt;/span&gt;&amp;nbsp;(+2)33358686&lt;/div&gt;</description><Point><coordinates>31.21457336134,30.042570120257,0</coordinates></Point>
There's  new version of repl.bat out which adds an extra N option to handle files with NULL characters correctly.

`repl.bat` (by dbenham) - download from:  https://www.dropbox.com/s/qidqwztmetbvklt/repl.bat

This ADDRESSES your error - there's no need to escape the > inside the quotes.

Code: [Select]type "Cars French 1.kml" | repl "<address>" "\n<address>" xi >file.txt
and you might find this better for your usage:

Code: [Select]type "Cars French 1.kml" | repl "(</.*?>)" "$1\n" xi >file.txtI'm getting a "A device attached to the system is not functioning." error at lines 300 and 305.  Both at occurring when the script tries to run "WScript.Stdout.WriteLine(...)".  Any ideas?

Code: (Didn't WORK) [Select]type 1.kml | repl "address" "2address" mn
type 1.kml | repl "address" "\naddress" mxin
type 1.kml | repl "<address>" "\n<address>" mxin
type 1.kml | repl "<address>" "\n<address>" xin

Both 'type "Cars French 1.kml" | repl "()" "$1\n" xi >file.txt' and 'type "Cars French 1.kml" | repl " " "\n " xi >file.txt' returned files, but did not add the newline character.


EDIT: The last one added the newline char, but it only appears when viewing from preview in explorer.exe
EDIT 2: I managed to get it to work, but would still like to learn whats wrong. Quote from: Lemonilla on July 28, 2014, 10:03:14 AM

Both 'type "Cars French 1.kml" | repl "(</.*?>)" "$1\n" xi >file.txt' and 'type "Cars French 1.kml" | repl "<address>" "\n<address>" xi >file.txt' returned files, but did not add the newline character.

Yes, they do, but they don't add a CR and LF as I assumed you had a reason for using \n alone.

Change \n to \r\n and it will use normal Windows line endings.

Look at the output files in Winhex and you will see the 0A which is the \n character.

0A is the DEFAULT line ending character for Unix/Linux, and Windows uses 0D 0A as the line ending characters, a Carriage Return and then a Line feed. 
The 0D is added by the \r in repl.

In an Apple system the line ending is just a 0D or it used to be.

The 0D 0A is hexadecimal notation for anyone not sure, and is shown as 13 10 in decimal ascii.Thanks, I didn't know that.
895.

Solve : batch file coding help?

Answer»

Hi im not too familiar with coding in .bat files just in general i havent done coding in a long time not since my school days. Anyways ive GOT a batch file running that basically hosts a dedicated server for a game i play at the time being and since the games is still being developed theres some things that havent been put in yet.
Right well the batch file i have runs the dedicated server and people are connecting fine etc, i have it on a timer which restarts the server every so often, ive also managed to GET it to pop out a message but the issue is i cant get it to play a sound with it nothing spectacular of a sound just a sound which will get my attention so i know when the server will restart so therefore i can tell players on the server to log out before server automatically restarts? if anyone knows the coding for this it would be much appreciated thanks.

p.s i can also post the coding for the batch file i have at the moment if needed, could do with some opinions and tweaks etc cheers Here is a solution I had squirreled away from a post on a web site:

Code: [Select]echo off
set "file=c:\Windows\Media\Windows Shutdown.wav"
( echo Set Sound = CreateObject("WMPlayer.OCX.7"^)
  echo Sound.URL = "%file%"
  echo Sound.Controls.play
  echo do while Sound.currentmedia.duration = 0
  echo wscript.sleep 100
  echo loop
  echo wscript.sleep (int(Sound.currentmedia.duration^)+1^)*1000
) >"%temp%\sound.vbs"
start "" /min "%temp%\sound.vbs"
how would i IMPLEMENT that into this?

:loop
echo (%time%) Loot Resetting...
start /high Unturned.exe -nographics -pei -bambi -nosync -pve -port:25444 -pass:razorpanda -players:24 -sv
echo (%time%) Loot Reset.
echo (%time%) Server is online.
echo (%time%) Loot Resetting in 2 hours.
timeout /t 5400 >null
echo (%time%) Loot Resetting in 15 seconds
timeout /t 15 >null
echo msgbox "Server Restart 15 secs" > %tmp%\tmp.vbs
wscript %tmp%\tmp.vbs
del %tmp%\tmp.vbs
echo (%time%) Server is ONLINE! Watching for crash...
start sndvol.exe
start /high Unturned.exe -nographics -pei -bambi -nosync -pve -port:25444 -pass:razorpanda -players:24 -sv
echo (%time%) Server CRASHED/CLOSED. Restarting...

taskkill /f /im "Unturned.exe"

goto loop

thats my coding for the server i host though im trying to tweak it so that the button doesnt reset the server only warns me that theres 5 minutes etc and the sound to be played when the message pops outalso i tried changing the sound from shutdown to tada but it doesnt play?
nvm got it to change.
Ive got it to work in my own coding but just wondering if i can increase the volume ?

BTW MANY MANY THANKS cant emphasis how much this has helped Quote from: razorpanda on July 28, 2014, 08:43:19 AM

Ive got it to work in my own coding but just wondering if i can increase the volume ?

BTW MANY MANY THANKS cant emphasis how much this has helped

Bewdy. 

The volume depends on your current volume setting and I don't have a script to set a specific volume level.
oh ok thanks my systems volumes at max but the windows sound is still fairly quiet for the pop up meh its cool but again many many thanks Quote from: razorpanda on July 28, 2014, 09:30:35 AM
oh ok thanks my systems volumes at max but the windows sound is still fairly quiet for the pop up meh its cool but again many many thanks

Try a different sound file - some are recorded at lower level - and you can normalize the sound file with the free Audacity.

OTOH are your computer sounds normally low in volume?



Quote from: foxidrive on July 28, 2014, 09:45:28 AM
Try a different sound file - some are recorded at lower level - and you can normalize the sound file with the free Audacity.

OTOH are your computer sounds normally low in volume?

yea had a seperate sound file i USED much louder
Nope my computer sounds are always at 100% max and i can FREELY change it with my speakers as my mic doesnt pick up my speakers so i dont bother with a headset just now that i have it all working its fantastic and the help was great. Just wondering now if im able to inject some messages into the program it starts up which i heard it was done or someone was able to send messages from the CMD to the game so that all players in the dedicated server was able to see the message so i think thats my next step but no idea how >.<
896.

Solve : Fix WMI remotely with list of hostnames?

Answer»

I am trying to create a script that will scan through a list of hostnames, do an NSLOOKUP to confirm if hostname is bad or GOOD. if good then copy the WMIfix to remote pc, and go run it on each machine's cmd.

so far it seems to be working fine. it seems as if it is actually fixing the WMI of remote machines. but i determined that the WMIFIX bombs out at line 15. and then PSEXEC gives error code/exit of 255. Which means "errors exceeding 154 files". And then it does not run any further.

I would also like to be able to echo something in the main script to state that the WMIFIX has been run on remote pc.

this is the main script... fallouts.bat

Code: [Select]echo off
cls

:: **************************************************
::
:: Just grabs the machine names from a list and then
:: calls another subroutine, passing the name to the
:: routine.
::
:: **************************************************

:getName

  for /f %%a in (list.txt) do call :doIt %%a

  goto end

:: **************************************************
::
:: The %1 is the %%a from the previous routine. In this
:: case you get the machine name. It is being set
:: as a VARIABLE for ease of use in the rest of the
:: script.
::
:: So now you copy the file out to the system and
:: and verify it is there. The IF statement defines
:: a variable to be used for logging and to determine
:: whether or not to waste time running PSEXEC against
:: a machine where the file failed to copy.
::
:: So now we say if the var strFil = "ok", go ahead
:: and run PSEXEC. If not, then go log what you have
:: so far.
::
:: I would include some kind of error checking after
:: running REGSVR32 to verify the file was registered
:: and then log that as well.
::
:: **************************************************

:doIt

  set strSvr=%1
 
PING %1 -n 1| FIND /i "TTL" > nul && goto Success
PING %1 -n 1| FIND /i "timed" > nul && goto Timedout
PING %1 -n 1 -w 400 | FIND /i "TTL" > nul || goto ErrorMsg
goto :EOF

:Success
cls
echo Ping command was successful
echo Now we are setting the IP and HostName variable

for /F "tokens=3" %%a in ('ping %1 ^| find /i "TTL"') do set Address=%%a
for /F "tokens=2" %%a in ('ping -a %Address::=% ^| find /i "pinging"') do set HostName=%%a

set IPAddress=%Address::=%
cls
echo.
echo %1
echo %IPAddress%
echo %Hostname%
echo.
echo above is just to confirm that hostname,IP and FQDN is set
echo.
pause
cls
echo now we do a NSLOOKUP on the IPAddress collected from PING.
for /f "tokens=2" %%a in ('nslookup %IPAddress% ^| find /i "Name: " ') do set "nsNAME=%%a"
echo.
pause
cls
echo now we confirm that original hostname = FQDN
echo using NSLOOKUP details from previous commands
echo.
pause
cls
if "%nsname%"=="%Hostname%" (
set hnstatus="HOSTNAME is GOOD fix will be run"
) else (
set hnstatus="HOSTNAME is BAD we cannot do anything"
)
echo %hnstatus%
echo.
echo Hostname status above = GOOD or bad
echo if bad, then hostname resolves to different IP.
echo.
pause
cls

echo %strSvr%
echo just checking if we still have a machine name as a variable.

if "%nsname%"=="%Hostname%" (
echo f | xcopy /f /Y "c:\Temp\CM2014.2\ONLYWMI.bat" "\\%strSvr%\c$\Temp\CM2014.2\ONLYWMI.bat"
psexec \\%strSvr% c:\Temp\CM2014.2\ONLYWMI.bat
) else (
echo Hostname is bad cannot do anything
set hnstatusbad="Hostname is bad cannot do anything"
)
 
  goto logIt

:: **************************************************
::
:: LOGS ARE IMPORTANT!!
:: Get in the habit of logging the results of your
:: scripts. Verify the important pieces so you know
:: what has been completed and what you have to chase
:: down.
::
:: **************************************************

:Timedout
Echo %1, Request timed out.
Echo %1, Request timed out. >> fallouts_log.csv
goto :EOF

:ErrorMsg
Echo %1, Ping request could not find host.
Echo %1, Ping request could not find host. >> fallouts_log.csv
goto :EOF

:logIt

  echo.%strSvr%,%hnstatus%,%hnstatusbad%>>fallouts_log.csv
pause
:end

I got the original code somewhere on the internet, and REMOVED most of its stuff (except the comments) added the ping parts and NSLOOKUP parts.

here is the ONLYWMI.bat file.

Code: [Select]%windir%\system32\wbem\winmgmt /clearadap
%windir%\system32\wbem\winmgmt /kill
%windir%\system32\wbem\winmgmt /unregserver
%windir%\system32\wbem\winmgmt /reserver
%windir%\system32\wbem\winmgmt /resyncperf
net stop winmgmt /y
if exist %windir%\system32\wbem\repository.old RMDIR /s /q %windir%\system32\wbem\repository.old
rename %windir%\system32\wbem\repository %windir%\system32\wbem\repository.old
regsvr32 /s %systemroot%\system32\scecli.dll
regsvr32 /s %systemroot%\system32\userenv.dll
mofcomp %windir%\system32\wbem\cimwin32.mof
mofcomp %windir%\system32\wbem\cimwin32.mfl
mofcomp %windir%\system32\wbem\rsop.mof
mofcomp %windir%\system32\wbem\rsop.mfl
for /f %s in ('dir /b /s %windir%\system32\wbem\*.dll') do regsvr32 /s %s
for /f %s in ('dir /b /s %windir%\system32\wbem\*.mof') do mofcomp %s
for /f %s in ('dir /b %windir%\system32\wbem\*.mfl') do mofcomp %s
net start winmgmt
%windir%\system32\wbem\wmiprvse /regserver

then list.txt just contains a list of hostnames.

Code: [Select]computer1
computer2
computer3

I don't understand why it bombs out around line 15, which ends in .dll') do regsvr32 /s %s, and the last error before that is the syntax of the command is incorrect. and then Done!

any suggestions?%s in a for loop should be escaped to %%s.

897.

Solve : Combination Ping, NSLOOKUP and echo from txt file script?

Answer»

I am trying to ping a list of machines, do an nslookup on the ip addresses, then if hostname is same as original hostname, read from another txt file to output possible location of hostname.

this is my hh.bat script:
Code: [Select]echo Off
cls
if '%1'=='' GOTO Syntax
echo Running Script and Saving Results to Results.CSV
echo Script Run %date% %time% >> Results.csv
for /F %%i in (%1) do Call :StartPing %%i
goto :EOF

:StartPing
PING %1 -n 1| FIND /i "TTL" > nul &AMP;& goto Success
PING %1 -n 1| FIND /i "timed" > nul && goto Timedout
PING %1 -n 1 -w 400 | FIND /i "TTL" > nul || goto ErrorMsg

:Success
for /F "tokens=3" %%a in ('ping %1 ^| find /i "TTL"') do set Address=%%a
for /F "tokens=2" %%a in ('ping -a %Address::=% ^| find /i "pinging"') do set HostName=%%a

set IPAddress=%Address::=%
nslookup %IPAddress% | find /i "Name" do set nsNAME=


echo %1, %IPAddress%,%Hostname%
echo %1, %IPAddress%,%Hostname% >> Results.csv
goto :EOF

:Timedout
Echo %1, Request timed out.
Echo %1, Request timed out. >> Results.csv

:ErrorMsg
Echo %1, Ping request could not find host.
Echo %1, Ping request could not find host. >> Results.csv
goto :EOF

:Syntax
echo . . .
goto :EOF

:EOF
echo this is the END OF FILE
pause

and this is my host.txt file
Code: [Select]Computer1

and this is the list of locations - home.txt
Code: [Select]ipaddress - 2G
either ip or hostname... i don't know
hostname - 2D

i am struggeling to do the NSLookup part, and have no idea how to read from the home.txt once nslookup is successfull and echo on the location line.

any suggestions or ideas?These snippets may help you (untested):

Code: [Select]for /f "tokens=2" %%a in ('nslookup %IPAddress% ^| find /i "Name: " ') do set "nsNAME=%%a"
echo "%nsname%"
pause

Code: [Select]for /f "usebackq delims=" %%a in ("home.txt") do (
   echo "%%a"
)
pause
thank you for the reply.  Looks perfect.
however, upon testing... the second the script hits the NSLOOKUP part, it creates 1700+ processes, doing the Code: [Select]nslookup %IPAddress% ^| find /i "Name: " part.
I am running this script hh.bat host.bat Quote from: MadFly on July 28, 2014, 11:23:46 PM

thank you for the reply.  Looks perfect.
however, upon testing... the second the script hits the NSLOOKUP part, it creates 1700+ processes, doing the Code: [Select]nslookup %IPAddress% ^| find /i "Name: " part.
I am running this script hh.bat host.bat

If you are getting 1700 processes running then you have a loop that is neverending - quite possibly because you called your batch file nslookup or you have another problem in your code.  Post it here as you have changed it for PEOPLE to look at.



File is called hh.bat
and i run it in cmd like hh.bat host.bat.
everything works fine without the nslookup part. once nslookup lines are active and uncommented and the script hits it, processes goes up from 390, 1700 or even 3500 sometimes.

Code: [Select]echo off

if '%1'=='' GOTO Syntax
echo Running Script and Saving Results to Results.CSV
echo.
echo Script Run %date% %time% >> Results.csv
for /F %%i in (%1) do Call :StartPing %%i
goto :EOF

:StartPing
PING %1 -n 1| FIND /i "TTL" > nul && goto Success
PING %1 -n 1| FIND /i "timed" > nul && goto Timedout
PING %1 -n 1 -w 400 | FIND /i "TTL" > nul || goto ErrorMsg

:Success
for /F "tokens=3" %%a in ('ping %1 ^| find /i "TTL"') do set Address=%%a
for /F "tokens=2" %%a in ('ping -a %Address::=% ^| find /i "pinging"') do set HostName=%%a

set IPAddress=%Address::=%
echo %1, %IPAddress%,%Hostname%
pause
for /f "tokens=2" %%a in ('nslookup %IPAddress% ^| find /i "Name: " ') do set "nsNAME=%%a"
echo "%nsname%"
pause

:: Get Location of machine
cls
:: replace tokens=3 with delims= to get the whole line
for /f "usebackq tokens=3" %%a in ("home.txt") do (
   echo "%%a"
)
pause
echo %1, %IPAddress%,%Hostname% >> Results.csv
goto :EOF

:Timedout
Echo %1, Request timed out.
Echo %1, Request timed out. >> Results.csv

:ErrorMsg
Echo %1, Ping request could not find host.
Echo %1, Ping request could not find host. >> Results.csv
goto :EOF

:Syntax
echo . . .
goto :EOF

:EOF
echo this is the END OF FILE


There is a system command called hh so pick another name, but that isn't the issue.

Do you have a set of computer names in host.bat or IP addresses? 
When using IP addresses it works, but using computer names it fails because the ping command doesn't include "TTL=" even though it is successful - which is a new behaviour on me.  Tested with the localhost in Windows 8.1 and it uses IPV6 in the ping SCREEN display.

Your code is missing a goto :EOF here and there and FWIW the :EOF label is internal to CMD and isn't needed in the batch script.


TRY this code - using a simple home.txt file with

Code: [Select]a b reading
c d file

and in your hosts.bat just include a few computer names, and try it with a few IP addresses as a test too.
Show us what it displays on the console if it still misbehaves.

Make sure there are no ping.bat or nslookup.bat in the current directory or on the path.  I didn't notice a problem with extra processes.

Code: [Select]echo off

if "%~1"=="" GOTO Syntax
echo Running Script and Saving Results to Results.CSV
echo.
echo Script Run %date% %time% >> Results.csv
for /F %%i in (%1) do Call :StartPing %%i
goto :EOF

:StartPing
PING %1 -n 1| FIND /i "TTL" > nul && goto Success
PING %1 -n 1| FIND /i "timed" > nul && goto Timedout
PING %1 -n 1 -w 400 | FIND /i "TTL" > nul || goto ErrorMsg
goto :EOF

:Success
for /F "tokens=3" %%a in ('ping %1 ^| find /i "TTL"') do set Address=%%a
for /F "tokens=2" %%a in ('ping -a %Address::=% ^| find /i "pinging"') do set HostName=%%a

set IPAddress=%Address::=%
echo %1, %IPAddress%,%Hostname%

for /f "tokens=2" %%a in ('nslookup %IPAddress% ^| find /i "Name: " ') do set "nsNAME=%%a"
echo "%nsname%"


:: Get Location of machine
:: cls
:: replace tokens=3 with delims= to get the whole line
for /f "usebackq tokens=3" %%a in ("home.txt") do (
   echo "%%a"
)

echo %1, %IPAddress%,%Hostname% >> Results.csv
goto :EOF

:Timedout
Echo %1, Request timed out.
Echo %1, Request timed out. >> Results.csv
goto :EOF

:ErrorMsg
Echo %1, Ping request could not find host.
Echo %1, Ping request could not find host. >> Results.csv
goto :EOF

:Syntax
echo . . .
goto :EOF
Interesting. Thank you for the feedback and updates.
will test in the morning once i am back at the office again.

i'll rename the main hh script to something very random.
and apologies, there isn't any host.bat, it should have been host.txt...

hh.bat -> to be renamed to qwe.bat = contains main script
host.txt -> just a list of computer names
home.txt -> ip addresses - office location (eg. 172.16.1.55 - Reception)

Quote from: foxidrive on July 30, 2014, 02:10:27 AM

Try this code - using a simple home.txt file with

Code: [Select]a b reading
c d file
Excellent! 

script is working like a charm.
can now even put a if state to tell me if hostname is bad or good, as well as location.

Just excellent stuff!

Thanks a million!one other issue I have picked up is when the script reaches the get location part...

Code: [Select]for /f "usebackq tokens=3" %%a in ("home.txt") do (
   echo Your machine is located at "%%a"
)
cls
echo "%%a"

it echos out every line in the home.txt, instead of only looking for the specified IP address in home.txt and echo only the location

home.txt looks like this...

Code: [Select]172.16.4.15 - Reception
172.16.5.155 - Server Room

It should only echo either the entire line where it finds the IP or only the Reception or Server Room part.
any suggestions on this?Instead of this:

Code: [Select]:: Get Location of machine
:: cls
:: replace tokens=3 with delims= to get the whole line
for /f "usebackq tokens=3" %%a in ("home.txt") do (
   echo "%%a"
)

Try this: (untested)

Code: [Select]:: Get Location of machine
:: cls
findstr /b/e  "%~1" "home.txt"
Thank you for the reply.
i have added your suggested code as suggested, but how do i echo from that findstr command?
or how can i put the result of findstr in some variable?It already echos it to the console, and you can get the information into a log file like this, if that is what you want to do.

Code: [Select]findstr /b/e  "%~1" "home.txt" >>"file.log"when i put it just as is then my command line tells me
FINDSTR: // ignored

that could be because i have 2 hostnames in host.txt.
however, when removing 1 hostname from host.txt it does not echo anything out.Test it with the extra lines below and tell me what was echoed when the error appears on the screen.

It seems like the %~1 term has slashes in it.

Code: [Select]echo "%~1"
findstr /b/e  "%~1" "home.txt" >>"file.log"
pause
it only echos out the hostname found in host.txt

Code: [Select]Computer1, 172.16.4.115,computer1.localdomain.net
HOSTNAME is GOOD
"Computer1"
FINDSTR: // ignored
Press any key to continue . . .
898.

Solve : batch file to give the output of programs and features with name, version detail?

Answer»

Hi ,

Can anyone GUIDE me, in CREATING a barch file.
Which will search for Programs and features of every system and give me the details of nam and version of proframs and features installed.

Basically i want to capture all the data of programs and features in to and xml file.

We can use command appwiz.cpl also, to directly go to the desired patha nd then capture all the data.

Thanks in advance.
You cannot use xml files with BATCH, look into VBscript or Jscript.Logic will be in batch file and then redirecting the output in xml file.

this can be using batch file.

To run this batch file BAGROUND, i will call batch via VB script.

Then my purpose will be solved.

So i just need the logic, to capture the output of appwiz.cpl/ program files Quote from: Aditi gupta on August 06, 2014, 09:55:20 PM

So i just need the logic, to capture the output of appwiz.cpl/ program files
Can't be done with batch. Quote from: Aditi gupta on August 06, 2014, 09:55:20 PM
To run this batch file baground, i will call batch via VB script.
Then why didn't you search GOOGLE for a Vbscript solution.  Here is what I found.
http://www.vbsedit.com/scripts/apps/user/scr_226.asp
899.

Solve : I need a turn system?

Answer»

With my saving problem fix. I need a turn system for my game that I am in the middle of and it needs a turn system for it work. Any help I will try
Thanks a million
You need to turn a system? What does that mean? And what do you mean your "saving problem fix"?

If English isn't your first language that's fine, we're happy to work with you - but I really don't understand what you're trying to say.What I mean is a turn system like the civilization games and ignore that part about the saving stuffMaybe he wants to implement a scheme for different players to take turns?

Shiverbob, you MUST TRY HARDER to be clear.

1 player it is a city builder game. Everything take turns research building Clear as mud...He can use Google Translate.
https://translate.google.com/this is what I meant it 1 player. There are no others. The game runs like civ and the building and the research all the this many turns. I have no idea how to make a turn system where things count down until that many turns are done and your building or research are done. I will try to post the code tomorrow and btws I born in kansas. I can't spell well.  My thoughts on this are that its best to learn a programming language and process a turns counter in which if the number of turns reaches certain intervals you can trigger other events to happen in the game. You could even have an Easy, Normal, and Hard Mode in which the easy mode gives more turns before events trigger that are likely events that are bad that you have to fend off a problem ETC, and normal mode having fewer turns than easy for the initial construction period, and hard mode being even fewer turns in which you really need to know what to make in what order to be able to sustain against the attack etc.

Curious as to this games visual construction.... in batch etc?

Are you happy with it being an ASCII based character constructed game or will you be creating a real graphics generated game which can be done in a number of many languages out there such as C or C++ or even simpler to call bit maps from within the code vs constructing each pixel placement etc?

I'd suggest not doing this in batch unless you are doing this as a fun way to strengthen your skills in batch, however the limitations of batch may be frustrating.

I have made games before in batch and hit walls that otherwise wouldnt have HAPPENED in creating the game within a true IDE such as C or C++.

If you are working with a DOS system even QBasic offers much more than Batch alone. Also the cool thing about QBasic is that if you know the older line number Basic programming you can code in QBasic in a legacy format of what normally would have been in GW-Basic format and the games will run. However if wanting to make a modern like game, I'd suggest C++.

If you are not good at creating graphics, another method of making turn based games is to make the game with HTML and a Scripting language such as Java Script, in which the Javascript handles the logic and the browser is used to display HTML web pages with text and pictures, in which you can create or use already created pictures called thru the javascript to display. Many Many turn based online games have this same layout of dynamic text and images that are called to FILL the browser window, however they go beyond JavaScript which is ( Local ) logic and the logic instead is server side of the web server SERVING up the dynamic web page to the many connected players with player accounts.

For the fact that you seem to be part way through a project I am eagerly awaiting your construction methods and execution of this game that you are making.
I believe he's looking to create a turn based game, such as chess.  The thing he's having difficulty with is a turn counter, which would count down the turns until something happens.  Here would be an example of how I would do this:

Code: [Select]set turn=0

:turn_start
set /a turn+=1
REM This is the playable turn



REM this is the AI part



if %turn% EQU %VAL% REM something happens
goto :turn_start
where VAL is the turn number that the thing would happen on.Thanks but that's not the problem. I don't know how to make it where if you click next turn everything counts down until however long it said it would take it would be done or build.
My game just needs a turn system to work. Its kinda like civ but it is one player and no ai. You start with one building and you build stuff from there and you progess by researching and building stuff. I am tyring to help u guys understand but I don't know how to explain it. And I really don't want to make it with javasrcipt and html. Plus I don't want to learn anything NEW right now. My little head can't take much more.


If I did the "if" command and have set the build times in the place where you build stuff it wouldn't work because it says if "%libbt%" == "5" (
set /a libbt-=1
)
if "%libbt%" == "4" (
set /a libbt-=1
) it wouldn't work because it would just go down then in one turn instead of five you would have a libarytry reversing the order,
Code: [Select]if "%libbt%" == "4" set /a libbt-=1
if "%libbt%" == "5" set /a libbt-=1
That will make only the last one true, or you can make an if else tree:
Code: [Select]if "%libbt%" == "5" (
set /a libbt-=1
) else (
if "%libbt%" == "4" (
set /a libbt-=1
) else (
if "%libbt%"=="3" (
set /a libbt-=1
)
)
)
Thanks I didn't know you could do the else tree. But it work thanks everyone

900.

Solve : A batch based profile manager GUI?

Answer»

Hello all I have decided to BRUSH up on my batch skills a bit and do something new to make me think a bit; so im just gonna share the experience with you guys as I go about it. Although im already a quarter of the way done (mabey)

Below is the code I have completed so far. Feel free to see if there is anything you have seen before and comment on below.

Code: [Select]Echo off
:start
mkdir "%appdata%\Millergram Morrowind Profile Manager"
mkdir "%appdata%\Millergram Morrowind Profile Manager\Profiles"
set Prf=%appdata%\Millergram Morrowind Profile Manager\Profiles
set dtr=%appdata%\Millergram Morrowind Profile Manager\Data
cls
Rem By Millergram

Title DIY Morrowind Profile Manager

Rem These Lines Check for A config file listing current profiles and creates one if does not exist

pushd "%dtr%"
if not exist Profiles.cfg (
Echo.>Profiles.cfg)
popd

Rem These lines check for a Save game directory config file and creates one with user input if does not exist

Echo.Type Your savegame directory below example (D:\Morrowind\Saves)
if not exist Savedir.cfg (
set /p svgdir=Save game directory in quotes or default=) Else goto body
set dir=%svgdir%
if /i "%svgdir%"=="" goto start
if /i "%svgdir%"=="default" set dir="%programfiles%\Bethesda Softworks\Morrowind\Saves"

Rem this line CHECKS to see if user specified directory has any savegames if not displays message

cls
pushd %dir%
if not Exist *.ess (Echo.There Seems to be no savegames here is that Ok?) Else Goto DirCheck
set /p inp=[Y/N]:
if /i "%inp%"=="Y" goto DirCheck
if /i "%inp%"=="N" goto start
if /i "%inp%"=="Yes" goto DirCheck
if /i "%inp%"=="No" goto start

Rem This line checks to see if users specified directory is true if not displays error message and returns to start

:DirCheck
cls
popd
pushd %dir%
popd
if %ERRORLEVEL%==0 goto body else Echo Directory Not found!
pause
goto start
:body
pushd "%dtr%"
if not exist Savedir.cfg (Echo %dir%>Savedir.cfg) Else (for /F "Tokens=*" %%c in (Savedir.cfg) do set dir=%%c)
cls
popd
Rem These Lines speficify parsing variables

set B=
set C=

Rem These Lines List Current Profiles

Echo.To get profile list again type "List"
Echo.For a list of commands type "Help"
Echo.Known profiles are as listed below.
Echo.
for /F "tokens=*" %%a in (Profiles.cfg) do echo %%a

Rem This line prompts user for commands

set /p ent=:

Rem These lines parses commands into Temporary tokens

:parsing
pushd "%dtr%"
del ent.cfg
Echo.%ent%>>ent.cfg
TIMEOUT -T 1 -Nobreak>nul
for /F "eol=  tokens=1,*" %%g in (ent.cfg) do (
set B=%%g) & (
set C=%%h)
popd

Rem These lines use above specified variables to desern witch command was prompted by the user

if /i "%B%"=="load" goto load
if /i "%B%"=="create" goto create
if /i "%B%"=="update" goto update
if /i "%B%"=="del" goto delete
if /i "%B%"=="list" goto list
if /i "%B%"=="help" goto help
if /i "%B%"=="whois" goto whois
if /i "%B%"=="RAGEQUIT" goto ragequit

Rem These lines "clean up" user input

if /i "%B%"=="" goto body
if /i "%B%"=="%B%" goto error

Rem These lines are the help script

:help
pushd "%dtr%"
del ent.cfg
popd
cls
Echo.To load a profile into the Saves directory type
Echo."load [insert profile NAME here]"
Echo.
Echo.To create a new profile type "Create [Insert Profile Name]"
Echo.
Echo.To use the currently loaded character under a specified
Echo.profile name type "Update [Insert profile here]"
Echo.
Echo.To delete a profile type "del [Insert profile here]"
Echo.
Echo.To display the profile that is currently in use type "whois"
Echo.
Echo.!!WARNING!! To destroy all profiles and saves type
Echo."RageQuit"
Echo.Note no Ctrl-z possiable
Echo.
Echo.To display this help section type "Help"
Pause
goto body

Rem These lines is the error display for incorrect commands

:error
pushd "%dtr%"
del ent.cfg
popd
echo.Not a known command. Type "help" for options!
pause
goto body

Rem these lines are the create script

:create
pushd "%dtr%"
Echo.%C%>Profiles.cfg
mkdir "%C%"
popd
pushd "%ptr%"
Echo.%C%>"%C%.cfg"
Echo."%C%" was created
Echo.Profile can now be loaded
popd
pause
pushd "%dtr%"
del ent.cfg
popd
goto body

Rem These lines are the load script

:load
robocopy "%dtr%\%C%" %dir% MOVE

I decided to make a profile manager for morrowind cause I don't have one, even though I could easily download one. 

The main problem thats stumping me right now is how to check for multiple instances of the same profile being made and display an error message warning the user, and Knowing what profile is currently loaded (I think I may have a solution for this)

A solution to checking for multiple instances of a profile could likely be solved with a for command likely resembling this

Code: [Select]For /F "Tokens=*" %%i In ('findstr /B /ON [A text file containg a list of all made profiles]') do (Echo.%%i>%%i)
Something like that i'm really not sure

If you have suggestions I'm happy to hear them. 
Thanks ahead of time.Profiles.cfg is where all profiles are stored, correct?

What format is the data inside the file?   Can you include a sample list here in code tags?Profiles.cfg is not in any particular format it is simply a plain text document listing all profiles in the order they were created