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.

951.

Solve : batch file data to email?

Answer»

I need a batch file which will search folders in this path
D:\users\alenkat\Users\Documents
D:\users\majag\Users\Documents
D:\users\toniz\Users\Documents
D:\users\juref\Users\Documents
D:\users\jakau\Users\Documents
D:\users\janezf\Users\Documents
D:\users\mihar\Users\Documents

and if there is no file
24.10.2014--datet.txt

it will send me an email with paths where that file doesn't EXIST

for sexample, here batch didn't find file 24.10.2014--datet.txt
D:\users\jakau\Users\Documents
D:\users\janezf\Users\Documents
D:\users\mihar\Users\Documents
and will send email with this in it

I list here just a fev folders I have it alot more
file 24.10.2014--datet.txt is changing every day so it should search for *.datet.txt







Batch has no native way to send email. You will EITHER have to use a third party utility to send the email or use vbscript.try this untested code:
Code: [Select]echo off
set "email="

if not exist D:\users\alenkat\Users\Documents\*datet.txt echo D:\users\alenkat\Users\Documents >>tmp.txt
if not exist D:\users\majag\Users\Documents\*datet.txt echo D:\users\majag\Users\Documents >>tmp.txt
if not exist D:\users\toniz\Users\Documents\*datet.txt echo D:\users\toniz\Users\Documents >>tmp.txt
if not exist D:\users\juref\Users\Documents\*datet.txt echo D:\users\juref\Users\Documents >>tmp.txt
if not exist D:\users\jakau\Users\Documents\*datet.txt echo D:\users\jakau\Users\Documents >>tmp.txt
if not exist D:\users\janezf\Users\Documents\*datet.txt echo D:\users\janezf\Users\Documents >>tmp.txt
if not exist D:\users\mihar\Users\Documents\*datet.txt echo D:\users\mihar\Users\Documents >>tmp.txt

:: Since batch does not support email, you will have to DOWNLOAD a 3rd party app to do it.
:: The paths are in the text file tmp.txtI have tested and works great bmail
http://retired.beyondlogic.org/solutions/cmdlinemail/cmdlinemail.htm Quote from: Lemonilla on October 25, 2014, 01:51:53 PM

try this untested code:
Code: [Select]echo off
set "email="

if not exist D:\users\alenkat\Users\Documents\*datet.txt echo D:\users\alenkat\Users\Documents >>tmp.txt
if not exist D:\users\majag\Users\Documents\*datet.txt echo D:\users\majag\Users\Documents >>tmp.txt
if not exist D:\users\toniz\Users\Documents\*datet.txt echo D:\users\toniz\Users\Documents >>tmp.txt
if not exist D:\users\juref\Users\Documents\*datet.txt echo D:\users\juref\Users\Documents >>tmp.txt
if not exist D:\users\jakau\Users\Documents\*datet.txt echo D:\users\jakau\Users\Documents >>tmp.txt
if not exist D:\users\janezf\Users\Documents\*datet.txt echo D:\users\janezf\Users\Documents >>tmp.txt
if not exist D:\users\mihar\Users\Documents\*datet.txt echo D:\users\mihar\Users\Documents >>tmp.txt

:: Since batch does not support email, you will have to download a 3rd party app to do it.
:: The paths are in the text file tmp.txt

Thanks, I already MAKE this, but I can't add in batch 100 lines for 100 folders for every user and adding a NEW one everytime I add user to backup.

So batch need search folders and add result to one file which can be sended with bmailSo you want to check D:\users\*\users\documents then?  If so look at the command for /r.still have no clue how to put that search into one txt fileThis untested: 

Just a comment here that some social lubrication is nice in a forum, so you could add a thank you to the people that have replied
even if you only add "still have no clue how to put that search into one txt file".

Code: [Select]echo off
for /d %%a in ("d:\users\*") do (
   if not exist "%%a\Users\Documents\*--datet.txt" >>"file.log" echo Missing: "%%a\Users\Documents\*--datet.txt"
)
pause
thank you for helping.
After 3 hours of trying to make a batch I write that last post.
I really appreciate all help from all of you.

Your batch works perfect, like always. thank you again
952.

Solve : How to merge images using gdal-merge and cmd(.bat file)?

Answer»

I'm new to these batch thing and I badly need your help. There are 4 to 5 projected IMAGES in one DAY. Let's say I have all the projected images for 3 days. For day 1, the file name are:

T2010232034000.L2.Tera.tif
T2010232035000.L2.Tera.tif
T2010232036000.L2.Tera.tif
T2010232037000.L2.Tera.tif

For day 2, the file name are:

T2010233045000.L2.Tera.tif
T2010233046000.L2.Tera.tif
T2010233047000.L2.Tera.tif
T2010233048000.L2.Tera.tif
T2010233049000.L2.Tera.tif

For day 3, the file name are:

T2010234050000.L2.Tera.tif
T2010234051000.L2.Tera.tif
T2010234052000.L2.Tera.tif
T2010234053000.L2.Tera.tif
T2010234054000.L2.Tera.tif

How will I MERGE all the images that are for day 1, for day 2 and for day 3 and save each merged images to a new directory LEAVING only the T/datayear/juliandate as the filename for each day. Merging files is easy but doing it in batch and merging based on the images per day is making me crazy.

Note: T2010232034000 = Terra/Data Year/Julian Date/HH/MM/SS

Here is the script I used in merging the files:

gdal_merge.py -n 0 -a_nodata -32767 -of GTiff -o output_directory input_directory_in1.tif input_directory_in2.tif input_directory_in3.tif input_directory_in4.tif/input_directory_in5.tif


Also posted on DosTips
http://www.dostips.com/forum/viewtopic.php?f=3&t=6007

953.

Solve : closing program with alt+f4?

Answer»

I have one updating software which updates 5 programs.
But problem is because it stays opened when it is finished, I can close it with button close or with alt+F4.
If I use taskkill than it will close this updating software befor it finish updating but now alt+F4 I can press it before it finished updating and it will continue updating and when it is finished than it will accept alt+F4.
So how to use in batch file alt+F4?

I TRIED this vbs script but it does the same like taskkill it stops updating.

Code: [Select]Set WshShell = WScript.CreateObject("WScript.Shell")

' Start Notepad.exe
WshShell.Run "%windir%\notepad.exe"

' Select, or bring Focus to a window named `Notepad`
WshShell.AppActivate "Notepad"

' Wait for 4 seconds
WScript.Sleep 4000

WshShell.SendKeys "Foo"
WshShell.SendKeys "{ENTER}"
WshShell.SendKeys "BAR"
WshShell.SendKeys "{ENTER}"
WshShell.SendKeys "{CAPSLOCK}"
WshShell.SendKeys "baz"
WshShell.SendKeys "%{F4}"Sorry forget about this, it close updating software anyway when I press alt+F4 buttons.

Only if it is possible to use closing taskkill when button CLOSE appear?

Or if it is possible to close when it is Zero on CPE for about 10 seconds?

I tried this and not working, it close application no mather if CPU is 3%

Code: [Select]echo off

set "process_name=notepad.exe"

::remoce .exe SUFFIX if there is
set pn=%process_name:.exe=%

setlocal enableDelayedExpansion

set c=0
:: getting three snapshots of CPU usage of the given process
for /f skip^=2^ tokens^=3^ delims^=^" %%p in ('typeperf "\Process(%pn%)\%% Processor Time"  -sc 3') do (
    set /a counter=counter+1
    for /f "tokens=1,2 delims=." %%a in ("%%p") do set  "process_snapshot_!counter!=%%a%%b"

)

:: remove rem to see the cpu usage from the three snapshots
rem set process_snapshot_

:: if all three snapshots are less than 0000010 process will be killed
if 1%process_snapshot_1% LSS 10000010 if 1%process_snapshot_2% LSS 10000010 if 1%process_snapshot_3% LSS 10000010 (
     tskill %pn%
) Quote from: BLISK on October 29, 2014, 02:50:20 AM

I have one updating software which updates 5 programs.
But problem is because it stays opened when it is finished

This can be done with a single command probably.
Do you use a batch file to start this program?  Show us the code here so we don't have to guess what is being done.no, it is a update.exe file when I run it, it opens a window and update programs one by another at the end when It finishes it shows up button CLOSE. I run it over task scheduler and problem is because if that program is opened I can not run it again to update until I press CLOSE button on it. Quote from: Blisk on October 29, 2014, 10:23:12 AM
no, it is a update.exe file when I run it, it opens a window and update programs one by another at the end when It finishes it shows up button CLOSE. I run it over task scheduler and problem is because if that program is opened I can not run it again to update until I press CLOSE button on it.

It looks like it isn't a command line program, but a GUI program.

There isn't enough information about the task - I was assuming it was a command line program running from a batch file because you wanted to automate the closing of the window.

It helps to provide relevant details about the task in the first post, so that your readers can understand what it is that you are doing and how it operates.  Otherwise we have to use our crystal balls, and mine's at the mechanic for it's 6 month overhaul.yes, sorry I thought I explained good what program is. Yes it is gui and problem is updating again not working until first instance is closed.
954.

Solve : Rename first file with structure name.?

Answer»

Hi All,

I have one folder with a lot of files, all them use same structure NAME example (bird_happy_1234.txt, bird_happy_1235.txt,bird_happy_1236.txt) only _1234 change.
I need to rename only the first one and them move this file to another folder.
The new name its the same EVERY time because this i want to move to another folder after i rename.
After a renamed the file i know its not a problem to move because the file have same name every time.

Best regards,
                  DiogoI have this solution right now its work.

Code: [Select]for /F %%i in ('dir /b/a-d/od/t:c') do set LAST=%%i
move /-y "C:\Users\Diogo\Desktop\Tests_Batch\%LAST%" "C:\Users\Diogo\Desktop\Tests_Batch\Processed"
copy /-y "C:\Users\Diogo\Desktop\Tests_Batch\Processed\%LAST%"  "C:\Users\Diogo\Desktop\Tests_Batch\Importing"
del C:\Users\Diogo\Desktop\Tests_Batch\Importing\imp_t.txt
rename C:\Users\Diogo\Desktop\Tests_Batch\Importing\%LAST% imp_t.txt
call "C:\Users\Diogo\Desktop\Tests_Batch\Test.bat"

But i have one issue, when my folder its empty from .txt files the code copy the .bat file.Try this:

Code: [Select]for /f %%i in ('dir /b/a-d/od/t:c') do set LAST=%%i
if not "%LAST%"=="%~nx0" (
move /-y "C:\Users\Diogo\Desktop\Tests_Batch\%LAST%" "C:\Users\Diogo\Desktop\Tests_Batch\Processed"
copy /-y "C:\Users\Diogo\Desktop\Tests_Batch\Processed\%LAST%"  "C:\Users\Diogo\Desktop\Tests_Batch\Importing"
del C:\Users\Diogo\Desktop\Tests_Batch\Importing\imp_t.txt
rename C:\Users\Diogo\Desktop\Tests_Batch\Importing\%LAST% imp_t.txt
call "C:\Users\Diogo\Desktop\Tests_Batch\Test.bat"
)
If it doesn't work, add 'echo %LAST%' to the END and post what it says.  %~0 will need to be formatted the same way for the EXCLUSION to work.Hi, your code help me change the old one, i used one more folder and when this folder empty i used if not.
Thx very much!

final code:
Code: [Select]for /f %%i in ('dir C:\Users\Diogo\Desktop\Tests_Batch\Incoming\*.txt /b/a-d/od/t:c') do set LAST=%%i
if not "%LAST%"=="" (
move /-y "C:\Users\Diogo\Desktop\Tests_Batch\Incoming\%LAST%" "C:\Users\Diogo\Desktop\Tests_Batch\Processed"
copy /-y "C:\Users\Diogo\Desktop\Tests_Batch\Processed\%LAST%"  "C:\Users\Diogo\Desktop\Tests_Batch\Importing"
del C:\Users\Diogo\Desktop\Tests_Batch\Importing\imp_t.txt
rename C:\Users\Diogo\Desktop\Tests_Batch\Importing\%LAST% imp_t.txt
)

955.

Solve : rename a directory whit the command move?

Answer»

hello all, i have a work to do in my class and one of the TASK is to rename the directory (fantasme) for (reve) but whit what i know in ms-dos 6.22 i can just change the name whit the COMMANDE move or xcopy.

if you can help me to find the ERROR in my batch file or a other METHODE to do the same task, i will linsten your advice.

thanks

(sorry for my bad english)

[attachment DELETED by admin to conserve space]From Our Archives...

956.

Solve : batch file sends mail after zipping?

Answer»

Hi i am totally new to the Batch file concept.

I have created a batch file which zip the sever logs month wise and then delete those logs. But when i delete that zip file, my batch file will send a mail on my ID.

So if any changes needed to be done please do suggest.

Thank you.

This is my code:-



echo off

rem Findout Month, Year and DATE
FOR /F "tokens=1,2,3,4 delims=/ " %%A in ('Date /t') do set year=%%D
FOR /F "tokens=1,2,3,4 delims=/ " %%A in ('Date /t') do set month=%%B
FOR /F "tokens=1,2,3,4 delims=/ " %%A in ('Date /t') do set day=%%C

rem Solve problem Year start and adding 0 in month
if %month% EQU 01 (
   set month=12
   set /a year=%year%-1
) else (
   set /a month=%month%-1
)
if %month% LSS 10 set month=0%month%

rem Set file names for last month file.
set lastmonthfiles=server.log.%year%-%month%-

rem To compress the file.
:compress
"C:\Program Files\7-Zip\7z.exe" a -y "bkp-%lastmonthfiles%.zip" %lastmonthfiles%*
ping -n 15 192.168.100.44 > nul
if Not exist bkp-%lastmonthfiles%.zip (
   echo zipping failed
   pause
   CALL mail2.bat
   )
else 
(
 DEL %lastmonthfiles%*
)

This is the code for mail2.bat file. I have used bmail into it.

bmail -s karina -t [email protected] -f [email protected] -h -a backupPlease do not post the same question more than once. I deleted the duplicates.I think that this should handle the date issue in a region insensitive way: not tested

Code: [Select]echo off
for /f "tokens=2 delims==" %%a in ('wmic OS Get localdatetime /value') do set "dt=%%a"
set "YYYY=%dt:~0,4%" & set "MM=%dt:~4,2%" & set "DD=%dt:~6,2%"

if "%MM%"=="01" (set /a YYYY=YYYY-1 & set "MM=12") else (set /a MM=1%MM% - 1)

set lastmonthfiles=server.log.%YYYY%-%MM:~-2%-
actually Allan the SCRIPT you deleted was the different. I asked about how to send mail from my batch file if zipping fails. And into new script i did mentioned that the file which i have created is sending the mails if zipping get fails. But still thanks

957.

Solve : Batch: convert text file to CSV?

Answer»

I have 11 plain text files which I want to open up in Excel.  Each file has a different record type and different record length with the following attributes:

fixed column length
no blank lines in the files
no delimiters
trailing spaces in some or all of the files

When I open up the files in Excel, I have to go through the tedious task of using the wizard to define the columns.  Would be nice to be able to convert the files into comma quoted ahead of time, that way Excel opens up with each column already defined.  Column headers are not necessary.

I am writing a batch to put double quotes, comma, and more double quotes in-between each of the columns, with one double quotes at the beginning and one double quotes at the end.  I have tested successfully with 7 columns so far.  I wanted to get your thoughts before continuing with the syntax for the rest of the columns.

Is there a limit to the number of bytes that can be included in one command/statement?  The file I have with the most number of columns to define is 50.  This is going to make the syntax extremely long.

Example input records from one file:
Code: [Select]AB012345AC    201399Long name                     55555198900006589673101N008500000008200979999999999900015294260999999999999999         
AB012345ABC   201399Another long name             11111194500000012023203N000313200001840909999999999900000260524999999999999999         
AB012345ABCD  201399three times                   33333199600003609819104N004265000008000979999999999900005823119999999999999999         

I want the output to be like this, for example:
Code: [Select]"AB","012345","AC    ","2013","99","Long name                     ","55555","1989","0000658967","31","01","N","00850000","00082","0097","999999","99999","0001529426","0","999999999999999","          "
"AB","012345","ABC   ","2013","99","Another long name             ","11111","1945","0000001202","32","03","N","00031320","00018","4090","999999","99999","0000026052","4","999999999999999","          "
"AB","012345","ABCD  ","2013","99","three times                   ","33333","1996","0000360981","91","04","N","00426500","00080","0097","999999","99999","0000582311","9","999999999999999","          "

Here is the batch code:
Code: [Select]echo off
setlocal EnableDelayedExpansion
cd/d c:\download
if ErrorLevel 1 (
cls
echo ---------------------------------------------
rem
echo ERROR  ERROR  ERROR
echo Folder "c:\download" not found
echo Press a key to close this window and stop the program.
rem
echo ---------------------------------------------
pause
goto FINISH
)

if exist test1.csv del test1.csv
set single_quote="
set quotes=","
for /f "delims=" %%A in (myfile1.TXT) do (
set partial=%%A
set newstring=%single_quote%!partial:~0,2!%quotes%!partial:~2,6!%quotes%!partial:~8,6!%quotes%!partial:~14,4!%quotes%!partial:~18,2!%quotes%!partial:~20,30!%quotes%!partial:~50,5!%single_quote%
echo !newstring!>> test1.csv
)
start "" test1.csv

:FINISH
exit

Note:  in the code I have defined only 7 columns so far, as stated above, whereas in the example input records I have listed the entire line of one of the input files.
Thanks in advance.Yes there is a character limit for the SET command.  I can't recall what it is.  I bet if you programmed up a SIMPLE FOR /L loop you could find out what it was. Thanks for your reply.  I'm racking my brain trying to figure out how the /L parameter will result in a long line of syntax for a command.  Can you please provide an example?This should hit the number.

Code: [Select]echo off
setlocal EnableDelayedExpansion
for /l %%A in (1,1,1000000000000000000) do (
set last=!a!
set a=!a!0
if "!last!"=="!a!" echo %%A
if "!last!"=="!a!" pause
)

EDIT: Warning it will take a LONG time.It's been running for 3.5 hours with nothing on the screen but the blinking cursor.  I am leaving work now, so I am pressing Ctrl+C.  I am not concerned about the output being too long; just the amount of characters it takes to make up/create a set command or any other command, like so:

Code: [Select]set newstring=%single_quote%!partial:~0,2!%quotes%!partial:~2,6!%quotes%!partial:~8,6!%quotes%!partial:~14,4!%quotes%!partial:~18,2!%quotes%!partial:~20,30!%quotes%!partial:~50,5!%quotes%!partial:~20,30!%quotes%!partial:~20,30!%quotes%!partial:~20,30!%quotes%!partial:~20,30!%quotes%!partial:~20,30!%quotes%!partial:~20,30!%quotes%!partial:~20,30!%quotes%!partial:~20,30!%quotes%!partial:~20,30!%quotes%!partial:~20,30!%quotes%!partial:~20,30!%quotes%!partial:~20,30!%quotes%!partial:~20,30!%quotes%!partial:~20,30!%quotes%!partial:~20,30!%quotes%!partial:~20,30!%quotes%!partial:~20,30!%quotes%!partial:~20,30!%quotes%!partial:~20,30!%quotes%!partial:~20,30!%quotes%!partial:~20,30!%quotes%!partial:~20,30!%quotes%!partial:~20,30!%quotes%!partial:~20,30!%quotes%!partial:~20,30!%quotes%!partial:~20,30!%quotes%!partial:~20,30!%quotes%!partial:~20,30!%quotes%!partial:~20,30!%quotes%!partial:~20,30!%quotes%!partial:~20,30!%quotes%!partial:~20,30!%quotes%!partial:~20,30!%quotes%!partial:~20,30!%quotes%!partial:~20,30!%quotes%!partial:~20,30!%quotes%!partial:~20,30!%quotes%!partial:~20,30!%quotes%!partial:~20,30!%quotes%!partial:~20,30!%quotes%!partial:~20,30!%quotes%!partial:~20,30!%quotes%!partial:~20,30!%single_quote%

I will try the full code tomorrow.Well the FOR /L didn't need to be set to that high.  8,193 would have sufficed. Pardon me.  Did I miss something?
You said:
Quote

fixed column length
Do you mean fixed width?
If that is true, parsing is not even needed.
I am confused  because your sample implicates fixed width FIELDS.
Please clarify.
Thanks.Geek, what is confusing you about a fixed length field vs a fixed width field? They are one in the same in my world of data processing.Well, whee records and fields are fixed size , parsing is just using what is in the filed, n o need to find the end. But  CSV is often used to compress the size of files and to transport to other programs that do not have the field definitions.
Just wanting  to follow the logic. Pardon me.
Here is one method using a batch script and helper batch file:

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.

There are only three lines of code here:

Code: [Select]echo off
type "file.txt"|repl "^(.{2})(.{6})(.{6})(.{4})(.{2})(.{30})(.{5})(.{4})(.{10})" "\q$1\q,\q$2\q,\q$3\q,\q$4\q,\q$5\q,\q$6\q,\q$7\q,\q$8\q,\q$9\q," x |repl "^(.{96})(.{2})(.{2})(.{1})(.{8})(.{5})(.{4})(.{6})(.{5})" "$1\q$2\q,\q$3\q,\q$4\q,\q$5\q,\q$6\q,\q$7\q,\q$8\q,\q$9\q," x |repl "^(.{153})(.{10})(.{1})(.{15})(.*)" "$1\q$2\q,\q$3\q,\q$4\q,\q$5\q" x >file2.txt
pause

In the second and third invocations of repl in the same line, the first term in the search term - such as (.{96}) - is equal to the length of the modified output of the command before it, and then it continues with setting the field widths of the following terms.

If you remove the code, in the middle line from the second | and onwards - and run it, then you will see what the first repl command does and which may make it a little clearer.

It's a little clumsy in the construction with multiple calls of repl, but it is very robust and quick on large files, compared to plain batch code.
Dave Benham has just written Jrepl.bat at dostips.com which should do it in a much more straight forward way if you ask him there, and show him this code and your question.

Your input file
Code: [Select]AB012345AC    201399Long name                     55555198900006589673101N008500000008200979999999999900015294260999999999999999         
AB012345ABC   201399Another long name             11111194500000012023203N000313200001840909999999999900000260524999999999999999         
AB012345ABCD  201399three times                   33333199600003609819104N004265000008000979999999999900005823119999999999999999         
The output
Code: [Select]"AB","012345","AC    ","2013","99","Long name                     ","55555","1989","0000658967","31","01","N","00850000","00082","0097","999999","99999","0001529426","0","999999999999999","          "
"AB","012345","ABC   ","2013","99","Another long name             ","11111","1945","0000001202","32","03","N","00031320","00018","4090","999999","99999","0000026052","4","999999999999999","          "
"AB","012345","ABCD  ","2013","99","three times                   ","33333","1996","0000360981","91","04","N","00426500","00080","0097","999999","99999","0000582311","9","999999999999999","          "


If your lines do not contain any commas then this simplification can be used:

Code: [Select]echo off
type "file.txt"|repl "^(.{2})(.{6})(.{6})(.{4})(.{2})(.{30})(.{5})(.{4})(.{10})" "$1,$2,$3,$4,$5,$6,$7,$8,$9," |repl "^(.{77}).(.{2})(.{2})(.{1})(.{8})(.{5})(.{4})(.{6})(.{5})" "$1,$2,$3,$4,$5,$6,$7,$8,$9," |repl "^(.{118}).(.{10})(.{1})(.{15})(.*)" "\q$1,$2,$3,$4,$5\q" x |repl "," "\q,\q" x >file2.txt
pause

Where the terms (.{77}). and (.{118}). refer to the leading parts that were changed by the preceding repl commands, respectively.Hey foxidrive - new site for me

I don't understand why you made your code so complicated. The following long one liner works for me (I used line continuation):
Code: [Select]type myfile.txt|repl "^(..)(.{6})(.{6})(....)(..)(.{30})(.{5})(....)(.{10})(..)(..)(.)(.{8})(.{5})(....)(.{6})(.{5})(.{10})(.)(.{15})(.{10})" ^
"\q$1\q,\q$2\q,\q$3\q,\q$4\q,\q$5\q,\q$6\q,\q$7\q,\q$8\q,\q$9\q,\q$10\q,\q$11\q,\q$12\q,\q$13\q,\q$14\q,\q$15\q,\q$16\q,\q$17\q,\q$18\q,\q$19\q,\q$20\q,\q$21\q" x >test1.csv

You can use up to 99 captured sub-matches. This problem only requires 21.

Using the new JREPL.BAT is nearly identical. You can specify the input and output files as options:
Code: [Select]call jrepl "^(..)(.{6})(.{6})(....)(..)(.{30})(.{5})(....)(.{10})(..)(..)(.)(.{8})(.{5})(....)(.{6})(.{5})(.{10})(.)(.{15})(.{10})" ^
"\q$1\q,\q$2\q,\q$3\q,\q$4\q,\q$5\q,\q$6\q,\q$7\q,\q$8\q,\q$9\q,\q$10\q,\q$11\q,\q$12\q,\q$13\q,\q$14\q,\q$15\q,\q$16\q,\q$17\q,\q$18\q,\q$19\q,\q$20\q,\q$21\q" /x /f "myfile.txt" /o "test1.csv"

It is probably easier / more reliable to let code build the search and replace strings. Because this solution is passing the strings as variables, I am able to embed the quotes directly instead of using \q with the /X option.
Code: [Select]echo off
setlocal enableDelayedExpansion
set "search=^"
set "replace="
set /a n=0
for %%N in (2 6 6 4 2 30 5 4 10 2 2 1 8 5 4 6 5 10 1 15 10) do (
  set /a n+=1
  set "search=!search!(.{%%N})"
  set "replace=!replace!"$!n!","
)
set "replace=!replace:~0,-1!"
call jrepl search replace /v /f test.txt /o test1.csv


Dave Benham Quote from: dbenham on November 14, 2014, 09:48:50 PM
Hey foxidrive - new site for me

Nice to see you here Dave.

Quote
I don't understand why you made your code so complicated.
You can use up to 99 captured sub-matches. This problem only requires 21.

D'oh!  I thought it only worked up to 9 back-references, like GNUsed does!  Mea Culpa!  Thanks for the info.

Quote
It is probably easier / more reliable to let code build the search and replace strings. Because this solution is passing the strings as variables, I am able to embed the quotes directly instead of using \q with the /X option.
Code: [Select]echo off
setlocal enableDelayedExpansion
set "search=^"
set "replace="
set /a n=0
for %%N in (2 6 6 4 2 30 5 4 10 2 2 1 8 5 4 6 5 10 1 15 10) do (
  set /a n+=1
  set "search=!search!(.{%%N})"
  set "replace=!replace!"$!n!","
)
set "replace=!replace:~0,-1!"
call jrepl search replace /v /f test.txt /o test1.csv

And that's a clever way to clarify the field widths in the command.

Welcome Aboard dbenham ! ! Quote from: patio on November 15, 2014, 07:26:58 AM
Welcome Aboard dbenham ! !
DittoSorry for the long delay in replying.  I am doing this at work, and FRIDAY the forum server was down, Monday I was GIVEN a priority assignment for QA, and yesterday I was out of the office.

Thanks for all of your input.  I had seen previously references to repl.bat by dbenham, but I did not see how I could incorporate that logic into my situation.  I will give this code a try.
958.

Solve : IE properties?

Answer»

I wrote a batch file to create INTERNET Explorer favourites and it successful.

Apart from it i want to enable Favourites toolbar (View->Toolbars->Enable Favourites bar)

Am targetting IE 8 and can U pls tell me how to access the IE properties by DOS commands.

Thanks



959.

Solve : Project all the images/newest images that were added to the directory(.bat,cmd)?

Answer»

I was able to project all the level 2 hdf files and saved the projected files to the new(CREATED) directory using this script:

set in_path=in_path
set out_path=out_path

md %out_path%
cd /d %in_path%

FORFILES /m *L2_LAC*.hdf /C "cmd /c gdalwarp -geoloc -t_srs EPSG:4326 -te 113.205 1.120 157.105 2.005 HDF4_SDS:hdf:file:01 %out_path%\fname.tif"*

But there is one last thing that I need to MAKE this goal complete:

How am I going to AUTOMATICALLY detect all the newest projected images that were added to the directory from time to time and then project it immediately?Because everyday I am DOWNLOADING hdf files and then if there are new files I'll project it from time to time which is a WASTE of time. That's why I need it in batch process and automatic. How will I complete this project using the script below?

for /f "tokens=1,2,5" %a in ('dir /-b /o-d /tc') do if %a==%date:~4% (if %b==%time:~0,5% (echo %c)

960.

Solve : Batch code that copies a specified folder outside another specified folder path?

Answer»

Hi ,

I need a batch code which performs the FOLLOWING:

I have a folder with CERTAIN xml files. i need to search and  COPY this folder along with the xml files outside another specified folder path.
For eg:
If my folder NAME  =FOLDER,
its location=C:\FOLDER =Input1
Input2=D:\abc\def
I need to copy "FOLDER" and its contents to  "D:\abc" that is outside the "def" folder

PLS HELP ... THANKS IN ADVANCE... Any Batch experts,Pls reply if the above scenario is possible or not The question is unclear to me.

I need to search for a folder which has some XML files in it and MOVE it to another location . If I give the destination location as d:/ABC/def I need that folder to be moved to d:/ABC .  Quote from: Venkat on October 18, 2014, 12:59:51 PM

I need to search for a folder which has some XML files in it and move it to another location.

Do you have to search for just one XML file to identify the folder?

Quote
If I give the destination location as d:/ABC/def I need that folder to be moved to d:/ABC .

Why do you specify the destination location as d:\abc\def when you want to move the detected folder to d:\abc

961.

Solve : creating file from computer name?

Answer»

If someone can help me with this.
I have my laptops marked with HP at the end so I need a BATCH which will check computername like JOHN01-HP
and if it finds HP in the computer name it will make a file like laptop.txt, I will use that file for some backups.
and that file will be stored at user folder Documents
I have many users so I can't do this for just one.

Thank you.Just looking at some of your PREVIOUS threads, you should have the knowledge to do this already.
You basically have two options.
1) Use the SET command to read the last two characters of the computer name. Then use an IF command to see if the last two characters are equal to HP.
2) Use the FOR /F command and the hyphen as a delimiter to split the computer name into two tokens.  Then use an IF command to see if the 2nd token is equal to HP.Ok I will try, to see if it will works.OK I did it
Code: [Select]echo.>>%computername%.txt  Quote from: Blisk on October 29, 2014, 07:17:54 AM

OK I did it
Code: [Select]echo.>>%computername%.txt 
How does this solve your problem?  You said you needed to check if the computer name has HP in the name.This batch makes file with computername like mike10-HP.txt
and second batch search for file with *-HP.txt if batch found that file than it makes backup, if not, than doesn't.This is another method which should work:

Code: [Select]echo %computername%|findstr /e /i "-HP" >nul && (goto :backup) || (goto :FINISH)

and this:

Code: [Select]if /i "%computername:~-3%"=="-HP" (goto :backup) else (goto :finish)thank you, tihis one is better I will use it Quote from: Blisk on October 29, 2014, 08:42:15 AM
This batch makes file with computername like mike10-HP.txt
and second batch search for file with *-HP.txt if batch found that file than it makes backup, if not, than doesn't.
Ugh! I guess you didn't bother to even research my ideas or even LOOK at all your old threads to accomplish this task. Quote from: Squashman on October 29, 2014, 01:51:33 PM
Ugh! I guess you didn't bother to even research my ideas or even look at all your old threads to accomplish this task.

No it is not that way, I have alot of work to do, so I don't have time now to sarch and learn how to do it so I found quickest way which worked.
Quote from: Blisk on October 30, 2014, 01:34:26 AM
No it is not that way, I have alot of work to do, so I don't have time now to sarch and learn how to do it so I found quickest way which worked.
You are preaching to the choir, but that doesn't keep me from learning new scripting techniques every day.  People will only want to give you the FISH so many times. Eventually you have to learn to FISH!unofrtunally everyone can't be fisherman, so thats why you have fish I have BREAD, you give me a fish I give you a bread!
The basics I know but in reality what I do with fev lines or 2 batch files you can do with one line, because you have experiences.
My work field is windows system and desktop, I use batch files just to make my job easier and I am not a programmer.I never saw you give him bread... Quote from: Blisk on October 30, 2014, 08:14:32 AM
unofrtunally everyone can't be fisherman, so thats why you have fish I have bread, you give me a fish I give you a bread!
The basics I know but in reality what I do with fev lines or 2 batch files you can do with one line, because you have experiences.
My work field is windows system and desktop, I use batch files just to make my job easier and I am not a programmer.
Most Network System Administrators and Desktop Support people are not programmers but are at least required to know some kind of scripting language to automate tasks.  I went to school 15 years ago and learning Batch on Windows and BASH on Unix was a requirement for my Network Administration degree.

So it has nothing to do with being a programmer.yes you are right, what can I say.
962.

Solve : Batch Counter for Booting Up Windows?

Answer»

Hey all, Rettsu here.

I'm working on a LITTLE project of mine that I want to try on my computer, I want to make a batch file that COUNTS up +1 every time I BOOT up my computer, so after a while I can see how many my computer has been started. But after a few searches on google I couldn't find it at all.
Can someone help me with this ? Put this batch file in your startup group:

Code: [Select]echo a>>"%userprofile%\desktop\counter.log"
And use this batch file to give you the current COUNT.

Code: [Select]echo off
find /c "a" <"%userprofile%\desktop\counter.log"
pause
Thanks, it worked!

Is it possible to actually put the Counter in a certain map on the desktop? I tried to change the location but it would give me a "Batch" file on my desktop.

"EDIT"
Nevermind, I found how to do it. I just changed the folders name

963.

Solve : Batch asking question to add value to jar parameter?

Answer»

hello all

I don't know where to begin with this... I'd like to have a BATCH asking the user to input data (text), then this data would LATER be used as a parameter for a java file...

Here's my thoughts:
Code: [Select]echo off
path=d:\AUXID\
echo input the CipherValue
echo.
pause
set input=
set /p input=%1
"C:\Program Files (x86)\Java\jre8\bin\java.exe" -jar SeedDecrypt.jar Ciphervalue %1 hex-key 1FF7738D8A8C5040DC68B9CB4E8DE2A2 >>d:\AUXID\SeedDecrypt.txt
echo see file d:\AUXID\SeedDecrypt.txt for infos.
echo.
pause
exit

My questions are :
1.  is my %1 input correct
2. dough I got a java error
Code: [Select]Exception in thread "main" org.apache.commons.codec.DecoderException: Odd NUMBER of characters.
        at org.apache.commons.codec.binary.Hex.decodeHex(Hex.java:82)
        at DecryptionText.main(DecryptionText.java:28)
My SeedDecrypt.txt file has a size of 0KB each time.

can someone help me on this%1 would be a command line argument.
Meaning you would start the batch file from the command prompt like this.
Code: [Select]C:\mybatchfile.bat sometext
If you want to ask for input you are partially doing it correctly by USING the SET /P but you never use the INPUT variable in your JAVA command.
Code: [Select]Set /P input=input the CipherValue:
"C:\Program Files (x86)\Java\jre8\bin\java.exe" -jar SeedDecrypt.jar Ciphervalue %input% hex-key 1FF7738D8A8C5040DC68B9CB4E8DE2A2 >>d:\AUXID\SeedDecrypt.txt Quote from: metal_man77 on November 05, 2014, 01:47:24 PM

Code: [Select]echo off
path=d:\AUXID\

Additionally, the path variable is a system variable and shouldn't be used as a general purpose variable name,
and when you are adding a folder to the path then you can use something like this Code: [Select]set "path=%path%;c:\new\folder" Quote from: foxidrive on November 06, 2014, 04:15:06 AM
Additionally, the path variable is a system variable and shouldn't be used as a general purpose variable name,
and when you are adding a folder to the path then you can use something like this Code: [Select]set "path=%path%;c:\new\folder"
Good catch.  I was so focused on the code errors I must have glazed over that.  Thanks !
now it looks like this :
Code: [Select]echo off
path=%path%;d:\AUXID\
set input=
set /p input=input the CipherValue
"C:\Program Files (x86)\Java\jre8\bin\java.exe" -jar d:\AUXID\SeedDecrypt.jar Ciphervalue %input% hex-key 1FF7738D8A8C5040DC68B9CB4E8DE2A2 >>d:\AUXID\SeedDecrypt.txt
echo see file d:\AUXID\SeedDecrypt.txt for infos.
echo.
pause
exit

I still have the Java error, but I GUESS it's because I input random $hit.
and still my txt file is at 0KB.Not sure why you are screwing around with path variable.  It is not needed in your script at all.

We would have no idea how to debug your Java program. But I am pretty sure you batch code is rock solid now.Thanks for the Help !
Took out the path variable like you said.
Now I just have to figure out the java error.

Thanks a lot !
964.

Solve : Need to Write a batch File?

Answer»

Hello guys. I need help with writing a script file. I have over 500000 mp3 files im downloading from my google CLOUD account cause my HD crashed and DIED. All the files are being downloaded to the root of my N: drive. All the files are without folders and have metadata to show album name and artist name. within windows i have "album and artist" show under view attributes. I want to write a script that would create a folder based on the artist name, then move those files based on artist name into said folder e.g  Coldplay -XY move to coldplay folder. please can anyone help me?Can't do it with BATCH natively. You will need a command line program that can read the ID3 tags. Once you have that someone can probably write you a script.  But until they know what program that can do it, you are out of luck.This TOOL can help you I THINK:  From the doc:

Mp3 Tag Tools v1.2(C) 2003 John George K. is GNU GPL free software, intutive ID3v1.1 and ID3v2.x mp3 tag editing utility, with several features such as...

Quote

Create Directories and organize mp3s from ID3 tag info

965.

Solve : i need help on this can someone fix the errors and email me !?

Answer»

echo off
title Windows Error Solution
:start
color 2
cls

echo Windows is Currently experincing problems with your Drive!
echo Please pick a solution for your problem
echo a.Use a ANTIVIRUS sofware
echo b.exit
echo c.shutdown computer
set /p var=Please TYPE the letter of your choice:
IF '%var%"==a goto :a
IF "%var%"==b goto :b
IF "%var%"==c goto :c


:a
echo Windows is using your antivirus sofware standby......
shutdown /s /c "Window antivirus has failed CURENTLY BEING HACKED BY ZEUS"
goto start
pause

:b
shutdown /s /c "Now DELETING All UR Files
pause
goto start


:c
shutdown /s
pause
goto startWe don't do email assistance. All responses will appear in this thread.yes sir
Yeah right. NOBODY likes helping script kiddie pranksters.Does he mean the spelling and grammar errors? There are a lot of those.
Not gonna entertain this...

        Topic Closed.

966.

Solve : How to Invert Mouse?

Answer»

How to Invert Mouse
with regedit (registry)

i'm sorry i don't english !You will have to explain with more detail in what you are trying to accomplish and why.when i move the mouse to up!
pointer move to down !


(mouse to up pointer to down)
(mouse to right pointer to left) Quote from: Squashman on November 13, 2014, 08:26:39 AM

and why.
Regardless of the WHY, this does not seem possible with a simple registry hack.  It either has to be built-in to the mouse DRIVER or you would need to use a 3rd party utility to make the change.  At least that is what I can find from a simple Google search.I need for school project

Please help me

Is Very Necessary1. We don't do homework here.
2. This is not possible through conventional cmd commands without regedit.  I would look into a fuller LANGUAGE like C or C++ if you want to write your own, though I'm sure there is 3rd party software that will do this for you.

Your other option is to go into the control panel and look there.  There might be SOMETHING of interest under the mouse options.Is this may be through the registry? Quote from: mss9668 on November 13, 2014, 09:29:23 AM
I need for school project

Please help me

Is Very Necessary

Has this link been shown here: http://superuser.com/questions/406502/how-can-i-reverse-mouse-movement-x-y-axis-system-wide-win-7-x64
967.

Solve : Script or batch file to capture the program log?

Answer»

Dear All,


I ping the hostname  to get the OUTPUT for each result and ERROR log to save it success ping or failed in excel file format 


ping 192.168.1.7.2
ping 192.168.1.7.3
ping 192.168.1.7.4


May I know how to write the SCRIPT ?   Kindly to advice

Thank you very much


http://www.robvanderwoude.com/redirection.php.xls is not a file that batch can redirect into.Thank you for all

I have 100 PC to do ping test. May I know how to write the script to capture the result if error or success It depends on how you define error and success.  The ping command can throw multiple different outputs, not just yes or no.  To start, I would look at for /f to loop through a text file that contains all your ip addresses.  After that you simply ping each in turn and have a big if tree to show success or failure, redirecting the output into a file. Quote from: sun_os on November 01, 2014, 10:49:49 AM

I have 100 PC to do ping test. May I know how to write the script to capture the result if error or success

This should work - with ONE PC address PER line in file.txt

Code: [Select]echo off
(
for /f "usebackq delims=" %%a in ("file.txt") do (
   ping -n 1 %%a |find "TTL=" >nul
   if errorlevel 1 (echo %%a failed) else (echo      %%a passed)
)
)>output.log
968.

Solve : Batch file to add date to file name?

Answer»

Hello Folks,

Have a small problem that I'm hoping I could get some assistance with.  I currently have a batch file (if memory serves, it seems I originally obtained the idea from this site) that takes the date and adds it to an archive file that's created on a daily basis.  This works fine when the regional short date format in Windows is setup for M/d/yyyy.  However, we have another location which is using the short date format of dd-MMM-yy in which case the same batch file will not work.  I've tried adjusting the date variables in the existing batch file, but I'm not getting anywhere. 

Is it possible someone might be able to tell me which settings I need to adjust to accommodate the other date format of dd-MMM-yy so the batch file could do it's thing?

Existing file:
Code: [Select]echo off
:: setting MM to equal the current numeric month
set MM=%date:~4,2%

:: putting all the possible months into a variable which will be parsed in the for loop
set month_text="01 JAN" "02 FEB" "03 MAR" "04 APR" "05 MAY" "06 JUN" "07 JUL" "08 AUG" "09 SEP" "10 OCT" "11 NOV" "12 DEC"

:: for loop is parsing the month_text variable and using the find command with the numeric month to set the month variable
for %%I in (%month_text%) do echo %%I |find "%MM%" &&set MM=%%~I
:: Need to remove the NUMBER and space
echo Date: %date%
echo Today: %date:~7,2% %MM:~3% %date:~10,4%
SET Month=%DATE:~4,2%
if %Month%==01 set Month=JAN
if %Month%==02 set Month=FEB
if %Month%==03 set Month=MAR
if %Month%==04 set Month=APR
if %Month%==05 set Month=MAY
if %Month%==06 set Month=JUN
if %Month%==07 set Month=JUL
if %Month%==08 set Month=AUG
if %Month%==09 set Month=SEP
if %Month%==10 set Month=OCT
if %Month%==11 set Month=NOV
if %Month%==12 set Month=DEC
echo %Month%
For /F "tokens=2,3,4 delims=/ " %%A in ('Date /t') do (
Set Day=%%A
Set Month=%%B
Set Year=%%C
Set All=%date:~7,2% %MM:~3% %%C
)
 
ECHO Compressing Daily Inventory/Receiving Files and Powering Off
ECHO off
7z a -t7z "Warehouse 7C - %ALL%.7z" -x!*.7z -mx9 -mmt
shutdown /s

In all file names, I wish for the date to appear as DD MMM YYYY [ie: 02 NOV 2014]

Thanks so much,

KenThis should work on XP Pro and above.
Code: [Select]ECHO off
:: GET DATE and TIME
for /f "tokens=2 delims==" %%a in ('wmic OS Get localdatetime /value') do set "dt=%%a"
set "YYYY=%dt:~0,4%"
set "MM=%dt:~4,2%"
set "DD=%dt:~6,2%"
set "HH=%dt:~8,2%"
set "Min=%dt:~10,2%"
set "Sec=%dt:~12,2%"Goodness, what a speedy and helpful reply.  That works marvelous.  It's also nice to have the time variables as well for future reference.

Tested as follows (to, hopefully, display the abbreviated month in uppercase):

Code: [Select]ECHO off

SET Month=%DATE:~3,3%
if %Month%==01 set Month=JAN
if %Month%==02 set Month=FEB
if %Month%==03 set Month=MAR
if %Month%==04 set Month=APR
if %Month%==05 set Month=MAY
if %Month%==06 set Month=JUN
if %Month%==07 set Month=JUL
if %Month%==08 set Month=AUG
if %Month%==09 set Month=SEP
if %Month%==10 set Month=OCT
if %Month%==11 set Month=NOV
if %Month%==12 set Month=DEC

:: GET DATE and TIME
for /f "tokens=2 delims==" %%a in ('wmic OS Get localdatetime /value') do set "dt=%%a"
set "YYYY=%dt:~0,4%"
set "MM=%dt:~4,2%"
set "DD=%dt:~6,2%"
set "HH=%dt:~8,2%"
set "Min=%dt:~10,2%"
set "Sec=%dt:~12,2%"

echo DD-MMM-YYYY: %DD% %Month% %YYYY%
pause

The only downside I can find is when the regional date format is set for M/d/yyyy, the month is displayed ENTIRELY in uppercase as I wish.  However, if the date format is set for dd-MMM-yy, only the first character is in uppercase.  Any way of getting the entire month to be uppercase? 

Thank you so much.

KenTry this:

Code: [Select]ECHO off
:: GET DATE and TIME
for /f "tokens=2 delims==" %%a in ('wmic OS Get localdatetime /value') do set "dt=%%a"
set "YYYY=%dt:~0,4%"
set "MM=%dt:~4,2%"
set "DD=%dt:~6,2%"
set "HH=%dt:~8,2%"
set "Min=%dt:~10,2%"
set "Sec=%dt:~12,2%"

if %MM%==01 set Month=JAN
if %MM%==02 set Month=FEB
if %MM%==03 set Month=MAR
if %MM%==04 set Month=APR
if %MM%==05 set Month=MAY
if %MM%==06 set Month=JUN
if %MM%==07 set Month=JUL
if %MM%==08 set Month=AUG
if %MM%==09 set Month=SEP
if %MM%==10 set Month=OCT
if %MM%==11 set Month=NOV
if %MM%==12 set Month=DEC

echo DD-MMM-YYYY: %DD% %Month% %YYYY%
pause Quote from: KenK13 on November 03, 2014, 07:24:37 AM


The only downside I can find is when the regional date format is set for M/d/yyyy, the month is displayed entirely in uppercase as I wish.  However, if the date format is set for dd-MMM-yy, only the first character is in uppercase.  Any way of getting the entire month to be uppercase? 

Thank you so much.

Ken
Was not the point of your question that you wanted one way to get the date in a consistent format so that you could use your SET commands to set the Month Abbreviation in upper case?  Why are you still using the DATE command?Thank you foxidrive, your solution works perfect!

Quote from: foxidrive on November 03, 2014, 07:29:28 AM
Try this:

Code: [Select]ECHO off
:: GET DATE and TIME
for /f "tokens=2 delims==" %%a in ('wmic OS Get localdatetime /value') do set "dt=%%a"
set "YYYY=%dt:~0,4%"
set "MM=%dt:~4,2%"
set "DD=%dt:~6,2%"
set "HH=%dt:~8,2%"
set "Min=%dt:~10,2%"
set "Sec=%dt:~12,2%"

if %MM%==01 set Month=JAN
if %MM%==02 set Month=FEB
if %MM%==03 set Month=MAR
if %MM%==04 set Month=APR
if %MM%==05 set Month=MAY
if %MM%==06 set Month=JUN
if %MM%==07 set Month=JUL
if %MM%==08 set Month=AUG
if %MM%==09 set Month=SEP
if %MM%==10 set Month=OCT
if %MM%==11 set Month=NOV
if %MM%==12 set Month=DEC

echo DD-MMM-YYYY: %DD% %Month% %YYYY%
pause
Quote from: Squashman on November 03, 2014, 07:37:09 AM
Was not the point of your question that you wanted one way to get the date in a consistent format so that you could use your SET commands to set the Month Abbreviation in upper case?  Why are you still using the DATE command?

Sorry, I guess I'm not understanding you clearly.  Yes, I want to get a consistent date displayed as: DD MMM YYYY (with abbreviated month name in uppercase).  However, when I displayed the date using the code you originally provided, the result was displayed as a numeric month.

For example, taking your code as is and displaying the output:
Code: [Select]ECHO off
:: GET DATE and TIME
for /f "tokens=2 delims==" %%a in ('wmic OS Get localdatetime /value') do set "dt=%%a"
set "YYYY=%dt:~0,4%"
set "MM=%dt:~4,2%"
set "DD=%dt:~6,2%"
set "HH=%dt:~8,2%"
set "Min=%dt:~10,2%"
set "Sec=%dt:~12,2%"

echo %DD% %MM% %YYYY%

Displayed results: 03 11 2014

That was why I went back and used a portion of the code I originally had.  This enables me to obtain the non-numeric date. [ie: NOV, not 11].

Thank you for your help.

You had the code to translate the numeric month to the abbreviated month. Did not THINK I had to add that to the code I gave you.  Seemed fairly obvious to me.Not sure why you think it's necessary to belittle me here, but if that's what makes you happy so be it.


YEAH, it was obvious to me as well.  That's why I did indeed include the month code to translate the months.  I was just curious why they had not all been uppercase.  And you made a choice to get on my case about using DATE instead of SET.  I used what worked properly for me in my particular case.  Thanks to the great help of foxidrive, I now have what works awesome.


I didn't get on your case about using the date command. I ASKED you a very black and white question. You obviously knew that the regional settings affected the output of the date command and I gave you a consistent date output that wasn't affected by the regional settings and could be used to translate into the month abbreviation using your existing set commands. You then asked again about using the date command again so I asked why you were still trying to use it. Quote from: KenK13 on November 03, 2014, 07:24:37 AM
Code: [Select]
SET Month=%DATE:~3,3%
if %Month%==01 set Month=JAN
if %Month%==02 set Month=FEB
if %Month%==03 set Month=MAR
if %Month%==04 set Month=APR
if %Month%==05 set Month=MAY
if %Month%==06 set Month=JUN
if %Month%==07 set Month=JUL
if %Month%==08 set Month=AUG
if %Month%==09 set Month=SEP
if %Month%==10 set Month=OCT
if %Month%==11 set Month=NOV
if %Month%==12 set Month=DEC


The code you showed is both peculiar and broken.  Your code essentially uses a numeric month to give you a three letter month, and
with Squashman's code it works perfectly.

The first line above sets the month variable to a THREE character string and then you proceed to compare it with a TWO character string - so it will do nothing and the original month variable will remain TOTALLY unchanged.

That is why it failed.


I should add that batch is peculiar too and if the string (of two numerals) happened to have a leading or trailing space then it could match in the compares. 
969.

Solve : Remove what i think are invisible or printer character from txt file?

Answer»

I'm having a hard time capturing the data using a vb script b/c of these characters i noticed in notepad++. This is causing my data to not line up correctly and causing me to capture incorrect data for my sub strings.

Is there a way i can remove them beforehand in vbs or batch and have my data line up correctly?

some of the characters look like so....

ð
NUL (in black a background)
SI  (in black a background)



[attachment deleted by admin to conserve space]Have you used a hex viewer before?

They allow you to see the exact pairs of hex digits and determine which characters are causing you a problem.
I seen Hex Viewers but never actually used one.Do you have any recommendation on one?On old versions of MS-DOS there was a file called DEBUG that would show the contents of a file in HEX format. But I don't think it is a 32 BIT program. So you will WANT to find an editor the is compliant with new versions of Windows.
Look here:
HTTP://sourceforge.net/projects/hexplorer/
Hexplorer. Binary (hexadecimal) editor for Windows
Quote

x86 disassembler
Import and export to 20 different formats of binary files, including Intel Hex, Motorola S-Record, Atmel standard etc.
Ability to find repeating patterns in data
Pixel viewer to visualise binaries as bitmaps
Filter text from binary data
...

Quote from: daillest319 on November 12, 2014, 08:37:05 AM
I'm having a hard time capturing the data using a vb script b/c of these characters i noticed in notepad++. This is causing my data to not line up correctly and causing me to capture incorrect data for my sub strings.

Is there a way i can remove them beforehand in vbs or batch and have my data line up correctly?
You can replace them with nothing, effectively removing them from the string

Code: [Select]LineResult = Replace(LineResult,Chr(0),"") 'Null character
LineResult = Replace(LineResult,Chr(240),"") 'greek character (Delta?)
LineResult = Replace(LineResult,Chr(145),"") 'backtick thing
LineResult = Replace(LineResult,Chr(15),"")   'Shift In Character

I would first eliminate other sources of the characters such as how you are retrieving the data.Thank you all for your help.
970.

Solve : create a batch file with date as folder name?

Answer»

Hey, i have CREATED a batch file which copy the data of one folder into another. But after copying i want to give the particular date as a folder name. I am not able to. Please give your suggestions.

This is my code.

echo off

:: variables

echo Backing up file

set /P source=Enter source folder:

set /P destination=Enter Destination folder:

set listfile=xcopy /L

set xcopy=xcopy /S/E/V/Q/F/H

%listfile% %source% %destination%

echo files will be copy press enter to proceed

pause

%xcopy% %source% %destination% %date%

pauseMultipost: http://stackoverflow.com/questions/27012028/create-a-batch-file-with-date-as-folder-name

Does it MATTER to anyone that PEOPLE multipost their questions?



i wanted my ans. this the reason why i have POSTED over here also. sorryThe DATE /T command and the %DATE% variable all output with slashes.  So you will need to USE a FOR /F command to strip out the day of the week and the slashes depending on what your DATE format is.

You would then use the MD command to create a new directory for the destination.

971.

Solve : Resume processing of files based on the date of the last processed files?

Answer»

The script indicated in here will merge files from the in_path and now will SUCCESSFULLY move the merged files only to ANOTHER directory which is the proc_path. The goal now is to merge the files based on the date of the last PROCESSED files and so on. So that whenever the system is down and you weren't able to process the files let's say for one week, it will just check for the last date where it stop and process it and then process the next date and so on. But how can I do that? Any idea?

Thank you!

Code: [Select]echo on
setlocal EnableDelayedExpansion

rem Modify following variables
set "in_path=E:\Proc\Pro\"
set "out_path=E:\Proc\Mer"
set "proc_path=E:\Proc\Proc_Pro"

rem DON'T modify the following variables
set "yearDay="
set "fileList="
set "numFiles=0"

md %out_path%
md %proc_path%

rem Process all *.tif files in input path
pushd "%in_path%"
for %%a in (*.tif) do (
   set "fileName=%%a"
   rem If the YearDay in this file is the same of previous one
   if "!fileName:~1,7!" equ "!yearDay!" (
      rem Join this filename to previous list
      set "fileList=!fileList!!fileName! "
      set /A numFiles+=1
   ) else (
      rem Merge the files in the list if there are more than 2, in the out_path leaving only TYYYYDDD.L2_LAC.Tera.tif
      if !numFiles! gtr 2 (
         gdal_merge.py -n 0 -a_nodata -32767 -of GTiff -o %out_path%\T!yearDay!.L2_LAC.Tera.tif !fileList!
         rem Move processed files to a different directory
         set "fileList=!fileList:~0,-1!"
         move !fileList: =,! "%proc_path%"
      )
      rem And start a new YearDay and fileList
      set "yearDay=!fileName:~1,7!"
      set "fileList=!fileName! "
      set numFiles=1
   )
)
rem Merge the files in the last list if there are more than 2
if !numFiles! gtr 2 (
   gdal_merge.py -n 0 -a_nodata -32767 -of GTiff -o %out_path%\T!yearDay!.L2_LAC.Tera.tif !fileList!
   set "fileList=!fileList:~0,-1!"
   move !fileList: =,! "%proc_path%"
)
popdNot sure why you are posting this here when you already got the original code from DosTips.com.  The helpers over there already know what the code does and can probably do a better job of helping you with any changes you need. Quote from: Squashman on NOVEMBER 30, 2014, 08:39:13 PM

Not sure why you are posting this here when you already got the original code from DosTips.com.  The helpers over there already know what the code does and can probably do a better job of helping you with any changes you need.

But I still need help with this. The question above is the last thing that I still need in order to have it done. And I don't know how to do it.
972.

Solve : Seeking help to move files from specifically named directory up one level?

Answer»

I have a vast collection of fonts, sorted in different ways depending on where I downloaded them.  Many of them are sorted into foundries or families, with a sublevel for designer. Thus:
Presence Typo/Alinea Sans/Puyfoulhoux, Thierry/AlineaSans.ttf   

This is not an ideal STRUCTURE for me, (for one thing, I'd put the designer before the font family name) but the immediate problem is that for many of them, the sorting program that did this could not identify the designer, so the vast majority of them are in a folder structure that goes:

2 the Left/Leftovers/_unknown/Leftovers.ttf
4YEO/4YEOSports/_unknown/4YEOSports.ttf

This just creates an unnecessary level (and often leads to a structure where the file name is too long).  There are literally thousands of foundries and designers (and hundreds of thousands of fonts). What I would like, if possible, is a batch file or visual basic script that would allow me to move all the files that in are a folder called "_unknown" up one level to the parent directory (which should be the family name), and then delete the folder called "_unknown". The number of directory levels may vary, and if they're in a folder that actually is a designer name, I don't want to move them.  Is this possible?
Need some clarification of the task here:

Will every folder called \_unknown have no folders inside it, and only *.ttf files inside it
that need to be moved up one folder level, and then the\_unknown folder deleted?


Every folder called unknown will have no folders inside it, but it may have .otf, or .pfb, .pfm, or .afm files.  It is possible there may be some sort of .txt (.DOC, .wri) file, but unlikely.  I haven't specifically checked for that.  If there is one, perhaps there is a solution that would only delete the folder if it were empty??Ohhh kay!

In every folder called \_unknown, do you only want the *.ttf files inside it
to be moved up one folder level, and then the\_unknown folder deleted if it is empty?

If there are folders called \_unknown that you do not want processed, then how do we tell if it is to be processed, or not?Thanks for your help.  Ideally, I want every folder called \_unknown to be processed, ALL the files in it moved up one level, and the \_unknown folder deleted.Yeah. I have written this batch file before. Just can't remember what forum I posted it in.This is untested:

This is supposed to process the folders called "_unknown" and move all files up one folder and remove the "\_unknown" folder.

It is designed to process the folders below the current folder - so test it WELL in a test folder with copies of your data.

If there are HUGE numbers of folders and long PATHS that match, then it could take a long time to begin. 
If so then there is a different way to approach this.

Code: [Select]echo off
for /f "delims=" %%a in (' dir /b /s /ad "_unknown" ^|find /i "\_unknown" ') do (
    echo processing "%%a"
    pushd "%%a" &&(move * .. & popd)
    rd "%%a" 2>nul
)
pause
Thank you very much.  That did the trick!

973.

Solve : Bit version of Microsoft Office and Install Program?

Answer»

Here's my situation, trying to write a batch file that will show me the bit VERSION of Office installed, not the OS necessarily, and choose the bit version of Lync to install.  Any Ideas?  Thanks in advance.All 32bit programs installed on a 64 bit Windows OS will be in the Program Files(x86) folder. 
64 bit programs will just be in the Program Files folder on a 64 bit version of Windows.Only Office 2010 (Office 14.0) and Office 2013 have shipped in 32 and 64 bit versions.

Suggestion:

If HKLM\Software\WOW6432Node exists then Windows is 64-bit.
If HKLM\Software\WOW6432Node\Microsoft\Office exists, then Office is 32-bit.
If HKLM\Software\WOW6432Node\Microsoft\Office does not exist, but HKLM\Software\Microsoft\Office does exist, then Office is 64-bit.
If HKLM\Software\WOW6432Node does not exist, then Windows and Office are 32-bit.

Use req query and errorlevel test to establish OS and Office bitness.
This doesn't seem to be working correctly because I have both of the below entries on more than one machine I am running this on.

If HKLM\Software\WOW6432Node\Microsoft\Office exists, then Office is 32-bit.
If HKLM\Software\WOW6432Node\Microsoft\Office does not exist, but HKLM\Software\Microsoft\Office does exist, then Office is 64-bit.Check this out

http://stackoverflow.com/questions/2203980/detect-whether-office-2010-is-32bit-or-64bit-via-the-registry
Good article, but it still is not the same on every machine as listed in the article.  I'm not sure if there is a common way to tell on a Windows 7 Pro box if it has a x86 or x64 Office install.Surely if you first check the bitness of the OS (if it's 32 bit you now know you have a 32 bit Office install) and if it's 64 bit then look in %PROGRAMFILES% (64 bit) or %ProgramFiles(x86)% (32 bit) for the Office folder (Office, Office10, Office11, Office12, Office14 or Office15) or else find the path of some common Office executable file such as Winword.exe or Excel.exe, you have your answer? Or am I missing something here? if this is some corporate thing, surely you know what your machines have installed anyhow?


How's Zeus doin lately ? ?

                    Quote from: patio on December 12, 2014, 11:21:43 AM

How's Zeus doin lately ? ?

He has been involved in a controversy of a modern rather than ancient kind. He is depicted as a bull, the form he took when raping Europa, on the Greek 2-euro coin and on the United Kingdom identity card for visa holders. Mary Beard, Professor of Classics at Cambridge University, has criticised this for its apparent celebration of rape.
Just don't worship Mary Beard...sounds LIKE every Liberal College Proff here in the states...

I won't get started. Quote from: Salmon Trout on December 12, 2014, 10:51:58 AM
Surely if you first check the bitness of the OS (if it's 32 bit you now know you have a 32 bit Office install) and if it's 64 bit then look in %ProgramFiles% (64 bit) or %ProgramFiles(x86)% (32 bit) for the Office folder (Office, Office10, Office11, Office12, Office14 or Office15) or else find the path of some common Office executable file such as Winword.exe or Excel.exe, you have your answer? Or am I missing something here? if this is some corporate thing, surely you know what your machines have installed anyhow?

This will be a Lync rollout on about 300 machines.  The majority, about 85%, are x64 OS's.  But we don't know if the Office install is always x86 or x64.  Also, Office does not always install in ProgramFiles or ProgramFilesx86.  A lot of times it installs in the ProgramData folder, which does not determine if it's a x86 or x64.  One more thing, I've had instances where a x86 Office installs in the ProgramFiles directory. Quote from: patio on December 12, 2014, 11:40:26 AM
Just don't worship Mary Beard...sounds like every Liberal College Proff here in the states...

I won't get started.

Well, I am a liberal, and I am opposed to misogyny (like any sane person ought to be) but I don't really think Zeus needs to be dragged into the argument. Maybe in 50 years people will think differently.What version of Lync are you planning to use? The 64-bit Lync 2010 installation works with the 32-bit version of Microsoft Office. If you have a 64-bit machine with a 32-bit Office 2010, you can use the 64-bit Lync Installer. The 64-bit Lync client installation will install the 32-bit version of the Online Meeting Add-In for Lync 2010 for Outlook. The Lync client itself is actually only 32-bit – the 64-bit download is a 64-bit installer wrapping the 32-bit client.

See here

http://blog.insidelync.com/2012/02/top-10-faq-for-planning-a-lync-2010-client-deployment/



Quote from: col. sanders on December 12, 2014, 11:42:40 AM
A lot of times it installs in the ProgramData folder

That has got to be because the admin chose to install it there, right?

Quote from: foxidrive on December 12, 2014, 12:40:48 PM
That has got to be because the admin chose to install it there, right?
Has to be.  It does not default to that.
974.

Solve : Run 2 Commands, Keep Smallest File?

Answer»

Hi again everyone,

After the help I was given PREVIOUSLY I was attempting to write a new batch script to do pretty much what the one that was written for me does, but with different programs being run and a little different setup...Long story short, the "little" difference was enough to stump me again--so I need some help.

Here is what I have. When run, this produces 2 files for each file:

Code: [Select]dir /s /b /A-D DIR_1\ &GT; list.txt
for /r DIR_1 %%a in (*.*) do (dime -D CO=Q -L %%~dpa "%%a" "%%a.q")
for /r DIR_1 %%a in (*.*) do (make -D CO=X -L %%~dpa "%%a" "%%a.x")
for /F "tokens=*" %%b in (list.txt) do del /Q "%%b"
The goal is to keep the smallest file of the two created. If the .q file is smaller, the script should delete the .x file, if the .x file is smaller, delete the .q file.

Any help would be great! I've learned a lot from you all so far, so I'm hoping to learn some more with this one and reduce the amount of help I have to ask you all for

Thanks.The q and x files could be the same size.  What should happen if that occurs? Quote from: foxidrive on December 09, 2014, 01:36:58 AM

The q and x files could be the same size.  What should happen if that occurs?

Well, the two different commands use two completely different compression algorithms. It is very unlikely that they would be exactly the same filesize. But, in that event, I would say it's BETTER to keep the .q file and delete the .x file.

Thanks.Test this on some sample files.


Code: [Select]echo off
for /r DIR_1 %%a in (*) do (
   dime -D CO=Q -L %%~dpa "%%a" "%%a.q"
   make -D CO=X -L %%~dpa "%%a" "%%a.x"
      for %%b in ("%%a.q") do for %%c in ("%%a.x") do if %%~zc LEQ %%~zb (del "%%a.x") else (del "%%a.q")
   )
pause
Quote from: foxidrive on December 09, 2014, 03:59:57 AM
Test this on some sample files.


Code: [Select]echo off
for /r DIR_1 %%a in (*) do (
   dime -D CO=Q -L %%~dpa "%%a" "%%a.q"
   make -D CO=X -L %%~dpa "%%a" "%%a.x"
      for %%b in ("%%a.q") do for %%c in ("%%a.x") do if %%~zc LEQ %%~zb (del "%%a.x") else (del "%%a.q")
   )
pause

Thanks! Always appreciate the help. Quote from: foxidrive on December 09, 2014, 03:59:57 AM
Test this on some sample files.


Code: [Select]echo off
for /r DIR_1 %%a in (*) do (
   dime -D CO=Q -L %%~dpa "%%a" "%%a.q"
   make -D CO=X -L %%~dpa "%%a" "%%a.x"
      for %%b in ("%%a.q") do for %%c in ("%%a.x") do if %%~zc LEQ %%~zb (del "%%a.x") else (del "%%a.q")
   )
pause

Quick follow-up question:

If I wanted to add a third command that would produce a ".z" file, how would I go about adding it in the comparison portion of the script? In other words, what would I need to add to compare 3 files and keep the smallest and delete the 2 larger files?

The extra command would be identical to the other two except the file extension would be .z, like so:

Code: [Select]   make -D CO=X -L %%~dpa "%%a" "%%a.z"
I'm hoping it's easy so I can, if need be, add more commands and not need to BOTHER you guys with this one again.

Any help would be great.It's not totally straight forward to add one, two, or more commands, with tests.


Batch files are frequently written for a SINGLE task and when the task changes, then the batch file can be very different.

If you have a task to solve and want a script (rather than just a tip on how to use a technique)
then always describe the full task -  never ask for a simplified version and add things later.

The reason is that the volunteers find little enjoyment in writing a script, and then having to change it because the task wasn't described accurately.

http://stackoverflow.com/questions/27422598/this-batch-script-wont-work-why
975.

Solve : ping an address, log errors to text file with timestamp?

Answer»

Hi,
I am aware that this requirement has been answered in a number of different ways, but none of them seemed that elegant to me (by elegant read short & simple).
I would like to leave a ping running (ping -t) and have any response that is a not a reply be written to a text file along with the time and date.

It's the time and date thing that's got me stumped.

First bit working fine for me:

ping -t 195.40.1.36 | find /v "Reply from 195.40.1.36" >> pinglog.txt

Could anyone please let me know how to add the time and date to what gets written out.
Many thanks.Not too sure where you're going with that one. Doesn't seem to work for me.
I get the FAILED pings written out to a log file but they aren't timestamped.

I could use the following batch file. Works fine, but it doesn't record the reason for failure, just that it did fail and the time it happened (and there's probably a cleverer way to pause for 1 second.....)

The reason for failure would be really handy.

echo off
:loop
ping -n 1 %1 >nul || echo %date% %time% no reply from %1 >> pinglog.txt
choice /N /T 1 /D Y >nul
goto loop


Quote from: Salmon Trout on June 11, 2011, 02:16:04 AM

I don't want him to bounce me into posting an untested and incompletely considered reply. Please bear with us a little longer!

No worries and much appreciated.The script below addresses the simplest case I can think of, namely a host which exists and which either is or is not servicing ping requests. If the ping command is "successful" then it looks like this...

Code: [Select]C:\>ping -n 1 192.168.56.129

Pinging 192.168.56.129 with 32 bytes of data:
Reply from 192.168.56.129: bytes=32 time<1ms TTL=128

Ping statistics for 192.168.56.129:
    Packets: Sent = 1, Received = 1, Lost = 0 (0% loss),
Approximate round trip TIMES in milli-seconds:
    Minimum = 0ms, Maximum = 0ms, Average = 0ms
If not, it looks like this

Code: [Select]C:\>ping -n 1 192.168.56.129

Pinging 192.168.56.129 with 32 bytes of data:
Request timed out.

Ping statistics for 192.168.56.129:
    Packets: Sent = 1, Received = 0, Lost = 1 (100% loss),

I only send 1 request for the sake of avoiding network congestion

The IP I am using is a local XP machine whose firewall I turn on and off

As you will see the meat is in the 2nd non-blank line, and we can examine this and decide whether to write it to a log file, preceded by the date and time. To make a delay I use the free sleep utility which is part of the Windows Server 2003 Resource Kit Tools which you can download here:

http://www.microsoft.com/downloads/en/confirmation.aspx?familyid=9d467a69-57ff-4ae7-96ee-b18c4790cffd

There are plenty of others around but not all have the -m (milliseconds) feature.

Code: [Select]echo off
setlocal enabledelayedexpansion
set hostIP=192.168.56.129
:loop
set pingline=1
for /f "delims=" %%A in ('ping -n 1 -w 250 -l 255 %hostIP%') do (
if !pingline! equ 2 (
set logline=!date! !time! "%%A"
echo !logline! | find "TTL=">nul || echo !logline! >> pinglog.txt
)
set /a pingline+=1
)
sleep -m 5000
goto loop


The IP you used as an example resolves to lr-rns.timik.uk.easynet.net on my machine; I wonder if you are wanting to log times and/or periods of bad Internet connection or whether it was just an example?
Thank you so much. Works perfectly.
I'll need to substitute my delay
choice /N /T 1 /D Y >nul
for your rather neater sleep utility as I don't have the option of installing anything.

Are you doing a FIND on "TTL" because it is only a healthy reply that would ever have those characters in it?

The IP I used in the example is just an ISP's nameserver that hasn't CHANGED in 15 years and for some reason I've always defaulted to it.

I'll be using the script to troubleshoot an intermittent network dropout on some servers at work. I plan on pinging a known good IP (our main data centre router) from multiple servers. By correlating the logs I should be able to determine if the dropouts are due to OS, hypervisor, switch or data centre (at least that's my theory!).

Thanks again. Love your nic by the way, started reading 'The Salmon of Doubt' by Douglas Adams just yesterday. Quote from: boff on June 11, 2011, 06:36:01 AM
Are you doing a FIND on "TTL" because it is only a healthy reply that would ever have those characters in it?

Yup. Note the || operator (execute 2nd command if 1st command returns nonzero errorlevel - the opposite of &&)

Also note that the message "Request timed out" is quoted because I am echoing %%A, the 2nd nonblank line of the ping output, via a pipe to find, and a healthy response on my system SHOWS the response time field as "time<1mS" and the < symbol in an unquoted literal string or expanded variable breaks script processing because it has a special meaning (redirection).
If you don't want the quotes to appear in the log see below

Code: [Select]echo off
setlocal enabledelayedexpansion
set hostIP=192.168.56.129
:loop
set pingline=1
for /f "delims=" %%A in ('ping -n 1 -w 250 -l 255 %hostIP%') do (
if !pingline! equ 2 (
set logline=!date! !time! "%%A"
echo !logline! | find "TTL=">nul || (
set logline=!logline:"=!
echo !logline! >> pinglog.txt
)
)
set /a pingline+=1
)
sleep -m 5000
goto loop   

Before...

Code: [Select]11/06/2011 14:44:42.28 "Request timed out." 
11/06/2011 14:44:47.78 "Request timed out." 
11/06/2011 14:44:53.28 "Request timed out." 
11/06/2011 14:44:58.78 "Request timed out." 
11/06/2011 14:45:04.28 "Request timed out." 
11/06/2011 14:45:09.78 "Request timed out." 
11/06/2011 14:45:15.28 "Request timed out." 
11/06/2011 14:45:20.78 "Request timed out." 

After...

Code: [Select]11/06/2011 14:47:11.28 Request timed out. 
11/06/2011 14:47:16.78 Request timed out. 
11/06/2011 14:47:22.28 Request timed out. 
11/06/2011 14:47:27.78 Request timed out. 
11/06/2011 14:47:33.28 Request timed out. 
11/06/2011 14:47:38.78 Request timed out. 
11/06/2011 14:47:44.28 Request timed out. 
11/06/2011 14:47:49.78 Request timed out. 
11/06/2011 14:47:55.28 Request timed out. 
11/06/2011 14:48:00.78 Request timed out. 
11/06/2011 14:48:06.28 Request timed out.  Alternative method using VBScript - save with .vbs extension and call with cscript.exe supplying IP and log file name. In some ways more "elegant", maybe?

e.g. cscript mypingscript.vbs 192.168.56.129 logfile.txt

Code: [Select]hostIp      = wscript.arguments(0)
logfilename = wscript.arguments(1)
Set fso     = CreateObject("Scripting.FileSystemObject")
Set Shell   = CreateObject("Wscript.Shell")
Set logfile = fso.OpenTextFile(logfilename, 8, True)
shellstring = "%comspec% /c ping -t " & hostIP
Set oExec   = Shell.Exec(shellstring)
wscript.echo "Ping Error log With Timestamp - Ctrl + C to halt"
Do While oExec.StdOut.AtEndOfStream <> True
pingline = Date & " " & Time & " " & oExec.StdOut.ReadLine
If Not InStr(pingline, "TTL=") Then
logfile.WriteLine(pingline)
End If
Loop

Quote from: Salmon Trout on June 11, 2011, 03:08:10 PM
Alternative method using VBScript

The nice thing about that one is that when you exit the script the ping stats get written to the log file.  Unfortunately for me every line is being written to the log file (the "TTL=" isn't working). The original dos script you wrote is perfect though. Thanks again. Quote from: boff on June 11, 2011, 04:10:35 PM
Unfortunately for me every line is being written to the log file (the "TTL=" isn't working).

Sorry about that...

hostIp      = wscript.arguments(0)
logfilename = wscript.arguments(1)
Set fso     = CreateObject("Scripting.FileSystemObject")
Set Shell   = CreateObject("Wscript.Shell")
' OpenTextFile Method requires a Const value
' (Over)Write = 2  Append = 8   
Set logfile = fso.OpenTextFile(logfilename, 8, True)
shellstring = "%comspec% /c ping -t " & hostIP
Set oExec   = Shell.Exec(shellstring)
wscript.echo "Ping Error log With Timestamp - Ctrl + C to halt"
Do While oExec.StdOut.AtEndOfStream <> True
      pingline = Date & " " & Time & " " & oExec.StdOut.ReadLine
      If InStr(pingline, "TTL=") = 0 Then
         logfile.WriteLine(pingline)
      End If
Loop

Fantastic. Will implement tonight and let you know how it goes in a couple of days.
The fact that with the vbscript you get the ping stats for the whole session written to the tail of the log file is very cool.Wanted to take the time to register on this forum and congratulate Salmon Trout for providing a 1st class solution.  I have looked far and wide for something elegant, simple, robust that works and was only able to find it in Salmon's solution. 

I added TRACERT into the single logical operator line to get additional useful information for troubleshooting:

echo !logline! | find "TTL=">nul || echo !logline! >> NetworkPingErrors.txt && echo Running TraceRT, please wait.... && tracert %hostIP% >> NetworkPingErrors.txt && echo ----------- >> NetworkPingErrors.txt
 
Thank you very much sir!  Hats off to you. Nice to see after nearly a year that SOMEBODY found it useful.

mmedia man, you are using the double ampersand (&&) as a command separator, I hope you remember it is actually an AND operator - that is:

command1 && command2     command2 is only executed if command1 returns a zero errorlevel

The opposite is the double pipe OR operator.

command1 || command2     command2 is only executed if command1 returns a non-zero errorlevel

The ordinary command separator is a single ampersand

command1 & command2 command2 is always executed



example:

Code: [Select]C:\>dir /b notexist.fil && echo command2
File Not Found

C:\>dir /b notexist.fil & echo command2
File Not Found
command2
In most cases it may not matter which one you use, but there may come a situation where a string of commands on one line will halt part way through if you use && when you don't actually intend to test the preceding errorlevel.

Quote from: Salmon Trout on June 11, 2011, 06:03:28 PM
Sorry about that...

hostIp      = wscript.arguments(0)
logfilename = wscript.arguments(1)
Set fso     = CreateObject("Scripting.FileSystemObject")
Set Shell   = CreateObject("Wscript.Shell")
' OpenTextFile Method requires a Const value
' (Over)Write = 2  Append = 8   
Set logfile = fso.OpenTextFile(logfilename, 8, True)
shellstring = "%comspec% /c ping -t " & hostIP
Set oExec   = Shell.Exec(shellstring)
wscript.echo "Ping Error log With Timestamp - Ctrl + C to halt"
Do While oExec.StdOut.AtEndOfStream <> True
      pingline = Date & " " & Time & " " & oExec.StdOut.ReadLine
      If InStr(pingline, "TTL=") = 0 Then
         logfile.WriteLine(pingline)
      End If
Loop


just registered this forum to thank you for such an excellent script.
however, it still does not print
"request timed out"
in my case..
it simply writes
"ping request could not find host www.google.com. Please check the name and try again."

for my case i need to count how many RTO's occured to measure the bandwidth quality.
so is there anyway to make it print the rto's as well?
thanks
976.

Solve : Update CSV files?

Answer»

Hi,

There are 30 CSV files in folder and i want to update all of them, the format of files are same.

Matching rows by comparing Col A, B, and C. If match(s) found, the duplicate rows to be deleted and their contents are appended to the original.

.csv file.

A|B|C|D|E|F|G|H|.........
x|y|z|1|2|3|4|5|
x|y|z|7|8|9|1|2|
o|p|q|9|6|3|2|1|
x|y|z|3|4|7|8|1|

modified.csv
A|B|C|D|E|F|G|H|.........
x|y|z|1|2|3|4|5|7|8|9|1|2|3|4|7|8|1|
o|p|q|9|6|3|2|1|

Any ways.





That is not a csv file format. The 'c' is 'csv' stands for 'comma'. Your column separator is a pipe character '|'. So please clarify.

However...

1. Must it be done using batch? Can VBScript be used? If not, why not?
2. Can temp files be written somewhere?
3. Does each column contain just 1 character? If not, please supply more representative example data.

Quote from: Salmon Trout on December 05, 2014, 04:43:52 AM

That is not a csv file format. The 'c' is 'csv' stands for 'comma'. Your column separator is a pipe character '|'. So please clarify.

However...

1. Must it be done using batch? Can VBScript be used? If not, why not?
2. Can temp files be written somewhere?
3. Does each column contain just 1 character? If not, please supply more representative example data.

Thanks Salmon for reply.
I agree its Pipe-Delimiter file exported from excel and SAVED as .csv
1. Approx. there are 20000 to 25000 rows and 200 columns. I don't mine if its more faster/flexible to achieve with VBScript, because i have atleast 30 files in which continuously new data is appended and once in month i will have to update/re-arrange it.
2. Yes we can create the temp files. c:\Temp.
3. No, total data is numeric not a single character. Col1=2 numeric, Col2=4 numeric, Col3=1 to 7 numericals and from Col4 fixed 6 numeric.
Sample data:
ST|BRIN|TP|KEY1|KEY2|KEY3|KEY4|KEY5|KEY6|KEY7|KEY8|KEY9|KEY10|KEY11|KEY12|KEY13|KEY14|KEY15|KEY16|KEY17|KEY18|KEY19|KEY20|KEY21|KEY22|KEY23|KEY24|KEY25|KEY26|KEY27|KEY28|KEY29|KEY30|KEY31|KEY32|KEY33|KEY34|KEY35|KEY36|KEY37|KEY38|KEY39|KEY40|KEY41|KEY42|KEY43|KEY44|KEY45|KEY46|KEY47|KEY48|KEY49|KEY50|KEY51|KEY52|KEY53|KEY54|KEY55|KEY56|KEY57|KEY58|KEY59|KEY60|
53|5305|1|722101|722102|722103|722104|722105|722106|722107|722108|722109|722110|722111|722112|722113|722114|722115|722116|722117|722118|722119|722120|722121|722122|722123|722124|722125|722126|722127|722128|722129|722130|722131|722132|722133|722134|722135|722136|722137|722138|722139|722140|722141|722142|722143|722144|722145|722146|722147|722148|722149|722150|
53|5305|1|745551|745552|745553|745554|745555|745556|745557|745558|745559|745560|745561|745562|745563|745564|745565|745566|745567|745568|745569|745570|745571|745572|745573|745574|745575|745576|745577|745578|745579|745580|745581|745582|745583|745584|745585|745586|745587|745588|745589|745590|745591|745592|745593|745594|745595|745596|745597|745598|745599|745600|
53|5305|1|823126|813002|813003|813004|813005|813006|813007|813008|813009|813010|813011|813012|813013|813014|813015|813016|813017|813018|813019|813020|813021|813022|813023|813024|813025|813026|813027|813028|813029|813030|813031|813032|813033|813034|813035|813036|813037|813038|813039|813040|813041|813042|813043|813044|813045|813046|813047|813048|813049|813050|
37|2037|22|575196|514202|514203|514204|514205|514206|514207|514208|514209|514210|514211|514212|514213|514214|514215|514216|514217|514218|514219|514220|514221|514222|514223|514224|514225|514226|514227|514228|514229|514230|514231|514232|514233|514234|514235|514236|514237|514238|514239|514240|514241|514242|514243|514244|514245|514246|514247|514248|514249|514250|
37|2037|22|713951|713952|713953|713954|713955|713956|713957|713958|713959|713960|713961|713962|713963|713964|713965|713966|713967|713968|713969|713970|713971|713972|713973|713974|713975|713976|713977|713978|713979|713980|713981|713982|713983|713984|713985|713986|713987|713988|713989|713990|713991|713992|713993|713994|713995|713996|713997|713998|713999|714000|
The basic algorithm is fairly simple.

1) SORT the INPUT descending so header remains at top.
2) initialize PreviousKey to SOMETHING that will never match
3) for each line: (note, writes are without \n unless explicitly stated)
     - if 1st line than write line
     - else if key = previousKey write nonKey data
     - else write \n + entire line
4) terminate the last line with \n

This can be done easily with VBScript or JScript or PowerShell.

Or you could use batch coupled with JREPL.BAT
Code: [Select]echo off
sort /r %1 /o %1
call jrepl "^((?:.*?\|){3})(.*)" "output.Write($1==prev?$2:(prev?'\r\n':'')+$0);prev=$1;false;" /jmatch /jbeg "var prev" /f %1 /o -
echo(>>%1

I suppose it could be done with pure batch, but I would worry about performance, as well as the potential for lines to exceed the max batch string length of ~8191 bytes.
Thanks, dbenham! I was inclining towards VBScript, because of the Dictionary Object but you have ridden to the rescue!
977.

Solve : How to make exe files with batch files????

Answer»

(If you never seen me, im a new user and i just registered.)


Well, im a pro on batch files but im creating in Advanced BAT to EXE Converter 2.92 a Setup. But the problem is that with a example of:

cd %userprofile%\Desktop
echo HELLO WORLD! &GT;> example.txt


How i MAKE a exe file with something like that? Please help!There is no true way to make a batch file into an EXE.  All the Bat to EXE converters do is create a wrapper around the batch file.  When the exe wrapper is executed it extracts the batch file to a temporary directory and executes the batch file.I used Batch to EXE before to wrap batches into EXE files when the batch files had credentials in them to escalate privileges, but other than that they are pretty worthless. Also being wrapped as an EXE doesnt mean that someone dedicated enough wouldnt figure out how to view the passwords etc.If the OP is an expert in batch, it should not be hard to use a general purpose language. Currently he favorite is C++ for most people.  One can make good EXE files with C++ that can make use of the Microsoft .NET library.

Pragmatically anything you do in batch can be done nicely in C++.I PRESUME this setup application is being written as a learning exercise because if you are writing a setup program for an application that you are planning on distributing, there are already tonnes of both free and commercial installers for Windows that you can use such as INSTALLSHIELD (commercial) or NSIS (open source).

Quote from: Geek-9pm on December 29, 2014, 10:54:05 AM

If the OP is an expert in batch, it should not be hard to use a general purpose language. Currently he favorite is C++ for most people.  One can make good EXE files with C++ that can make use of the Microsoft .NET library.

Pragmatically anything you do in batch can be done nicely in C++.

C++ has a use but is only really worthwhile in much lower level programs, there are a lot of much more suitable languages for most tasks.  It is certainly not the "favourite for most people".

While I personally don't use Batch, for this use (a setup program), a shell scripting language is surely the most suitable since its main job is GOING to likely be moving files around on disk, Trying to use C++ for this would be a right pain, you would end up doing a lot more work for exactly the same output, not to mention all the other issues that crop up with C and C++.
978.

Solve : Sring handling problem?

Answer»

Hello,
I have a file with lines of text such as:
"C:\PROGRAM Files\something\app.exe" int.ini

I have been able to extract each line and place the text of each line into a variable.
Now comes my problem. I would like to split the two 'words' of text "C:\Program Files\something\app.exe" and int.ini into SEPARATE variables.
I've looked on the internet and found solutions that don't work. an example is:

 for /f "tokens=1,2 delims=;" %%a in ("%name%") do (
   set first=%%a&set second=%%b
   echo %first% and %second%
 )
where %name% contains my string with a ';' delimiter INSTEAD of a space.
This doesn't seem to work.
COULD someone offer an alternative with a space for the delimiter that does work.
Thanking youOne of the issues is that there is no ; in the string you provided.  the other is that delayed expansion is not on, so the %first% and %second% will be processed before they are assigned a value. You may have to manually replace the separation with a (.  If you do this should work.

Code: [Select]setlocal EnableDelayedExpansion
for /f "tokens=1,2 delims=;" %%a in ("%name%") do (
   set first=%%a
   set second=%%b
   echo !first! and !second!
)
You can't split on a space because your file path has spaces. So you need to use a double quote as your delimiter.
Code: [Select]echo off

for /f usebackq^ tokens^=1^,2^ delims^=^" %%a in ("file.txt") do (
set first=%%a
set second=%%b
)
echo %first%
echo %second%
pauseoutput
Code: [Select]C:\JFW\batch files\quote_delim>type file.txt
"C:\Program Files\something\app.exe" int.ini

C:\JFW\batch files\quote_delim>quote.bat
C:\Program Files\something\app.exe
 int.ini
Press any key to continue . . .Beat me to it by a matter of seconds 

You might want to strip leading spaces. One way is to use another FOR /F
Code: [Select]for /f usebackq^ tokens^=^ 1* %%A in ("file.txt") do for /f "tokens=*" %%C in ("%%B") do (
  set "first=%%A"
  set "second=%%B"
)
echo %first%
echo %second%
Quote from: dbenham on December 17, 2014, 05:15:07 PM

Beat me to it by a matter of seconds 
 
Gotta be quick over here Dave. Thanks for addition.  I saw the space in the 2nd token but figured they could figure out how to strip it.Shouldn't that be second=%%C.
Code: [Select]echo off
for /f usebackq^ tokens^=1^*^ delims^=^" %%A in ("file.txt") do for /f "tokens=*" %%C in ("%%B") do (
  set "first=%%A"
  set "second=%%C"
)
echo %first%
echo %second%
pauseLemonilla, thank you for fixing my example. I would like to use a space for the delimiter. Unfortunately, this may be too difficult.

Squashman, Thank you for offering another way. That is, going back one step and extracting the text form the file and splitting the text in one go. However, I notice that it only works if there is a space in the first path. There may be, in my case, where there is no space or more than one space in the first path and the script fails. As mentioned above, I might need to change my delimiter.

I am not understanding you. It works with the example you provided. If it is not working then provide a non obfuscated example of your data that it is not working with.OK, yes it does work with the example I supplied. But, as I said if there are more or less spaces in the path it fails.
I intended to enter more than one line in the file.txt file and process each line in turn.
A couple of real examples:

D:\MyProgs\DriveGleam\drivegleam.exe /startup
"C:\Program Files (X86)\DropMyRights\DropMyRights.exe" "C:\Program Files (x86)\Mozilla Thunderbird\thunderbird.exe"

Just to show a couple.Shouldn't have any problems with spaces as the code is using the double quote as the delimiter. But, you need to be consistent with your input. One example you just showed has no quotes.Thank you. I thought that script was using 2 spaces as the delimiter. Goes to show how well I understand batch scripting.
I'll use double quotes. Quote from: Frank on December 17, 2014, 08:34:24 PM
Thank you. I thought that script was using 2 spaces as the delimiter. Goes to show how well I understand batch scripting.
I'll use double quotes.
I did specifically say in my first post I was using a double quote as the delimiter. Quote from: Frank on December 17, 2014, 08:34:24 PM
Thank you. I thought that script was using 2 spaces as the delimiter.
I'll use double quotes.

if you can control the delimiter and are using filename\paths then using a pipe character is a good choice as a delimiter. 
or a * or ? or < or > as none of them can be in a path\filename.

Quotes are a poison character in batch scripts in many ways.

Quote from: foxidrive on December 17, 2014, 11:26:04 PM
if you can control the delimiter and are using filename\paths then using a pipe character is a good choice as a delimiter. 
I am in 100% agreement with you on that. It works flawlessly for us where I work.  I do data automation for a living and we have all of our customers send in their data PIPE delimited.
979.

Solve : Shutdown the computer using an .exe file done in Code Blocks?

Answer»

Hello guys.
I am NEW on this forum and new also new in learn about batch file.
Me question is about a code made it in c programming.
If i run this code allows me to shutdown the computer,but also i want to run this code in a batch file to shutdown the computer.
The path of this code is : C:\Users\mircea\Desktop\Shutdown My Computer\bin\Debug\Shutdown My Computer.exe.
I have tried many options but no result.

Look at this code in C :
Code: [Select]#include <stdio.h>
#include <stdlib.h>

int main()
{
    char ch;
    printf("\n Do you want to shutdown the computer (y/n) ?\n\n");
    printf("  ");
    scanf("%c", &ch);
    if(ch == 'y' || ch == 'Y')
        system("C:\\WINDOWS\\System32\\shutdown -s");
    return 0;
}

I wait some advices.
Thank you.
All the best.No clue why you are using a C program when you can do it all in batch.
But to run your executable from a batch file just PUT this in a batch file.
Code: [Select]"C:\Users\mircea\Desktop\Shutdown My Computer\bin\Debug\Shutdown My Computer.exe"I ALWAYS wonder why there are so many people who write batch code in C.why not just
shutdown /r /f

980.

Solve : Help needed for a batch file to extract data from text files?

Answer»

Hi,

I have over 1000 TEXT files.  The files are located in about 40 subdirectories, all within a single parent directory.  All files are in the same format (example file below).  I would LIKE to be able to extract data to a single output txt file as follows:

2014-02-26 21.51.53.000.TIF, -38.72672, 176.05866, 1413.2

Note the first output field is the input filename, but with the suffix changed to .tif. 

I am hoping SOMEONE can help me WRITE a batch file that would do this.  I have no experience writing batch files.

Regards,
Mark

EXAMPLE FILE
File name:  2014-02-26 21.51.53.000.txt

latitude=-38.72672
longitude=176.05866
height=1413.2
nSatellites=9
GPSHeading=146.1105594523
speed=64.2541111111
yaw=146.1105594523
pitch=-1
roll=-1
nFlightLine=1
nImageNumber=1
AVIATRIX_VERSION=5th DEC 2013
LUTFile=5
computerTimeStamp=201402262153015648
imageFormat=TIFF
imageWidth=640
imageHeight=480
imagePixelDepth=0
imageMode=0
minPixelValue=12716
maxPixelValue=12865
cameraModelName=FLIR A615
selectedCamera=A615
cameraDate=26/02/2014 9:53:01 AM
cameraMS=476
temperatureUnits=0
focusMotorState=stop
focusAbsolutePosition=5071
currentType=15
currentLens=
deviceType=8
commPort=0
zoomFactor=1
frameRate=25
//////////////////////////////////////////////////
/////////////// DEBUG STUFF BELOW ////////////////
//////////////////////////////////////////////////
validGPSSignal=True
outputPath=C:\TIR data\wk-th\FlightPlanner\wk-th  2014-02-13\Aviatrix\2014-02-26 21.25.10
bConnected=True
MD_filename=C:\TIR data\wk-th\FlightPlanner\wk-th  2014-02-13\Aviatrix\2014-02-26 21.25.10\METADATA\RUN1\2014-02-26 21.51.53.000.txt
freeRunMode=False
flightLineMode=True
flightPlanFile=wk-th.fpl
freeRunFrequency_at_10Hz=40
cameraName=FLIR A615-25
trackBarOffTrackTolerance=77.5677496332519
distanceToFlightLine=29.9671440045477
sideOfFlightLine=LEFTThis is close:

Code: [Select]echo off
(
for /f "delims=" %%a in ('dir *.txt /a:-d /b /s') do (
 set /p "=%%~na.tif,"<nul
 set "skip="
   for /f "usebackq tokens=1,2 delims==" %%b in ("%%a") do (
      if not defined skip set /p "=%%c,"<nul
      if "%%b"=="height" set skip=1
   )
 echo(
 )
)>"file.log"

981.

Solve : Handle ampersand "&" inputted by user in batch file.?

Answer»

I have a batch file that takes user input and places it in a variable. The problem is that sometimes the user may enter an "&" symbol which then causes the script to TRY to process the string after the & as a command.  I need the script to take the ampersand and place it variable string and then convert it to url encoding. For example:

User is prompted: What is your company NAME?
User inputs: You & Me
variable1= You & Me
variable2= You%26Me

Is this possible?

Code: [Select]echo off &setlocal enabledelayedexpansion
set /p "variable1=Enter Input:"

set "variable2=!variable1:&=%%26!"
echo %variable2%output
Code: [Select]C:\Batch\Ampersand>Ampersand.bat
Enter Input:You & Me
You %26 MeI see you posted an almost similar question in the Computer Programming category.  The code is basically the same as what Salmon Trout had posted for you for the spaces. Not sure why you didn't attempt to modify his code for the Ampersand replacement.To the OP, if it's URL encoded then the spaces also need encoding in your example.

Code: [Select]echo off &setlocal enabledelayedexpansion
set /p "variable1=Enter Input:"
set "variable2=!variable1:&=%%26!"
set "variable2=!variable2: =%%20!"
echo "%variable2%" Quote from: Squashman on January 06, 2015, 08:36:26 PM

I see you posted an almost similar question in the Computer Programming category.  The code is basically the same as what Salmon Trout had posted for you for the spaces. Not sure why you didn't attempt to modify his code for the Ampersand replacement.

I actually did, but with the code:
Code: [Select]echo off & setlocal enabledelayedexpansion
set /p "variable1=Enter Input:"
set "variable2=!variable1:&=%%26!"
set "variable3=!variable2: =%%20!"
set "variable4=!variable3:,=%%2c!"
echo %variable1%
echo %variable2%
echo %variable3%
echo %variable4%
pause

I get the output:
Code: [Select]Enter Input:you, me, & them
you, me,
'them' is not recognized as an internal or external command,
operable program or batch file.
you, me, %26 them
you,%20me,%20%26%20them
you%2c%20me%2c%20%26%20them
Press any key to continue . . .
Because the input has an Ampersand you either need to enclose it in quotes or use Delayed EXPANSION to ECHO the contents.
Code: [Select]echo off & setlocal enabledelayedexpansion
set /p "variable1=Enter Input:"
set "variable2=!variable1:&=%%26!"
set "variable3=!variable2: =%%20!"
set "variable4=!variable3:,=%%2c!"
echo %variable1%
echo "%variable1%"
echo !variable1!
echo %variable2%
echo %variable3%
echo %variable4%
pauseoutput
Code: [Select]Enter Input:you, me, & them
you, me,
'them' is not recognized as an internal or external command,
operable program or batch file.
"you, me, & them"
you, me, & them
you, me, %26 them
you,%20me,%20%26%20them
you%2c%20me%2c%20%26%20them
Press any key to continue . . .And there is also the SET /P trick, which doesn't require the use of Delayed Expansion.
Code: [Select]echo off & setlocal enabledelayedexpansion
set /p "variable1=Enter Input:"
set "variable2=!variable1:&=%%26!"
set "variable3=!variable2: =%%20!"
set "variable4=!variable3:,=%%2c!"
set /p ".=%variable1%"<nul
echo/
echo %variable2%
echo %variable3%
echo %variable4%
pauseoutput
Code: [Select]Enter Input:you, me, & them
you, me, & them
you, me, %26 them
you,%20me,%20%26%20them
you%2c%20me%2c%20%26%20them
Press any key to continue . . .
982.

Solve : May I advetise a free product??

Answer»

Hi!  Joseph Rose a.k.a. Harry Potter, here.  I read PARTS of the agreement, and it said that I can't advertise.  Is it okay to advertise and share freeware here?     I have some....No. And thank your for asking.Oh.  You might want to go to a website where it has a list of freeware and try there instead.
also get a website and a GNU General Public License.I have a site on sourceforge.net and have been advertising in two DOS NEWSGROUPS.  Where else can I distribute and advertise DOS software?Well, ask some of you buddies on another forum if they are members of this forum. And if they would recommend your stuff on this forum and give a link to a good download site.
So many sites and now offering 'free software' along with SPAM and Spyware that some of use an recalcitrant to recommend anything anymore. 
Quote from: Harry Potter on January 01, 2015, 04:16:04 PM

Where else can I distribute and advertise DOS software?
Not here...

Utilities written by and for 30 year old software development software appeal to a very small fraction of people.
Someone named Harry Potter has posted a few batch files on Usenet in alt.msdos.batch.nt in recent weeks and also asked where else to publish them.

Was that you?  Is that what you are creating - they were batch files. Quote from: foxidrive on January 01, 2015, 09:59:09 PM
Someone named Harry Potter has posted a few batch files on Usenet in alt.msdos.batch.nt in recent weeks and also asked where else to publish them.

Was that you?  Is that what you are creating - they were batch files.

Assuming the "Harry Potter" nick on sourceforge is the same individual, it SEEMS one is a VBDOS program designed to create file templates, which is apparently a feature in Win32 according to the readme. The other is a .DSK file with no documentation that I'm unable to open with Winimage.If any of it is open source you can post it on github etc. I posted a few projects there I wrote in C++ for the taking as open source as well as compiled form for download.

Its nothing that you could ever make any money on, but might be useful to someone else as it was for myself. 

Just think of all the programs that people custom write for a specific purpose that many probably wont use so its not a money making program idea, but could be useful to others.

As open source, people can download the source and alter it as they want or look at it and know its clean and compile their own copy of the program etc. No hidden Surprises vs a downloaded EXE or a MSI installer etc with unwanted problems bundled within.I thank all of you for your interest.  I am the one who posted the batch file.  Also, the .dsk files aren't WinImage disk images but Apple2 disk images.  The BSW image is an empty data disk for Bank Street Writer, a simple Apple2 word processor for students.  I also have two ProDOS images: one directly from the internet, and one that immediately loads into the menu.  For the Win32 audience: don't worry.  Template Creator for Windows is under production.    BTW, I could use more templates.  It was never designed to be a money-making scheme but to fulfill a need I had and thought it would HELP others.  This leaves me with the same problem: where else can I advertise DOS software on-line?  As a matter of face, Win32 software as well?Just create a website of the programs you make and Google will inevitably index your site. Someone is bound to search for something you may have created.I already have the files on sourceforge.net.  As for my own web site, I started to, but it didn't get far.  Do I have permission to share what the program is?
983.

Solve : Invalid Parameter?

Answer»

I have a function that doesn't work in context, but does as an independent program.  One of the 3rd party external commands I am using (convert) is throwing a Invalid Parameter error.  Any ideas why?

Both montage and convert are from imagemagick = http://www.imagemagick.org/index.php


Code: (fail) [Select]
T:\mtg>pushd "T:\mtg\\packs\pack_1"

T:\mtg\packs\pack_1>montage -geometry 400x550 card_0.jpg card_1.jpg card_2.jpg c
ard_o_1.jpg

T:\mtg\packs\pack_1>montage -geometry 400x550 card_3.jpg card_4.jpg card_5.jpg c
ard_o_2.jpg

T:\mtg\packs\pack_1>montage -geometry 400x550 card_6.jpg card_7.jpg card_8.jpg c
ard_o_3.jpg

T:\mtg\packs\pack_1>montage -geometry 400x550 card_9.jpg card_10.jpg card_11.jpg
 card_o_4.jpg

T:\mtg\packs\pack_1>montage -geometry 400x550 card_12.jpg card_13.jpg card_14.jp
g card_o_5.jpg

T:\mtg\packs\pack_1>montage -geometry 550x1200 -rotate 90 card_o_1.jpg card_o_1.
jpg

T:\mtg\packs\pack_1>montage -geometry 550x1200 -rotate 90 card_o_2.jpg card_o_2.
jpg

T:\mtg\packs\pack_1>montage -geometry 550x1200 -rotate 90 card_o_3.jpg card_o_3.
jpg

T:\mtg\packs\pack_1>montage -geometry 550x1200 -rotate 90 card_o_4.jpg card_o_4.
jpg

T:\mtg\packs\pack_1>montage -geometry 550x1200 -rotate 90 card_o_5.jpg card_o_5.
jpg

T:\mtg\packs\pack_1>montage -geometry 550x1200 card_o_1.jpg card_o_2.jpg card_o_
3.jpg pg_1.jpg

T:\mtg\packs\pack_1>montage -geometry 550x1200 card_o_4.jpg card_o_5.jpg pg_2.jp
g

T:\mtg\packs\pack_1>montage -geometry 1200x1650 -rotate 270 pg_1.jpg pg_1.jpg

T:\mtg\packs\pack_1>montage -geometry 1200x1100 -rotate 270 pg_2.jpg pg_2.jpg

T:\mtg\packs\pack_1>convert pg_1.jpg 1.pdf
Invalid Parameter - 1.pdf

T:\mtg\packs\pack_1>convert pg_2.jpg 2.pdf
Invalid Parameter - 2.pdf

T:\mtg\packs\pack_1>popd
Code: (pass) [Select]
T:\mtg\packs\pack_1>..\..\montage -geometry 400x550 card_0.jpg card_1.jpg card_2
.jpg card_o_1.jpg

T:\mtg\packs\pack_1>..\..\montage -geometry 400x550 card_3.jpg card_4.jpg card_5
.jpg card_o_2.jpg

T:\mtg\packs\pack_1>..\..\montage -geometry 400x550 card_6.jpg card_7.jpg card_8
.jpg card_o_3.jpg

T:\mtg\packs\pack_1>..\..\montage -geometry 400x550 card_9.jpg card_10.jpg card_
11.jpg card_o_4.jpg

T:\mtg\packs\pack_1>..\..\montage -geometry 400x550 card_12.jpg card_13.jpg card
_14.jpg card_o_5.jpg

T:\mtg\packs\pack_1>..\..\montage -geometry 550x1200 -rotate 90 card_o_1.jpg car
d_o_1.jpg

T:\mtg\packs\pack_1>..\..\montage -geometry 550x1200 -rotate 90 card_o_2.jpg car
d_o_2.jpg

T:\mtg\packs\pack_1>..\..\montage -geometry 550x1200 -rotate 90 card_o_3.jpg car
d_o_3.jpg

T:\mtg\packs\pack_1>..\..\montage -geometry 550x1200 -rotate 90 card_o_4.jpg car
d_o_4.jpg

T:\mtg\packs\pack_1>..\..\montage -geometry 550x1200 -rotate 90 card_o_5.jpg car
d_o_5.jpg

T:\mtg\packs\pack_1>..\..\montage -geometry 550x1200 card_o_1.jpg card_o_2.jpg c
ard_o_3.jpg pg_1.jpg

T:\mtg\packs\pack_1>..\..\montage -geometry 550x1200 card_o_4.jpg card_o_5.jpg p
g_2.jpg

T:\mtg\packs\pack_1>..\..\montage -geometry 1200x1650 -rotate 270 pg_1.jpg pg_1.
jpg

T:\mtg\packs\pack_1>..\..\montage -geometry 1200x1100 -rotate 270 pg_2.jpg pg_2.
jpg

T:\mtg\packs\pack_1>..\..\convert pg_1.jpg pg_1.pdf

T:\mtg\packs\pack_1>..\..\convert pg_2.jpg pg_2.pdf

T:\mtg\packs\pack_1>pause
Press any key to continue . . .

Code: (Stand Alone) [Select] ..\..\montage -geometry 400x550 card_0.jpg card_1.jpg card_2.jpg card_o_1.jpg
..\..\montage -geometry 400x550 card_3.jpg card_4.jpg card_5.jpg card_o_2.jpg
..\..\montage -geometry 400x550 card_6.jpg card_7.jpg card_8.jpg card_o_3.jpg
..\..\montage -geometry 400x550 card_9.jpg card_10.jpg card_11.jpg card_o_4.jpg
..\..\montage -geometry 400x550 card_12.jpg card_13.jpg card_14.jpg card_o_5.jpg

..\..\montage -geometry 550x1200 -rotate 90 card_o_1.jpg card_o_1.jpg
..\..\montage -geometry 550x1200 -rotate 90 card_o_2.jpg card_o_2.jpg
..\..\montage -geometry 550x1200 -rotate 90 card_o_3.jpg card_o_3.jpg
..\..\montage -geometry 550x1200 -rotate 90 card_o_4.jpg card_o_4.jpg
..\..\montage -geometry 550x1200 -rotate 90 card_o_5.jpg card_o_5.jpg

..\..\montage -geometry 550x1200 card_o_1.jpg card_o_2.jpg card_o_3.jpg pg_1.jpg
..\..\montage -geometry 550x1200 card_o_4.jpg card_o_5.jpg pg_2.jpg

..\..\montage -geometry 1200x1650 -rotate 270 pg_1.jpg pg_1.jpg
..\..\montage -geometry 1200x1100 -rotate 270 pg_2.jpg pg_2.jpg

..\..\convert pg_1.jpg pg_1.pdf
..\..\convert pg_2.jpg pg_2.pdf
pause
Code: (function) [Select]:combine_Image dir
REM the dir referenced by ..\.. was added to path earlier in the script
echo on
pushd %1
montage -geometry 400x550 card_0.jpg card_1.jpg card_2.jpg card_o_1.jpg
montage -geometry 400x550 card_3.jpg card_4.jpg card_5.jpg card_o_2.jpg
montage -geometry 400x550 card_6.jpg card_7.jpg card_8.jpg card_o_3.jpg
montage -geometry 400x550 card_9.jpg card_10.jpg card_11.jpg card_o_4.jpg
montage -geometry 400x550 card_12.jpg card_13.jpg card_14.jpg card_o_5.jpg

montage -geometry 550x1200 -rotate 90 card_o_1.jpg card_o_1.jpg
montage -geometry 550x1200 -rotate 90 card_o_2.jpg card_o_2.jpg
montage -geometry 550x1200 -rotate 90 card_o_3.jpg card_o_3.jpg
montage -geometry 550x1200 -rotate 90 card_o_4.jpg card_o_4.jpg
montage -geometry 550x1200 -rotate 90 card_o_5.jpg card_o_5.jpg

montage -geometry 550x1200 card_o_1.jpg card_o_2.jpg card_o_3.jpg pg_1.jpg
montage -geometry 550x1200 card_o_4.jpg card_o_5.jpg pg_2.jpg

montage -geometry 1200x1650 -rotate 270 pg_1.jpg pg_1.jpg
montage -geometry 1200x1100 -rotate 270 pg_2.jpg pg_2.jpg

convert pg_1.jpg 1.pdf
convert pg_2.jpg 2.pdf

::del *.jpg
popd
goto :eof
would giving the full name with file extension help SINCE the system might not know that convert is an EXE for example so if convert is an exe you can change it to:

T:\mtg\packs\pack_1>..\..\convert.exe pg_1.jpg pg_1.pdf

T:\mtg\packs\pack_1>..\..\convert.exe pg_2.jpg pg_2.pdf


Not sure if you would also have to place the pg_1.jpg pg_1.pdf within " " or not as well, but I'd try first without the " "

I have run into similar issues with some perl scripts that I made that call to other utilities etc to perform processes beyond that of batch etc, and adding the full name with file extension fixed it for me.

CONVERT is an internal command to Windows.  So you need to specify the full path to the convert program you are using. QUOTE from: Squashman on December 14, 2014, 03:33:41 PM

CONVERT is an internal command to Windows.  So you need to specify the full path to the convert program you are using.

I will try that, but I don't think that's the issue as the program is executing.  It just isn't recognizing one of the inputs that It would normally recognize. Quote from: Lemonilla on December 14, 2014, 05:06:00 PM
I will try that, but I don't think that's the issue as the program is executing.  It just isn't recognizing one of the inputs that It would normally recognize.
Yes it is executing Windows Convert command.  See my output. LOOKS just like your error.
Code: [Select]C:\Users\Squashman>convert pg_1.jpg 1.pdf
Invalid Parameter - 1.pdf Quote
It just isn't recognizing one of the inputs that It would normally recognize.

Do the files have to be within " " MAYBE?

such as

T:\mtg\packs\pack_1>..\..\convert.exe "pg_1.jpg pg_1.pdf"

T:\mtg\packs\pack_1>..\..\convert.exe "pg_2.jpg pg_2.pdf"Oh, I didn't realize windows had a convert command. That fixed it, thanks! Quote from: Lemonilla on December 14, 2014, 06:08:40 PM
Oh, I didn't realize windows had a convert command. That fixed it, thanks!
Been there for almost 20 years. Basically since Windows NT came out. Quote from: Squashman on December 15, 2014, 06:22:02 AM
Been there for almost 20 years. Basically since Windows NT came out.
I got caught by this when I first started using Image Magick. In batch scripts you have to run the batch from the same folder as the IM convert.exe program, or provide the full path to it,  or rename the IM program, e.g. to imconvert.exe, or you can rename the Windows c:\windows\System32\convert.exe to something else (it converts FAT volumes to NTFS and if you have bever heard of it, you probably don't need it, and if you subsequently do, you can rename it back).


984.

Solve : adding to a script to send an email if a folders date modified is > 1 day?

Answer» HI guys,

using the script below i am successfully able to find if a folders date modified time is less than 1 day ignore it and if not, do an else command to create a TEXT file in a location.

what i need is to instead of create a text file, i need it to send an email to inform me it is greater than 1 day.

this is the current script;

dim filesys, filetxt, getname, path
Set objFSO = CreateObject("Scripting.FileSystemObject")
If objFSO.GetFolder("c:\test").DateLastModified >= Date - 1 Then
Wscript.quit
   Else if   objFSO.GetFolder("c:\test").DateLastModified <= Date - 1 Then
      Set filesys = CreateObject("Scripting.FileSystemObject")
      Set filetxt = filesys.CreateTextFile("c:\test\not created.txt", True)
      path = filesys.GetAbsolutePathName("c:\test\not created.txt")
      getname = filesys.GetFileName(path)
      filetxt.WriteLine("file doesnt exist.")
      filetxt.Close
   End if
end if

im using outlook 2013 and windows 7.

thanks!Is that code complete?

You can use a batch file to send an email using VBS,  and also use batch code to check if the folder date is not todays date
 - that's all your code seems to be doing (although the Date variable appears undefined).

I'm not sure how you are launching this - more info is needed. Quote from: foxidrive on January 22, 2015, 11:18:13 AM
the Date variable appears undefined

Date is a built-in VBscript function which returns the current system date, formatted according to the system locale settings. On my system wscript.echo Date produces 22/01/2015, and adding or subtracting numbers e.g. Date-1, Date+30 produces a similarly formatted date string, representing the date that number of days in the past or future.

Note to the OP: you mention files less than 1 day old, and files more than 1 day old. What do you want to do with files that are exactly ONE day old?






This is how you could try to send an email using Outlook. I only have Outlook 2003 so I don't know if it would work with Outlook 2013. You would probably need to change Outlook security settings to allow unattended scripted sending of emails.

Code: [Select]ToAddress = "[email PROTECTED]"
MessageSubject = "Subject goes here"
MessageBody = "Body message goes here."
Set ol = WScript.CreateObject("Outlook.Application")
Set ns = ol.getNamespace("MAPI")
Set newMail = ol.CreateItem(olMailItem)
newMail.Subject = MessageSubject
newMail.Body = MessageBody & vbCrLf & MyTime
newMail.RecipIents.Add(ToAddress)
newMail.Send

There are better ways of sending emails, like the CDO object.
Quote from: Salmon Trout on January 22, 2015, 12:57:05 PM
Date is a built-in VBscript function which returns the current system date, formatted according to the system locale settings.

Thanks Mr Trout.  You're very helpful to an old codger.

I did search the WSH help for 'date' and clicked on the few that looked likely suspects, but gave up too soon it looks like.

Foxidrive. Look at SS64 website. It has a list of all the VBscript commands just like it does for NT batch. Quote from: Squashman on January 22, 2015, 07:59:01 PM
Foxidrive. Look at SS64 website. It has a list of all the VBscript commands just like it does for NT batch.

Thanks Squashman.
985.

Solve : My Batch File will not Run Properly?

Answer»

I need help with the following batch program, it is supposed to check for the EXE WebFormApp.exe, if it is running then it should start Internet explorer. Otherwise it should start the WebFormApp.exe and then start Internet Explorer. the batch file below only works if the WebFormApp.exe is running. meaning it will open Internet Explorer. When the program is not running, it will run it and the cmd window will stay open.

what is the best way for me to do this?? I need this batch to be able to run WebFormApp.exe when ProcessNotFound is true, then launch Internet explorer. I'm a novice at this and your detailed help is greatly appreciated.

:ProcessNotFound
echo %EXE% is not running
"C:\Program Files (x86)\Common Files\STF SERVICES Shared\WebFormApp.exe" -start


echo off
SETLOCAL EnableExtensions
set EXE=WebFormApp.exe

FOR /F %%X IN ('tasklist /NH /FI "IMAGENAME eq %EXE%"') DO IF %%x == %EXE% goto ProcessFound

goto ProcessNotFound

:ProcessFound
echo %EXE% is running
start "C:\Program Files\Internet Explorer" IEXPLORE.EXE taxandaccounting.bna.com/btac/
goto END

:ProcessNotFound
echo %EXE% is not running
"C:\Program Files (x86)\Common Files\STF Services Shared\WebFormApp.exe" -start
goto END

:END
echo Finished!


thanksWithout having WebFormApp.exe in front of me, I don't know what the -start switch does, so I'll take if for granted that it's what you want.
One of the things you should know is that you never start the WebFormApp.exe after you start iexplorer.  Here is something to try:
Code: [Select]echo off
SETLOCAL EnableExtensions
set EXE=WebFormApp.exe

REM you can also use tasklist's /im "imagename" switch
FOR /F %%x IN ('tasklist /NH /FI "IMAGENAME eq %EXE%"') DO IF %%x == %EXE% goto ProcessFound

goto :ProcessNotFound

:ProcessFound
echo %EXE% is running
start "C:\Program Files\Internet Explorer" IEXPLORE.EXE taxandaccounting.bna.com/btac/
REM I removed this ' goto :END ' statement so that it will continue down to start WebFormApp.exe.

:ProcessNotFound
echo %EXE% is not running
"C:\Program Files (x86)\Common Files\STF Services Shared\WebFormApp.exe" -start
goto :END

:END
echo Finished!This is what I came Up with You will have to fix where the files are and the exe and stuff.
Code: [Select]echo off
title BLA
::WILL  NOT  WORK UNLESS YOU FIX WHERE THE FILES AND FOLDERS ARE!!!
:presets
set exe=blah
set isRunning=unknown
if "%isRunning%" == "unkown" (
    ::Copyed Code of Yours
FOR /F %%x IN ('tasklist /NH /FI "IMAGENAME eq %EXE%"') DO IF %%x == %EXE% (
set isRunning=yes
) else (
set isRunning=no
)
)
goto start
:start
if "%isRunning%" == "yes" (
start folders/ie.exe
goto end
)
if "%isRunning%" == "no" (
start folders/%blah%.exe
set isRunning=yes
if "%isRunning%" == "yes" (
start folders/ie.exe
goto end
)
)

:end
echo I'm done
ping localhost -n 3 >nul
exitThank you for all your replies, I spoke to the vendor of the application and he tells me that the -start switch has to be at the end of the path otherwise the program will not start from a batch file. example
"C:\Program Files (x86)\Common Files\STF Services Shared\WebFormApp.exe" -start . the problem is when the batch RUNS the cmd window never closes... I tried Exit and taskkill, but the batch file never reads anything past -start.

I will attach the msi file for WebFormApp.exe if anyone is WILLING to help. the file size is 1.7MB therefore I can't upload it here... but willing to send by email or it can be downloaded from Bloomberg Tax and accounting center.

thank.Batch files do sequential processing.  What this means is that if you launch an application from your batch file it will wait for that application to finish and exit before it MOVES on to the next command.
The work around for this as Shiverbob has pointed out is to use the internal START command to execute your application.  This spawns a new process and returns control back the batch file.

So you need to do something like this.
Code: [Select]START "Launching WebFormApp" "C:\Program Files (x86)\Common Files\STF Services Shared\WebFormApp.exe" -startSquashman - thank you for your help, your suggestion worked.

986.

Solve : Checking Variables?

Answer»

It has been a long time since I have coded in Batch. There is a problem that I can't not figure out. I am making a Tic-Tac-Toe game, and when I have the player ENTER their choice via "set /p" and it goes through the process of setting the VARIABLE, which works fine. But what if they enter one that has already been selected. I do not know how to check the variable without having a bunch of if statements.

Thanks, Shiverbob

Code: Code: [Select]echo off
setlocal enabledelayedexpansion
title Tic Tac Toe

:presets
::x o
set player=player
set 11=
set 12=
set 13=
set 21=
set 22=
set 23=
set 31=
set 32=
set 33=
set turn=x
goto start
:check


:turnCheck

if "!turn!" == "x" (
set turn=o
goto start
)
if "!turn!" == "o" (
set turn=x
goto start
)
goto turnCheck
:start
cls
echo  !player! versus CPU
echo ----------------------
echo 1 2 3
echo !11!Û!21!Û!31! 1
echo ÛÛÛÛÛ
echo !12!Û!22!Û!32! 2
echo ÛÛÛÛÛ
echo !13!Û!23!Û!33! 3
echo.
set /p K=!turn! Turn:
goto turnSet


:turnSet

if "!k!" == "11" (
set 11=!turn!
goto turnCheck
)
if "!k!" == "12" (
set 12=!turn!
goto turnCheck
)
if "!k!" == "13" (
set 13=!turn!
goto turnCheck
)
if "!k!" == "21" (
set 21=!turn!
goto turnCheck
)
if "!k!" == "22" (
set 22=!turn!
goto turnCheck
)
if "!k!" == "23" (
set 23=!turn!
goto turnCheck
)
if "!k!" == "31" (
set 31=!turn!
goto turnCheck
)
if "!k!" == "32" (
set 32=!turn!
goto turnCheck
)
if "!k!" == "33" (
set 33=!turn!
goto turnCheck
)
goto start
Code: [Select]echo off
setlocal enabledelayedexpansion
title Tic Tac Toe

:presets
::x o
set player=player
set 11=
set 12=
set 13=
set 21=
set 22=
set 23=
set 31=
set 32=
set 33=
set turn=x
goto start
:check


:turnCheck

if "!turn!" == "x" (
set turn=o
goto start
)
if "!turn!" == "o" (
set turn=x
goto start
)
goto turnCheck
:start
cls
echo  !player! versus CPU
echo ----------------------
echo 1 2 3
echo !11!Û!21!Û!31! 1
echo ÛÛÛÛÛ
echo !12!Û!22!Û!32! 2
echo ÛÛÛÛÛ
echo !13!Û!23!Û!33! 3
echo.
set /p k=!turn! Turn:
goto turnSet


:turnSet

if NOT "!%k%!"==" " goto start
if "!k!" == "11" (
set 11=!turn!
goto turnCheck
)
if "!k!" == "12" (
set 12=!turn!
goto turnCheck
)
if "!k!" == "13" (
set 13=!turn!
goto turnCheck
)
if "!k!" == "21" (
set 21=!turn!
goto turnCheck
)
if "!k!" == "22" (
set 22=!turn!
goto turnCheck
)
if "!k!" == "23" (
set 23=!turn!
goto turnCheck
)
if "!k!" == "31" (
set 31=!turn!
goto turnCheck
)
if "!k!" == "32" (
set 32=!turn!
goto turnCheck
)
if "!k!" == "33" (
set 33=!turn!
goto turnCheck
)
goto startYou technically do not need to use delayed expansion for all your other IF commands but you need it for the one I added.Here is a slightly more optimized version of your code.  I look forward to seeing your WIN logic.
Code: [Select]echo off
setlocal enabledelayedexpansion
title Tic Tac Toe

:presets
::x o
set player=player
FOR /L %%G IN (1,1,3) DO FOR /L %%H IN (1,1,3) DO SET "%%G%%H= "
set turn=x
goto start
:check


:turnCheck

if "%turn%"=="x" (
set turn=o
goto start
)
if "%turn%"=="o" (
set turn=x
goto start
)
goto turnCheck
:start
cls
echo  %player% versus CPU
echo ----------------------
echo 1 2 3
echo !11!Û!21!Û!31! 1
echo ÛÛÛÛÛ
echo !12!Û!22!Û!32! 2
echo ÛÛÛÛÛ
echo !13!Û!23!Û!33! 3
echo.
set /p k=%turn% Turn:

:turnSet

if NOT "!%k%!"==" " goto start

FOR /L %%G IN (1,1,3) DO (
FOR /L %%H IN (1,1,3) DO (
IF "%%G%%H"=="%k%" (
SET %k%=%turn%
goto turncheck
)
)
)
goto startMy win solution requires if statements to be nested into each other. However, when I nest if statements together it crashes. Could it be the fact the the second if statement is false. It also crashes when i enter a different cord-nets.
And is it  possible to have a if "!var!" == "bah" || "bal"?

Code: [Select]echo off
setlocal enabledelayedexpansion
title Tic Tac Toe

:presets
::x o
set player=Logan
set 11=
set 12=
set 13=
set 21=
set 22=
set 23=
set 31=
set 32=
set 33=
set turn=x
goto start
:check


:turnCheck

if "!turn!" == "x" (
set turn=o
goto start
)
if "!turn!" == "o" (
set turn=x
goto start
)
goto turnCheck
:start
cls
echo  !player! versus CPU
echo ----------------------
echo 1 2 3
echo !11!л!21!л!31! 1
echo ллллл
echo !12!л!22!л!32! 2
echo ллллл
echo !13!л!23!л!33! 3
echo.
set /p k=!turn! Turn:
goto turnSet


:turnSet

if "!k!" == "11" (
set 11=!turn!
goto wincheck
)
if "!k!" == "12" (
set 12=!turn!
goto wincheck
)
if "!k!" == "13" (
set 13=!turn!
goto wincheck
)
if "!k!" == "21" (
set 21=!turn!
goto wincheck
)
if "!k!" == "22" (
set 22=!turn!
goto wincheck
)
if "!k!" == "23" (
set 23=!turn!
goto wincheck
)
if "!k!" == "31" (
set 31=!turn!
goto wincheck
)
if "!k!" == "32" (
set 32=!turn!
goto wincheck
)
if "!k!" == "33" (
set 33=!turn!
goto wincheck
)
goto start

:wincheck
:: Way one bottom row
:: o o
:: o o x
:: x x x
:: 13 23 33
::for /l %%g in (1,1,3) do (
::)

if "!13!" == "x" (
 echo hello
 pause
if "!23!" == "x"(
  echo hello
  pause
)
)

if "!win!" == "3x" goto xwin
if "!win!" == "3o" goto owin
goto turncheck

:owin
cls
echo o Has won!!
set /p c=Would you like to  have another game?(y/n):
if "!c!" == "n" exit
if "!c!" == "y" goto presets
goto owin
:xwin
cls
echo x Has won!!
set /p c=Would you like to  have another game?(y/n):
if "!c!" == "n" exit
if "!c!" == "y" goto presets
goto xwin


But when I used a for loop it would work however if you enter the last cordnets  and there is no winner YET it skips that and say whatever player is on there, they win.



is this what you need to do?

Code: [Select]if "!13!" == "x" if "!23!" == "x" (
  echo hello
  pause
)


A problem in your code is that the ( needs a space before it here:

Code: [Select]if "!23!" == "x"(
  echo hello
  pause
)You are overthinking it. In its simplest form you only need 8 IF statements and none of them need to be nested.And stop using delayed expansion for your variables when you dont have to use it.Last Night I finished the game, with delayed-expansion. All works fine. The reason I added delayed-expansion was for my multiplayer add-on... It runs with nested if and is about 100 lines of code. Thanks for the help!Seems like it would be appropriate to post your final code otherwise people who read this thread in the future will see it as unfinished. Depending on what you were trying to do I still believe you could code it without using delayed expansion. Quote from: shiverbob on January 06, 2015, 08:01:36 PM

I am very bored
Apparently you are too busy.

In your other thread you talk about writing code together but you haven't bothered to share your final code.  If you are going to ask for help in writing code then it is polite to share the entire code after you are finished.I don't have it. I gave it to my friend, and I didn't back it up sorry. And my multiplayer peice of code requires delayedExpansion and all it does is send it to a text file with the (echo whatever ) >> file.txt  And there you have it...This rates right up there with JacobRocks not enough time excuse. Front runners for the Nebulous Request of the Month Award...
987.

Solve : Batch file to delete file?

Answer»

Hello,

I am in need of a batch file to automatically delete a file older in some stated hours
at a specified hourly interval. I have a system that generates a report at some hourly
interval. It renames the new one leaving the old one still there. With this i require a
batch file to periodically delete the old file base on some hours older.

Thanks.
If all you are doing is keeping the newest file in the folder then this should WORK. Run this batch file outside of the folder it is working on.  Make sure you test this on some test files first.
Code: [Select]echo off
pushd "c:\folder path"
FOR /F "skip=1 delims=" %%G in ('dir /a-d /B /o-d') do del "%%~G"
popdI tried your script in a temporal folder and it deleted all files including it self and leaving just
the current one. My folder contains some other files and i don't want to end up deleting
other files as well. Please modify it to not delete other files. Thanks. Quote from: Akod on January 11, 2015, 11:24:59 AM

I tried your script in a temporal folder and it deleted all files including it self and leaving just
the current one. My folder contains some other files and i don't want to end up deleting
other files as well. Please modify it to not delete other files. Thanks.
If the batch file deleted itself then you didn't FOLLOW my instructions!!!!
Based on the information you gave me the script works as described.

Until you can supply more information on what folder the files are in and what files are in the folder and what files need to remain and what files need to be deleted there is little anyone can do to help you.  You need to think about what you are trying to do and be very specific with your instructions.Squashman, I suspect Akod doesn't have the knowledge to change this line:

Code: [Select]pushd "c:\folder path"
Akod - you must have failed to comprehend the instructions - why didn't you ask a question describing which part you didn't UNDERSTAND?Below is a description of the files in this location where the latest file is to be deleted:

Control3.dmp > (Time of creation 11:26pm)
Control2.dmp > (Time of creation 5:45pm)
schedule2 > (folder)
Schedule3 > (folder)
schedule > (folder)

The directory contains 2 files and 3 folders. The application we running automatically generates the two
files at the time indicated above. Because of low disk ISSUE, anytime a file is created, the old one needs
to be deleted.

Please hope this explanation helps to get a solution.
Thanks. You didn't answer all my questions but this again is the best I can do with the limited information.
Code: [Select]echo off
pushd "c:\folder path"
FOR /F "skip=1 delims=" %%G in ('dir /a-d /b /o-d control*.dmp') do del "%%~G"
popd
988.

Solve : check if Multiple Network Drives exist then Launch Application?

Answer»

I have 6 network drives that host applications, and are PUBLISHED in Terminal server. I currently use the batch FILE below to check for one network drive. I need help making this script check 6 network drives if they exist, if they do launch an APP. I tried various forms of if statements but wasn't successful. I am new to batch SCRIPTING, so your help is greatly appreciated.

echo off
IF EXIST T:\ (
GOTO SKIPPED
) ELSE (
NET USE T: "\\server1\data"
)
:SKIPPED
start "" "C:\directory\program.exe"You are kind of on the right path. You can use a FOR command to iterate through all the paths you have to check. Then use an IF EXIST as the DO part of the FOR command and add to a variable each time the IF is TRUE.
Then it is just a matter of checking to see if your counter variable is EQUAL to 6.Squashman has given you the advice - I'm just following up with a suggestion in code.

Code: [Select]echo off
set "skipped="
for %%a in (J K L M N O) do if not exist %%a:\ set skipped=1
if not defined skipped start "" "C:\directory\program.exe"Foxidrive I like that logic better.

989.

Solve : ntfs4dos?

Answer»

I use ntfs4dos.exe (only the executable) on a DOS 5.5 boot CD.
I downloaded the NTFS4DOS free utility and extracted the ntfs4dos.exe
When I type ntfs4dos.exe it mounts my ntfs partitions and a FAT32 partition.
When I try the command "DIR" in the root of a mounted (a just tried NTFS) partitions, it says: no files found and it shows nothing.
I've tried different times and one time it succeeded to show the directories.When I tried then to delete a file in a directory it says with the command "DEL": bad command.

Is this normal?Never heard of DOS 5.5.... there is however a DOS 5.0.5 http://en.wikipedia.org/wiki/MS-DOS

You might have better luck if you used FreeDOS INSTEAD which has features that integrated better with NTFS as well as legacy support for DOS commands instructions. Its based on Linux, but ACTS just LIKE MS DOS. Games written for DOS ALSO work within FreeDOS as far as Doom and Wolfenstein and Commander Keen etc.

Also there is no licensing issues against the EULA of Microsoft with its use on a bootable CD if going with FreeDOS etc.

http://www.freedos.org/

Why aren't you running it from eth bootdisk ? ?It's DOS 5.0 Sorry (I will try freedos)
Patio:What do you mean by ethernet bootdisk?
I have an internal DVD writer and an usb floppy but the usb floppy needs a windows driver so I can't boot from it.eth = THE ( typo )  Quote from: louis14 on January 04, 2015, 02:53:07 AM

When I type ntfs4dos.exe it mounts my ntfs partitions and a FAT32 partition.
When I try the command "DIR" in the root of a mounted (a just tried NTFS) partitions, it says: no files found and it shows nothing.

It would help to show the screen when the drives mount, for diagnostic purposes, plus the screen where you type in the commands.

Seeing is 98% of figuring out the issue.I've redirected my stdout of "dir"
dir > dir.txt

But I could not access the file dir.txt in windows7: "no access" when I wanted to open it in notepad

When I wanted to include stderr (because "file not found" is an stderr)
dir 1>dir2.txt 1>&1
I get the dos answer: too much parameters

I cannot redirect ntfs4dos.exe because it's an interactive command:there is an answer " yes" Quote from: louis14 on January 06, 2015, 09:47:42 AM
When I wanted to include stderr (because "file not found" is an stderr)
dir 1>dir2.txt 1>&1
I get the dos answer: too much parameters
STDERR is not file stream 1.  It is 2. Quote from: louis14 on January 06, 2015, 09:47:42 AM
But I could not access the file dir.txt in windows7: "no access" when I wanted to open it in notepad

Perhaps your account doesn't have read permission for that file.

This error also happens when you try to write the file in a root directory or other location, when the account doesn't have permissions to write there - the file is not created.

Quote
I cannot redirect ntfs4dos.exe because it's an interactive command:there is an answer " yes"

Use a phone and take images of the screen and upload them to a site - then include the links here.Here are my Phone images of my "dir" and my ntfs4dos" command.
The share link is:
http://www.filetolink.com/2855f94f6a
Sorry but the link asks a facebook or google login
I've tried to use the site senduit but there was a technical error Quote from: louis14 on January 09, 2015, 08:07:23 AM
Here are my Phone images of my "dir" and my ntfs4dos" command.
Sorry but the link asks a facebook or google login

Thanks for creating the files - the site is asking a lot to get people to use credentials just to download a file.

You can use a free dropbox account to share files without needing the downloader to log in.
Not gonna create a FBook account just to see your pics....thats just me. Quote from: patio on January 09, 2015, 06:51:33 PM
Not gonna create a FBook account just to see your pics....thats just me.
+1oI've rehosted the files:



Quote from: BC_Programmer on January 10, 2015, 12:52:50 AM
I've rehosted the files:

Thanks BC_Programmer.

louis14, the screenshots aren't complete and things could have happened between screenshot 1 and 2
but assuming they follow each other with nothing in between - it looks like Drive D: was mounted and it is in fact empty.

If I had access to the machine I would use these commands to determine if any other NTFS drive has files showing, and if the FAT32 drive does also.

Code: [Select]dir f:\
dir e:\
dir d:\
dir c:\

Assuming the FAT drive shows files, and
if all the NTFS drives show as empty, and still have files when examined under Windows, then the NTFS dos driver is failing.

The reason could be either :
  • a flawed NTFS driver,
  • an incorrect or missing parameter in the NTFS driver install command,
  • or the NTFS drive is a modern high capacity unit and the driver doesn't have support for it - or possibly because it is a SATA drive.


990.

Solve : delete zero byte files?

Answer»

I need some help I have a process that creates a file and another that will start other jobs based on the file existing however I need to delete the file if there is no data in it.  i.e. zero byte.

how do I delete a file if it has zero BYTES in a BATCH command? :-? :-?you can create an empty file, and use FC command (CHECK out fc /? ) to compare

  set zerofile=zerobyte
  copy nul %zerofile% &GT;nul
  for /f "delims=" %%a in ('dir/s/b/a-d') do (
    fc %zerofile% "%%a" >nul && del "%%a"
  )
  del %zerofile%I do not understand what you are telling me :-?  

I already have a file that may or may not be zero bytes.

when it is zero bytes I need to delete it so my next job will not run. Code: [Select]set zerofile=zerobyte
  copy nul %zerofile% >nul
This will copy a 0 byte file and name it as zerobyte. This file will be used later in the for loop to compare
file sizes

Code: [Select]  for /f "delims=" %%a in ('dir/s/b/a-d') do (
    fc %zerofile% "%%a" >nul && del "%%a"
  )
This will go to the directory where your files are, and compare their sizes with the file zerobyte
if they are 0 bytes,then delete

thank you that worked prefectly Or without creating the 0 byte file or calling FC, you can just check the size of the file like:
Code: [Select]  for /f "delims=" %%a in ('dir/s/b/a-d') do (
    if %%~za==0 del "%%a"
  )I have almost the same situation.
one file is zipped each day and it happends that ziping doesn't go well and I have 0 bytes zipped file.
So how can I delete that zipped file and start zipping original file again. In the same folder is more files so it must be file created today, which is zipped again.
all is in the folder d:/backupdb

batch for zipping file is
Code: [Select]FOR %%i IN (*.bak) DO 7z.exe a "%%~ni.7z" "%%i" Code: [Select]FOR %%i IN (*.bak) DO (
FOR %%G in (%%~ni.7z) DO IF "%%~zG"=="0" del "%%~G" 2>nul
7z.exe a "%%~ni.7z" "%%i"
)Start your own thread, don't try and re-use old ones.

991.

Solve : Help Needed : String Split issue in for loop... while process folders?

Answer»

Hello Everybody,

I am problem splinting the string in a loop.  I have a subroutine (:STRING_SPLIT ) that splits the string by delimiter and return the split value.  But the returned value is empty.
So for the debug purpose I called ":STRING_SPLIT"  in another wrapper subroutine ":SPLIT_WRAP" to check if the string split value is retuned and yes I am getting the value I want.
But I am not getting this string split value in the main.

My Requirement:-
-----------------------
I have a FOLDER structure like

+PHASE1         ( Directory)
++PREFERENCES    ( Sub - Directory)
+++SITE       ( Sub Sub - Directory)
+++GROUP      ( Sub Sub - Directory)
++++FIlE1.xml
++++FIlE2.xml
++++RUN.bat

Code:-
-----------------
Code: [Select]:: Set TITLE name...
SET JOB_TITLE=Executing:{ %ROOT_FOLDER% }
TITLE %JOB_TITLE%

ECHO #=================== START:: %ROOT_FOLDER% ========================#
FOR /f "tokens=*" %%D IN ('DIR /B /AD /ON') DO (
    ECHO #---"%%D"---#
    CD "%%D"
FOR /f "tokens=*" %%F IN ('DIR /B *') DO (
IF /I "%%D"=="Preferences" (
REM ECHO Importing file "%%F"...
IF /I "%%F"=="group" (
REM ECHO DO NOTHING..
CALL :LOAD_SUB "group" %%D
) ELSE IF /I "%%F"=="role" ( 
REM ECHO DO NOTHING..
CALL :LOAD_SUB "role" %%D
ECHO.
) ELSE (
ECHO Importing file "%%F"...
)
)
)
    CD ..
)
ECHO #=================== END:: %ROOT_FOLDER% ==========================#
cmd

:endext
endlocal
set EXITVALUE=%ERRORLEVEL%


:LOAD_SUB
::SETLOCAL
ECHO.
::SET CURRENT_DIR=%~1
REM ECHO I am processing %~1 preferences.
ECHO #---"%~2":"%~1"---#
CD "%~1"
FOR /f "tokens=*" %%P IN ('DIR /B *') DO (
:: IF EXIST *.xml( ECHO Importing file "%%P"... )
ECHO Processing file/directory "%%P"...
:: ECHO.CURRENT_DIR : %CURRENT_DIR%
    IF /I "%~2"=="Preferences" (

IF /I "%~1"=="role" (

CALL:STRING_SPLIT "%%P" "." "FileName" "FileExtn"
ECHO.FileName : %FileName%  REM $$$ ERROR : EMPTY VALUE
ECHO.FileExtn : %FileExtn%  REM $$$ ERROR : EMPTY VALUE
IF /I "%FileExtn%"=="XML" (

:: CALL IMPORT COMMAND
:: CALL :IMPORT_PREFERENCES "%%P"
)
)
)
)
CD..
::ENDLOCAL
GOTO:EOF


:STRING_SPLIT
:: CALL:STRING_SPLIT %data% "." "FileName" "FileExtn"
SETLOCAL ENABLEDELAYEDEXPANSION
 SET MY_STRING=%~1
 SET DELIMITER_CHAR=%~2
 ::ECHO.MY_STRING : %MY_STRING%
 ::ECHO.DELIMITER_CHAR : %DELIMITER_CHAR%
FOR /f "tokens=1* delims=%DELIMITER_CHAR%" %%x IN ("%MY_STRING%") DO SET FileName=%%x&SET FileExtn=%%y
::ECHO.FileName : %FileName%
::ECHO.FileExtn : %FileExtn%
ENDLOCAL & SET %~3=%FileName% & SET %~4=%FileExtn%
::exit /b
GOTO:EOF

:SPLIT_WRAP
SETLOCAL
SET tSTRING=%~1
SET DEL_CHAR=%~2
ECHO.tSTRING : %tSTRING%
ECHO.DEL_CHAR : %DEL_CHAR%
CALL :STRING_SPLIT %tSTRING% %DEL_CHAR% "FileName" "FileExtn"
ECHO.FileName : %FileName%
ECHO.FileExtn : %FileExtn%
ENDLOCAL & (SET %~3=%FileName%) & ( SET %~4=%FileExtn% )
GOTO:EOF
Also posted on DosTips.
http://www.dostips.com/forum/viewtopic.php?f=3&t=6219 Quote from: mskavim on January 25, 2015, 02:30:08 PM

I am problem splinting the string in a loop.

My Requirement:-
-----------------------
I have a folder structure like

Code: [Select]+PHASE1         ( Directory)
++PREFERENCES    ( Sub - Directory)
+++SITE       ( Sub Sub - Directory)
+++GROUP      ( Sub Sub - Directory)
++++FIlE1.xml
++++FIlE2.xml
++++RUN.bat

What are you trying to do to the listing?  It can be more FUN to derive a solution than to READ long code which is broken.
992.

Solve : batch file as a setup file?

Answer»

Hello,
I am working to open a blender(.txt) file as a .blend file. So, i wanna create a copy of my .txt file as a .blend file in my BATCH file . I am not getting the EXACT command to execute that. I am attaching a code below but thats not working, i am missing few commands.
Can, anyone help me out?


Echo OFF
ECHO _______________________________________ _______________________
ECHO !!! Start Bleneder!!!
ECHO _______________________________________ _______________________
ECHO xcopy D:\jjs_\*.xxx       Y:\610\616\IFF_Daten\JJS_\*.xxx  /S/d /y /e /h /r
Echo _______________________________________ _______________________
Echo Start... [Strg-C]Abbrechen
D:\jjs\programme\blender2.68a\blender2.68a.exe  D:\Hannemann.blend
:Exit

Regards.None of your commands are GOING to execute when you have an ECHO in front of them.And blender is mis-spelled... Code: [Select]TYPE myfile.txt >myfile.blend
REM Open your .blend file here

993.

Solve : Subtract images in batch process(leap year and regular year)?

Answer»

I have numerous images from a directory that needs to be subtracted to another image and I don't know how to do it automatically in batch process.

Here's what I need to do:

  • Create the output directory
  • Check automatically if there are new files added in the INPUT directory, if there are new files subtract immediately
  • Subtract one image from the directory to another image from another directory

LEAP YEARS:                                                            REGULAR YEARS:
*2000, 2004, 2008, 2012, 2016, 2020...*          *2001-2003, 2005-2007, 2009-2011, 2013-2015...*

January - 1-31                                                          January - 1-31                                                                                     
February - 32-60                                                      February - 32-59
March - 61-91                                                          March - 60-90
April - 92-121                                                          April - 91-120
May - 122-152                                                         May - 121-151
June - 153-182                                                        June - 152-181
July - 183-213                                                         July - 182-212
August - 214-244                                                    August - 213-243
September - 245-274                                              September - 244-273
October - 275-305                                                  October - 274-304
November - 306-335                                               November - 305-334
December - 336-366                                               December - 335-365

Here are the sample file name for the images(these will be the minuend):
:there will only be 12 subtrahend(sample_file_jan.tif, sample_file_feb.tif, sample_file_march.tif . . .)

C2000060.A1_ABC.ABCD.tif - sample_file_feb.tif ------------------> the file was subtracted to feb because 060 is a day included in February (leap year)
C2002152.A1_ABC.ABCD.tif - sample_file_june.tif------------------> the file was subtracted to june because 152 is a day included in June (regular year)
C2000032.A1_ABC.ABCD.tif - sample_file_feb.tif------------------> the file was subtracted to feb because 032 is a day included in February (leap year)
C2001060.A1_ABC.ABCD.tif - sample_file_march.tif------------------> the file was subtracted to march because 060 is a day included in March (regular year)

where:

C = data name
2000 - year (leap year or regular year)
001 - julian date (leap year or regular year)
A1_ABC.ABCD.tif - extension name

If the year specified in the file name is 2000, 2004, 2008... then the date would be based on leap year. If the year specified in the file name is 2001-2003, 2005-2007, 2009-2011... then the date would be based on regular year.

If the date from the file name is based on the date from the leap years, then subtract the image to its corresponding subtrahend/month to where it should be subtracted. Repeat this step if the date are from the regular years.


Here is the script in subtracting images:


gdal_calculate --outfile=D:\path\to\file\difference.tif --calc="((image1-image2)/(image1

+image2))" --image2=D:\path\to\subtrahend\sample_file_feb.tif image1=D:\path\to\minuend\C2001060.A1_ABC.ABCD.tif --extent=INTERSECT


You are really referring to an Ordinal Date not a Julian Date.
This will help you change your ordinal date to a Calendar date.  Once you have the calendar date information you should then be able to figure out how to run your program.
http://www.commandline.co.uk/cmdfuncs/dandt/#ordinaltodate
Code: [Select]echo off&setlocal
call :OrdinalToDate %1 %2 yy mm dd
echo/%yy%-%mm%-%dd%
goto :EOF

:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
:OrdinalToDate %year% %doy% yy mm dd
::
:: By:   Ritchie Lawrence, 2002-09-29. Version 1.0
::
:: Func: Returns a calendar date from an ISO 8601 Ordinal date.
::       For NT4/2K/XP.
::
:: Args: %1 year component to be converted, 4 digits (by val)
::       %2 day of year component to be converted, 001 to 366 (by val)
::       %3 var to receive year, 4 digits (by ref)
::       %4 var to receive month, 2 digits, 01 to 31 (by ref)
::       %5 var to receive day of month, 01 to 31 (by ref)
:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
setlocal ENABLEEXTENSIONS
for /f "tokens=1-2" %%a in ('echo/%1 %2') do set /a yy=%%a,o=1%%b%%1000
set /a z=14-1,z/=12,y=yy+4800-z,m=1+12*z-3,j=153*m+2
set /a j=j/5+1+y*365+y/4-y/100+y/400-2432046,j+=o-1
set /a a=j+2432045,b=4*a+3,b/=146097,c=-b*146097,c/=4,c+=a
set /a d=4*c+3,d/=1461,e=-1461*d,e/=4,e+=c,m=5*e+2,m/=153,dd=153*m+2,dd/=5
set /a dd=-dd+e+1,mm=-m/10,mm*=12,mm+=m+3,yy=b*100+d-4800+m/10
(if %mm% LSS 10 set mm=0%mm%)&(if %dd% LSS 10 set dd=0%dd%)
endlocal&set %3=%yy%&set %4=%mm%&set %5=%dd%&goto :EOF
:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::Going to assume you will want to convert the month number to the month name, so that you can use the month name with the GDAL_CALCULATE command.
I have added that code.
Code: [Select]echo off&setlocal enabledelayedexpansion
call :OrdinalToDate %1 %2 yy mm dd
echo/%yy%-%mm%-%dd%

:: Now convert the month number to month name abbreviation
set m=100
for %%m in (Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov  Dec) do (
set /A m+=1
set month[!m:~-2!]=%%m
)
set MONTHNAME=!month[%mm%]!
echo %monthName%

goto :EOF

:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
:OrdinalToDate %year% %doy% yy mm dd
::
:: By:   Ritchie Lawrence, 2002-09-29. Version 1.0
::
:: Func: Returns a calendar date from an ISO 8601 Ordinal date.
::       For NT4/2K/XP.
::
:: Args: %1 year component to be converted, 4 digits (by val)
::       %2 day of year component to be converted, 001 to 366 (by val)
::       %3 var to receive year, 4 digits (by ref)
::       %4 var to receive month, 2 digits, 01 to 31 (by ref)
::       %5 var to receive day of month, 01 to 31 (by ref)
:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
setlocal ENABLEEXTENSIONS
for /f "tokens=1-2" %%a in ('echo/%1 %2') do set /a yy=%%a,o=1%%b%%1000
set /a z=14-1,z/=12,y=yy+4800-z,m=1+12*z-3,j=153*m+2
set /a j=j/5+1+y*365+y/4-y/100+y/400-2432046,j+=o-1
set /a a=j+2432045,b=4*a+3,b/=146097,c=-b*146097,c/=4,c+=a
set /a d=4*c+3,d/=1461,e=-1461*d,e/=4,e+=c,m=5*e+2,m/=153,dd=153*m+2,dd/=5
set /a dd=-dd+e+1,mm=-m/10,mm*=12,mm+=m+3,yy=b*100+d-4800+m/10
(if %mm% LSS 10 set mm=0%mm%)&(if %dd% LSS 10 set dd=0%dd%)
endlocal&set %3=%yy%&set %4=%mm%&set %5=%dd%&goto :EOF
::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: Quote from: Squashman on November 05, 2014, 09:21:49 AM
Going to assume you will want to convert the month number to the month name, so that you can use the month name with the GDAL_CALCULATE command.
I have added that code.
Code: [Select]echo off&setlocal enabledelayedexpansion
call :OrdinalToDate %1 %2 yy mm dd
echo/%yy%-%mm%-%dd%

:: Now convert the month number to month name abbreviation
set m=100
for %%m in (Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov  Dec) do (
set /A m+=1
set month[!m:~-2!]=%%m
)
set monthName=!month[%mm%]!
echo %monthName%

goto :EOF

:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
:OrdinalToDate %year% %doy% yy mm dd
::
:: By:   Ritchie Lawrence, 2002-09-29. Version 1.0
::
:: Func: Returns a calendar date from an ISO 8601 Ordinal date.
::       For NT4/2K/XP.
::
:: Args: %1 year component to be converted, 4 digits (by val)
::       %2 day of year component to be converted, 001 to 366 (by val)
::       %3 var to receive year, 4 digits (by ref)
::       %4 var to receive month, 2 digits, 01 to 31 (by ref)
::       %5 var to receive day of month, 01 to 31 (by ref)
:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
setlocal ENABLEEXTENSIONS
for /f "tokens=1-2" %%a in ('echo/%1 %2') do set /a yy=%%a,o=1%%b%%1000
set /a z=14-1,z/=12,y=yy+4800-z,m=1+12*z-3,j=153*m+2
set /a j=j/5+1+y*365+y/4-y/100+y/400-2432046,j+=o-1
set /a a=j+2432045,b=4*a+3,b/=146097,c=-b*146097,c/=4,c+=a
set /a d=4*c+3,d/=1461,e=-1461*d,e/=4,e+=c,m=5*e+2,m/=153,dd=153*m+2,dd/=5
set /a dd=-dd+e+1,mm=-m/10,mm*=12,mm+=m+3,yy=b*100+d-4800+m/10
(if %mm% LSS 10 set mm=0%mm%)&(if %dd% LSS 10 set dd=0%dd%)
endlocal&set %3=%yy%&set %4=%mm%&set %5=%dd%&goto :EOF
:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::


How will I add the gdal_calculate command to the batch script you gave? Quote from: _unknown_ on November 06, 2014, 07:56:16 PM

How will I add the gdal_calculate command to the batch script you gave?
Well I assumed you wanted to use the Month Name Abbreviation as part of your sample_file_feb.tif file.  So use the month abbreviation variable that I created for you.In which part of your script should I add the gdal_calculate command? Quote from: _unknown_ on November 09, 2014, 11:01:18 PM
In which part of your script should I add the gdal_calculate command?
Well you are not even to that point yet.  You still need the code to extract the Ordinal Date from the file name. 

Look at the code that Aacini gave you on DosTips.com.
That will show you the FOR command that will process all your files and it will show you how to get the ordinal date from the file name and then it basically shows you where you would put your GDAL command. Quote from: Squashman on November 10, 2014, 06:55:34 AM
Well you are not even to that point yet.  You still need the code to extract the Ordinal Date from the file name. 

Look at the code that Aacini gave you on DosTips.com.
That will show you the FOR command that will process all your files and it will show you how to get the ordinal date from the file name and then it basically shows you where you would put your GDAL command.


Sorry for this. But is it like this?


Code: [Select]echo off&setlocal EnableDelayedExpansion
call :OrdinalToDate %1 %2 yy mm dd
echo/%yy%-%mm%-%dd%

:: Now convert the month number to month name abbreviation
set m=100
for %%m in (Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov  Dec) do (
set /A m+=1
set month[!m:~-2!]=%%m
)
set monthName=!month[%mm%]!
echo %monthName%

set "in_path=E:\Processed_Files\Merged\"
set "out_path=E:\Diff"
set "in_subtrahend=E:\sample_file_months\"
set "yearDay="
set "fileList="

md %out_path%

rem Process all *.tif files in input path
cd "%in_path%"
for %%a in (*.tif) do (
   set "fileName=%%a"
   rem If the YearDay in this file is the same of previous one
   if "!fileName:~1,7!" equ "!yearDay!" (
      rem Join this filename to previous list
      set "fileList=!fileList! !fileName!"
   ) else (
      rem Subtract the files in the list
      if defined fileList gdal_calculate --outfile=%out_path%\C!yearDay!.A1_ABC.ABCD.tif --calc="((image1-image2)/(image1+image2))" --

image2=%in_subtrahend% image1=%in_path% --extent=INTERSECT
   )
)
rem Subtract the files in the list
gdal_calculate --outfile=%out_path%\C!yearDay!.A1_ABC.ABCD.tif --calc="((image1-image2)/(image1+image2))" --image2=

%in_subtrahend% image1=%in_path% --extent=INTERSECT

goto :EOF

:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
:OrdinalToDate %year% %doy% yy mm dd
::
:: By:   Ritchie Lawrence, 2002-09-29. Version 1.0
::
:: Func: Returns a calendar date from an ISO 8601 Ordinal date.
::       For NT4/2K/XP.
::
:: Args: %1 year component to be converted, 4 digits (by val)
::       %2 day of year component to be converted, 001 to 366 (by val)
::       %3 var to receive year, 4 digits (by ref)
::       %4 var to receive month, 2 digits, 01 to 31 (by ref)
::       %5 var to receive day of month, 01 to 31 (by ref)
:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
setlocal ENABLEEXTENSIONS
for /f "tokens=1-2" %%a in ('echo/%1 %2') do set /a yy=%%a,o=1%%b%%1000
set /a z=14-1,z/=12,y=yy+4800-z,m=1+12*z-3,j=153*m+2
set /a j=j/5+1+y*365+y/4-y/100+y/400-2432046,j+=o-1
set /a a=j+2432045,b=4*a+3,b/=146097,c=-b*146097,c/=4,c+=a
set /a d=4*c+3,d/=1461,e=-1461*d,e/=4,e+=c,m=5*e+2,m/=153,dd=153*m+2,dd/=5
set /a dd=-dd+e+1,mm=-m/10,mm*=12,mm+=m+3,yy=b*100+d-4800+m/10
(if %mm% LSS 10 set mm=0%mm%)&(if %dd% LSS 10 set dd=0%dd%)
endlocal&set %3=%yy%&set %4=%mm%&set %5=%dd%&goto :EOF
::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: Quote from: Squashman on November 10, 2014, 06:55:34 AM
That will show you the FOR command that will process all your files and it will show you how to get the ordinal date from the file name and then it basically shows you where you would put your GDAL command.

Am I doing the right thing? Please help! I'm just beginning to learn batch files and I don't know how to do it.

 


Quote from: Squashman on November 10, 2014, 06:55:34 AM
Well you are not even to that point yet.  You still need the code to extract the Ordinal Date from the file name. 

Look at the code that Aacini gave you on DosTips.com.
That will show you the FOR command that will process all your files and it will show you how to get the ordinal date from the file name and then it basically shows you where you would put your GDAL command.

I have tried my very best with this. Please bear with me.

Code: [Select]echo on
setlocal EnableDelayedExpansion

set "in_path=E:\Proc\Mer\"
set "out_path=E:\Proc\Abcde"
set "two_path=E:\Proc\Me\"
set "proc_path=E:\Proc\Proc_Mer_Fi"

::Don't modify the following variables
set "yearDay="
set "fileList="

md %out_path%
md %proc_path%

::Process all *.tif files in input path
cd /d "%in_path%"
for %%a in (*.tif) do (
   set "fileName=%%a"
   if %1 == 001-031 goto :condition1 ::reg/leap
   if %2 == 032-059 goto :condition2 ::reg
   if %3 == 032-060 goto :condition2 ::leap
   if %4 == 060-090 goto :condition3 ::reg
   if %5 == 061-091 goto :condition3 ::leap
   if %6 == 091-120 goto :condition4 ::reg
   if %7 == 092-121 goto :condition4 ::leap
   if %8 == 121-151 goto :condition5 ::reg
   if %9 == 122-152 goto :condition5 ::leap
   if %10 == 152-181 goto :condition6 ::reg
   if %11 == 153-182 goto :condition6 ::leap
   if %12 == 182-212 goto :condition7 ::reg
   if %13 == 183-213 goto :condition7 ::leap
   if %14 == 213-243 goto :condition8 ::reg
   if %15 == 214-244 goto :condition8 ::leap
   if %16 == 244-273 goto :condition9 ::reg
   if %17 == 245-274 goto :condition9 ::leap
   if %18 == 274-304 goto :condition10 ::reg
   if %19 == 275-305 goto :condition10 ::leap
   if %20 == 305-334 goto :condition11 ::reg
   if %21 == 306-335 goto :condition11 ::leap
   if %22 == 335-365 goto :condition12 ::reg
   if %23 == 336-366 goto :condition12 ::leap

   :condition1
   gdal_calculate --outfile=%out_path%\Abcde!yearDay!.Q_WER.Tera.tif !fileList! --calc="((one-two)/(one+two))" --two=%two_path%\two_abc_jan.tif --one=%in_path%\A!yearDay!.Q_WER.Tera.tif !fileList! --extent=INTERSECT
   goto end
   :condition2
   gdal_calculate --outfile=%out_path%\Abcde!yearDay!.Q_WER.Tera.tif !fileList! --calc="((one-two)/(one+two))" --two=%two_path%\two_abc_feb.tif --one=%in_path%\A!yearDay!.Q_WER.Tera.tif !fileList! --extent=INTERSECT
   goto end
   :condition3
   gdal_calculate --outfile=%out_path%\Abcde!yearDay!.Q_WER.Tera.tif !fileList! --calc="((one-two)/(one+two))" --two=%two_path%\two_abc_mar.tif --one=%in_path%\A!yearDay!.Q_WER.Tera.tif !fileList! --extent=INTERSECT
   goto end
   :condition4
   gdal_calculate --outfile=%out_path%\Abcde!yearDay!.Q_WER.Tera.tif !fileList! --calc="((one-two)/(one+two))" --two=%two_path%\two_abc_apr.tif --one=%in_path%\A!yearDay!.Q_WER.Tera.tif !fileList! --extent=INTERSECT
   goto end
   :condition5
   gdal_calculate --outfile=%out_path%\Abcde!yearDay!.Q_WER.Tera.tif !fileList! --calc="((one-two)/(one+two))" --two=%two_path%\two_abc_may.tif --one=%in_path%\A!yearDay!.Q_WER.Tera.tif !fileList! --extent=INTERSECT
   goto end
   :condition6
   gdal_calculate --outfile=%out_path%\Abcde!yearDay!.Q_WER.Tera.tif !fileList! --calc="((one-two)/(one+two))" --two=%two_path%\two_abc_june.tif --one=%in_path%\A!yearDay!.Q_WER.Tera.tif !fileList! --extent=INTERSECT
   goto end
   :condition7
   gdal_calculate --outfile=%out_path%\Abcde!yearDay!.Q_WER.Tera.tif --one=%in_path%\A!yearDay!.Q_WER.Tera.tif !fileList! --extent=INTERSECT
   goto end
   :condition8
   gdal_calculate --outfile=%out_path%\Abcde!yearDay!.Q_WER.Tera.tif !fileList! --calc="((one-two)/(one+two))" --two=%two_path%\two_abc_aug.tif --one=%in_path%\A!yearDay!.Q_WER.Tera.tif !fileList! --extent=INTERSECT
   goto end
   :condition9
   gdal_calculate --outfile=%out_path%\Abcde!yearDay!.Q_WER.Tera.tif !fileList! --calc="((one-two)/(one+two))" --two=%two_path%\two_abc_sep.tif --one=%in_path%\A!yearDay!.Q_WER.Tera.tif !fileList! --extent=INTERSECT
   goto end
   :condition10
   gdal_calculate --outfile=%out_path%\Abcde!yearDay!.Q_WER.Tera.tif !fileList! --calc="((one-two)/(one+two))" --two=%two_path%\two_abc_oct.tif --one=%in_path%\A!yearDay!.Q_WER.Tera.tif !fileList! --extent=INTERSECT
   goto end
   :condition11
   gdal_calculate --outfile=%out_path%\Abcde!yearDay!.Q_WER.Tera.tif !fileList! --calc="((one-two)/(one+two))" --two=%two_path%\two_abc_nov.tif --one=%in_path%\A!yearDay!.Q_WER.Tera.tif !fileList! --extent=INTERSECT
   goto end
   :condition12
   gdal_calculate --outfile=%out_path%\Abcde!yearDay!.Q_WER.Tera.tif !fileList! --calc="((one-two)/(one+two))" --two=%two_path%\two_abc_dec.tif --one=%in_path%\A!yearDay!.Q_WER.Tera.tif !fileList! --extent=INTERSECT
   goto end
   :: Move processed files to a different directory
   for %%a in (!fileList!) do move %%a "%proc_path%" >nul
   ) Quote from: _unknown_ on November 05, 2014, 02:34:30 AM
I have numerous images from a directory that needs to be subtracted to another image and I don't know how to do it automatically in batch process.

Here's what I need to do:
  • Create the output directory
  • Check automatically if there are new files added in the input directory, if there are new files subtract immediately

Files have a MODIFIED date which can be used to see if they are new.
Do your files get modified so that the most RECENT file was the last one that was created, or modified?

Quote from: foxidrive on December 01, 2014, 02:39:47 AM
Files have a modified date which can be used to see if they are new.
Do your files get modified so that the most recent file was the last one that was created, or modified?

Everyday there will be new files added to the input directory that's why I included that in my goals but now instead of that those processed files will just be moved to another directory. So that the input directory will not be confused of the newer files. I hope I'm explaining it well? Quote from: _unknown_ on December 01, 2014, 07:07:20 PM
Everyday there will be new files added to the input directory that's why I included that in my goals but now instead of that those processed files will just be moved to another directory. So that the input directory will not be confused of the newer files. I hope I'm explaining it well?

Well nothing you said replied to the question I posed.
The task may be much simpler than the way your code looks to be - using the file dates rather than the numbers in the filename.

I don't follow the task too well though, as subtracted and subtrahend are your TERMS for something
but they make no sense in terms of describing what the task is.

To me it would make more sense to say "processing" or "process the file with programB and copy it to folder c:\widget\"

Quote from: foxidrive on December 01, 2014, 09:01:53 PM
Well nothing you said replied to the question I posed.
The task may be much simpler than the way your code looks to be - using the file dates rather than the numbers in the filename.

I don't follow the task too well though, as subtracted and subtrahend are your terms for something
but they make no sense in terms of describing what the task is.

To me it would make more sense to say "processing" or "process the file with programB and copy it to folder c:\widget\"

Well sorry for me. I'm really not good in explaining. So you mean, I should replace the subtract with process?or processing? I'm using subtract and subtrahend because I thought that was the right term and because the batch will literally subtract one image to another.
994.

Solve : Batch file is getting false positives?

Answer»

I'm fairly new to writing scripts and having trouble (yes, yet another newbie with a question..  ) But I have been working pretty hard on this and I'm not able to get this to work.

I've also just recently learned how to make an access database. Not very relevant, except for that is what the script will be working with. Basically, my company's network is terrible and I'm trying to write a script to work around this.

The script started as a simple "Is access running? If no, start the database." This was put in the task scheduler to run every 3 minutes. That worked, until the computer lost connection to the server for a while. Then since access was still open, it wouldn't restart the database. So I'm attempting to write a script that can read if a specific title of a dialog box if it appears, force close access and open it again. This will also open a network drive in an explorer window and close it to refresh the connection since Microsoft has yet to figure out how to make network drives reconnect AFTER the PC/Laptop connects to the WiFi. 

Here is my script. I've added a lot of extra echos so I can see what steps the program is going through when running.

Code: [Select]echo off
echo 10
TASKLIST /FI "imagename eq explorer.exe" /v | Find "Restoring Network Connections" 2>nul
timeout 10
echo 20
if "%errorlevel%"=="0" GOTO check2
timeout 10
echo 30
if "%errorlevel%"=="1" GOTO prog1
timeout 10

echo 40
:check2
echo 50
TASKLIST /FI "imagename eq MSACCESS.EXE" /v | Find "Microsoft Office Access" 2>nul
echo 60
if "%errorlevel%"=="0" GOTO check3
echo 70
if "%errorlevel%"=="1" GOTO prog2

echo 80
:check3
echo 90
TASKLIST /FI "imagename eq MSACCESS.EXE" /v | FIND /I "ACTION FAILED" 2>nul
echo 100
if "%errorlevel%"=="0" GOTO progcheck
echo 110
if "%errorlevel%"=="1" GOTO prog3

echo 120
:progcheck
echo 130
tasklist | findstr /i MSACCESS.EXE
echo 140
if %errorlevel% neq 0 goto restart else
echo 150
timeout 20
echo 160
goto end

echo 170
:restart
echo 180
REM start "" "C:\Program Files\Microsoft Office\Office12\MSACCESS.EXE" "J:\Manufacturing\TECH\Tool crib\TCI Database rev1.accdb"
echo 190
goto end

echo 200
:prog1
echo 210
timeout 10
echo 220
TASKKILL /F /FI "WINDOWTITLE eq Restoring Network Connections" /IM explorer.exe
echo 230
echo Restoring Network Connections Dialog box closed
echo 240
start "" "C:\refreshnetdrive.bat"
timeout 20
echo 250
goto check2

echo 260
:prog2
echo 270
timeout 10
TASKKILL /F /IM MSACCESS.EXE
echo 280
timeout 10
goto check3

echo 290
:prog3
echo 300
timeout 10
TASKKILL /F /IM "MSACCESS.EXE"
echo 310
timeout 10
goto progcheck

:end
echo 320 end of script
timeout 600

I'll clean it up a bit to make it easier to read:

Code: [Select]echo off
TASKLIST /FI "imagename eq explorer.exe" /v | Find "Restoring Network Connections" 2>nul
if "%errorlevel%"=="0" GOTO check2
if "%errorlevel%"=="1" GOTO prog1

:check2
TASKLIST /FI "imagename eq MSACCESS.EXE" /v | Find "Microsoft Office Access" 2>nul
if "%errorlevel%"=="0" GOTO check3
if "%errorlevel%"=="1" GOTO prog2

:check3
TASKLIST /FI "imagename eq MSACCESS.EXE" /v | FIND /I "ACTION FAILED" 2>nul
if "%errorlevel%"=="0" GOTO progcheck
if "%errorlevel%"=="1" GOTO prog3

:progcheck
tasklist | findstr /i MSACCESS.EXE
if %errorlevel% neq 0 goto restart else
goto end

:restart
REM start "" "C:\Program Files\Microsoft Office\Office12\MSACCESS.EXE" "J:\Manufacturing\TECH\Tool crib\TCI Database rev1.accdb"
goto end

:prog1
TASKKILL /F /FI "WINDOWTITLE eq Restoring Network Connections" /IM explorer.exe
start "" "C:\refreshnetdrive.bat"
goto check2

:prog2
TASKKILL /F /IM MSACCESS.EXE
goto check3

:prog3
TASKKILL /F /IM "MSACCESS.EXE"
goto progcheck

:end

It looks like I have the first check working (Line 10-30.) I haven't fully tested to be sure. But I know the 2nd and 3rd are not (Line 40-110.) Even when access isn't running, the script finds a positive on the errorlevel and attempts to close and reopen access. I'm really hoping I didn't just MISS a quotes somewhere, because I have poured over this for hours wondering where I went wrong. Attached is the output I'm getting from the script with the line echos still entered. Thanks for any help you can give me!



[attachment deleted by admin to conserve space]Your code has 'fall into' errors. Unless you want to fall into something. You need to deal with the case where the error level is not a 0 or 1.
Also, your use of ERRORLEVEL is odd. Below is a typical use of it in a batch FILE.
Code: [Select]IF ERRORLEVEL ==3 GOTO THREE
IF ERRORLEVEL ==2 GOTO TWO
IF ERRORLEVEL ==1 GOTO ONE[
DOS batch files rules are very odd. Look at this:
http://support.microsoft.com/kb/69576

If batch is hard for you, consider using a more friendly script language.
Myself, I would VBA inside of Access, but I am not sure if your application could do what your want using only VBA.  (Visual Basic for Applications.)
https://www.youtube.com/watch?v=G9pqmd2PSYk

Many IT professionals use Powershell with batch for common problems.
This guide is for using Powershell to test network issues.
http://www.microsoft.com/en-us/download/details.aspx?id=41948

Sorry I can't help more.  QUOTE from: Geek-9pm on February 10, 2015, 10:06:13 PM

Also, your use of ERRORLEVEL is odd.

The OP is using the NT family alternative SYNTAX for errorlevel, which is an improvement on the old MS-DOS syntax

Old MS_DOS syntax:

If errorlevel N command

(There are no == signs like in your example.)

That means if the errorlevel is N or more, execute the command (often a GOTO a label)

HOWEVER in NT family command language (I believe since Windows 2000 at least) you have an additional alternative syntax where errorlevel is treated like any percent-sign variable like this:

You don't really need any quotes

if %errorlevel%==N command
if %errorlevel% equ N command (equivalent)

Conveniently, you can use the standard IF comparison operators available in NT family command language:

  EQU - equal
  NEQ - not equal
  LSS - less than
  LEQ - less than or equal
  GTR - greater than
  GEQ - greater than or equal

I suggest to the OP: put some lines like this...

echo errorlevel is %errorlevel%

...in your script to try to see what is happening.
995.

Solve : Echo command?

Answer» HI,

I have a question about Echo. I have read about what it is and what it is USED for ,but did not really help me to understand what the following line mean. Cananyona help please?

echo .> D:\Projects\logs\WinScpFtp_log.txt


What I cant find on the web is what  these characters mean .>

Does this mean that it puts in the file WinScpFtp_log.txt a dot?

Thanks

Yes but it also overwrites that file if it already exists.  If you need to append to the log file then you would use two >
You are physically echoing a period and redirecting the output to the log file.This:

(with a space between echo and the dot!)

echo . > path\filename

echoes a dot and a newline (cr + lf) to the file, creating the file if it does not exist, overwriting the file completely if it already exists.

Note however:

This:

(no space between the echo and the dot!)

echo. > path\filename

echoes a blank new line to the file.



Redirection operators:

> create new file if it does not exist, over-write file if it exists.

>> create new file if it does not exist, append to file (add to end of file if it exists.

Quote from: Suhi100 on February 11, 2015, 11:31:40 AM
What I cant find on the web is what  these characters mean .>

Examples of many guides:

(1) http://ss64.com/nt/syntax-redirection.html

(2) http://ss64.com/nt/echo.html

General help:

http://ss64.com/nt/

http://www.microsoft.com/resources/documentation/windows/xp/all/proddocs/en-us/ntcmds.mspx?mfr=true

Or type cmd syntax into Google

Also, because DOS batch was not intended as a learning language for those new to computer programming. If you look for information about computer languages, batch is seldom, if ever, LISTED as suitable for newcomers.
Instead you might see:
Quote
Assembly (a relatively simple dialect)
C is a Procedural language,
Java / C# / Eiffel / C++: Something Object-Oriented 
LISP and Prolog: Teaches students a new way to THINK,
SQL and XML: Introduces new ways to think about data and how to retrieve it and manage
To be sure,  there are excellent tutorials for  batch. As was mentioned by Salmon Trout above. But you have to read them.
Well said Salmon Trout.
I visit SS64 and Rob Vanderwoude's site as well.
http://www.robvanderwoude.com/redirection.php Quote from: Salmon Trout on February 11, 2015, 12:58:29 PM
This:

echo . > path\filename

echoes a dot and a newline (cr + lf) to the file

Just idly commenting here that your examples also add spaces. Quote from: foxidrive on February 12, 2015, 07:45:42 AM
Just idly commenting here that your examples also add spaces.

You know, I was on the bus coming back from work, and I thought "I put spaces before the redirections".

Correction:

This:

(with a space between echo and the dot!)

echo .> path\filename

echoes a dot and a newline (cr + lf) to the file, creating the file if it does not exist, overwriting the file completely if it already exists.

Note however:

This:

(no space between the echo and the dot!)

echo.> path\filename

echoes a blank new line to the file.



Redirection operators:

> create new file if it does not exist, over-write file if it exists.

>> create new file if it does not exist, append to file (add to end of file if it exists.



[/quote]
996.

Solve : Batch Project?

Answer»

I would like to start a project that involves the forum community. Before I do this I would like to know if people would like do it and prove that I am not a total idiot. Thanks for Your time anyway tho!Curious of what project ideas you have? Depends on what the project is. I for one don't have a lot I can contribute to a large scale project as it will most likely not be written in batch, and my grasp on python and java is not sufficient to contribute anything meaningful.Not sure why you or anyone else would think you are an idiot. If you want to start a batch program just post your ideas and some code and I am sure a lot of people will contribute their two cents if it peaks their interest.Why the Poll ? ?

Just curious... Quote from: patio on January 04, 2015, 07:51:17 PM

Why the Poll ? ?

Just curious...

  Quote from: Squashman on January 04, 2015, 04:17:38 PM
If you want to start a batch program just post your ideas and some code and I am sure a lot of people will contribute their two cents if it peaks their interest.

Me agree.  I don't why the poll, just guessed it would help some how. Anyway I didn't come into this with any ideas. But now since you mentioned it I thought of a few like, advance Calculator, a city builder, a space adventure, a batch file manager. An since this is the first really new thing I tried on this forum. Maybe these projects could be written in multiple languages, via C++, python and java. Plus if multiple people help, some people might not need to speed massive amounts of time. The code of these projects could range from 20 to 1000.

So that's all the questions I SAW, but the reason I didn't post some code, was I didn't have any. Other people can come up with more ideas then I can. And If anyone wanders why, I am very bored after school and practice, so i want to help people and program random things.

Thanks for all the feedback anyway!,
Shiverbob Quote from: shiverbob on January 06, 2015, 08:01:36 PM
Maybe these projects could be written in multiple languages, via C++, python and java.
Then post in the Computer Programming forum category.

Quote from: shiverbob on January 06, 2015, 08:01:36 PM
I am very bored after school and practice
Then help out on multiple forums.  There are tons of them out there.  I probably post on about 6 different forums. Quote from: shiverbob on January 06, 2015, 08:01:36 PM
a space adventure

Here's a start.  I don't think I commented everything, but you should be able to figure it out.  Every file other than launcher.bat should be in a folder named "bin".  The files with names like this "filename." have no extension and shouldn't be saved with one.  They are simply text files, but I was lazy and decided I didn't want to write .txt every time I used them.  Post if I missed a file.

Code: (launcher.bat) [Select]:: Launches the game.  Displays the controls found
:: in the controls file.

echo off

cd bin
for /f "delims=" %%A in (controls) do set %%A

echo.
echo.controls
echo.
echo.  %move_+_y_theta% = + y theta
echo.  %move_-_y_theta% = - y theta
echo.  %move_+_x_theta% = + x theta
echo.  %move_-_x_theta% = - x theta
echo.  %move_+_vel% = + vel
echo.  %move_-_vel% = - vel
echo.  %move_ping% = ping
echo.  %move_quit% = quit
echo.
pause

call master.bat

====================BIN====================

Code: (cont.bat) [Select]:: Waits for user input and writes it to the cmd file.
:: Closes upon finding the contr file, created by cmd.bat
:: when the exit command is found.

setlocal enableDelayedExpansion
for /f %%a in ('copy /Z "%~dpf0" nul') do set "CR=%%a"
set "key="
for /L %%. in () do (
set "key="
for /f "delims=" %%A in ('xcopy /w %~f0 %~f0 2^>nul') do if not defined key set "key=%%A"
set key=!key:~-1!
echo !key!>cmd
if exist contr exit
)
Code: (com.bat) [Select]:: Checks file cmd generated by cont.bat for which command to execute
:: and then executes that command.  Uses values in controls file for
:: key to commnand bindings.

setlocal EnableDelayedExpansion

set /p cmd=<cmd
set /p pos_x=<pos_x
set /p pos_y=<pos_y
set /p pos_z=<pos_z
set /p vel=<vel
set /p theta_y=<theta_y
set /p theta_x=<theta_x
for /f "delims=" %%A in (controls) do set %%A

if "%cmd%"=="." goto :end

if /i "%cmd%"=="%move_+_y_theta%" (
set /a theta_y+=%delta_theta%
echo !theta_y!>theta_y
)
if /i "%cmd%"=="%move_-_y_theta%" (
set /a theta_y-=%delta_theta%
echo !theta_y!>theta_y
)
if /i "%cmd%"=="%move_+_x_theta%" (
set /a theta_x+=%delta_theta%
echo !theta_x!>theta_x
)
if /i "%cmd%"=="%move_-_x_theta%" (
set /a theta_x-=%delta_theta%
echo !theta_x!>theta_x
)
if /i "%cmd%"=="%move_+_vel%" (
set /a vel+=1
echo !vel!>vel
)
if /i "%cmd%"=="%move_-_vel%" (
set /a vel-=1
echo !vel!>vel
)
if /i "%cmd%"=="%move_ping%" call ping.bat
if /i "%cmd%"=="%move_quit%" (
echo .>contr
timout /t 1 /nobreak >nul
exit
)

echo .>cmd

:end
Code: (disp.bat) [Select]
REM load data
set /p pos_x=<pos_x
set /p pos_y=<pos_y
set /p pos_z=<pos_z
set /p vel=<vel
set /p theta_y=<theta_y
set /p theta_x=<theta_x
set /p turn=<turn
for /f "delims=" %%A in (settings) do set %%A


if not exist last goto :disp
for /f "delims=" %%A in (last) do set l_%%A
if "%pos_x: =%"=="%l_pos_x: =%" (
if "%pos_y: =%"=="%l_pos_y: =%" (
if "%pos_z: =%"=="%l_pos_z: =%" (
if "%vel: =%"=="%l_vel: =%" (
if "%theta_x: =%"=="%l_theta_x: =%" (
if "%theta_y: =%"=="%l_theta_y: =%" (
if not "%display%"=="1" goto :end
))))))
:disp
cls
echo.
echo.  Possition: [%pos_x: =%],[%pos_y: =%],[%pos_z: =%]
echo.  Direction: y [%theta_y: =%], x [%theta_x: =%]
echo.  Velocity : [%vel: =%]
echo.
if "%display%"=="1" (
if exist v_grav type v_grav
echo.
)
:end
Code: (grav.bat) [Select]:: apply gravity by calling grav.vbs

set /p pos_x=<pos_x
set /p pos_y=<pos_y
set /p pos_z=<pos_z
for /f "delims=" %%A in (settings) do set %%A

cscript //nologo grav.vbs "%cd%\planets" %pos_x% %pos_y% %pos_z% "%cd%" "%wvec_lim%" 1>v_grav
Code: (controls.) [Select]move_+_y_theta=w
move_-_y_theta=s
move_+_x_theta=d
move_-_x_theta=a
move_+_vel=o
move_-_vel=l
move_ping=p
move_quit=t
diplay_ex=g
Code: (land.bat) [Select]:: Displays crash information and
:: calls reset for a new game.

set /p planet=<crashrep
for /f "tokens=1-4 delims=," %%A in (planets) do (
if "%%D"=="%planet%" (
echo %%A >pos_x
echo %%B >pos_y
echo %%C >pos_z
)
)

if /i "%planet%"=="earth" call win.bat
call disp.bat

echo You've landed on %planet%
echo.
echo Press G to explore. . .

:l
if exist cmd set /p cmd=<cmd
if /i not "%cmd%"=="g" goto :l
echo .>cmd

call planet.bat
Code: (master.bat) [Select]:: The master file that calls all other components.
:: LOOPS forever, always reading the cmd file for
:: commands to execute.

echo off
if exist last del last
if exist contr del contr
if exist turn set /p turn=<turn
if "%~1"=="l" goto :l

start /b cmd /c cont.bat 2>nul 1>&2
cmd /c ^""%~f0" l ^"
rem ^<nul
exit /b 0


:l

REM setup Var
set cmd=.
if exist cmd (
set /p cmd=<cmd
) else (
echo . >cmd
)

REM Start moving
call mov.bat

REM read commands
call com.bat

REM start view
call disp.bat

REM apply gravity
call grav.bat

REM check crash
call chkcrsh.bat

REM wait
timeout /t 1 /nobreak >nul

goto :l
Code: (mov.bat) [Select]:: CHANGES ship position through the use of pt.vbs

set /p pos_x=<pos_x
set /p pos_y=<pos_y
set /p pos_z=<pos_z
set /p vel=<vel
set /p theta_y=<theta_y
set /p theta_x=<theta_x

cscript //nologo pt.vbs "%vel%" "%theta_x%" "%theta_y%" "%cd%\Pos_x" "%cd%\Pos_y" "%cd%\Pos_z" "%pos_x%" "%pos_y%" "%pos_z%"
Code: (planet.bat) [Select]:: Displays information on current planet you are on.
:: Also allows for takeoff.

set /p pos_x=<pos_x
set /p pos_y=<pos_y
set /p pos_z=<pos_z
set /p vel=<vel
set /p theta_y=<theta_y
set /p theta_x=<theta_x
set /p planet=<crashrep

:: chart planet on map
echo %planet% >chart


call disp.bat
type "..\desc\%planet%"
echo.
echo.
echo Press G to leave planet. . .

:l
if exist cmd set /p cmd=<cmd
if /i not "%cmd%"=="g" goto :l
echo .>cmd

set /a pos_x+=5
set /a pos_y+=5
set /a pos_z+=5

rem echo 1 >vel
echo %pos_x% >pos_x
echo %pos_y% >pos_y
echo %pos_z% >pos_z

del crashrep
Code: (planets.) [Select]0,0,0,0,0,0,0,0, How to read: x,y,z,name,danger,grav,bound_sun_name
0,0,0,0,0,0,0,0,   danger 0 = can't land, 1 = can safely land, 2 = crash
0,0,0,0,0,0,0,0,   bound_sun_name=0 if self bound
0,0,0,0,0,0,0,0,   smaller the grav the harder the pull
0,0,0,0,0,0,0,0, 1 pt ~ 100,000 miles
0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0, Sol System
0,0,0,0,0,0,0,0,
390000,470000,-38000,Sol,2,1,0
390000,470360,-37900,Mercury,1,50,Sol
390600,470070,-38100,Venus,1,30,Sol
390629,469700,-38070,Earth,1,10,Sol
388584,470000,-38030,Mars,1,10,Sol
394000,470836,-37970,Jupiter,0,5,Sol
381118,469990,-38000,Saturn,0,7,Sol
372136,469900,-37920,Uranus,0,20,Sol
390000,442012,-38000,Neptune,0,20,Sol
426662,470000,-40000,Pluto,1,100,Sol
0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0, Elbei/Ambon System
0,0,0,0,0,0,0,0,
-950,-950,11,Elbei/Ambon,0,0,0
-1000,-1000,10,Elbei,2,2,Elbei/Ambon
-900,-900,12,Ambon,2,2,Elbei/Ambon
10,10,100,Abron,1,10,Elbei/Ambon
-150,-150,50,Upien,0,15,Elbei/Ambon
Code: (grav.vbs) [Select]' grav "%cd%\planets" %pos_x% %pos_y% %pos_z% "%cd%" %wvec_lim%
'
' Applies gravity for each planet withing range.  Uses wvec_lim variable
' from files settings to determine range.  if dis/grav < wvrc_lim then
' gravity is applied. Value of grav is taken from file settings as well.

dim x,y,z,working_x,working_y,working_z,dis,wvec,vec_x,vec_y,vec_z,x1,y1,z1,grav,wvec_lim,planets,name
dim file,fso,listFile,line,arrline
file=Wscript.Arguments(0)
x=Wscript.Arguments(1)
y=Wscript.Arguments(2)
z=Wscript.Arguments(3)
cd1=Wscript.Arguments(4)
wvec_lim=CSng(Wscript.Arguments(5))
vec_x=0
vec_y=0
vec_z=0


' Loop through planets list
Set fso = CreateObject("Scripting.FileSystemObject")
Set listFile = fso.OpenTextFile(file)
do while not listFile.AtEndOfStream
line =  listFile.ReadLine()


' setup variables
arrline=Split(line,",")
working_x=arrline(0)
working_y=arrline(1)
working_z=arrline(2)
name=arrline(3)
grav=arrline(5)

' Ignore all planets with 0 gravity
' These are comments in the file
If grav <> 0 Then

'find distance
dis=Sqr((x-working_x)*(x-working_x)+(y-working_y)*(y-working_y)+(z-working_z)*(z-working_z))
wvec=dis/grav

Wscript.echo name &" | "& round(wvec,2)


'determine adding
If wvec < wvec_lim Then

' Find Vector length
if dis=0 then dis=.0000001
x1=round(((working_x-x)/dis/grav),2)
y1=round(((working_y-y)/dis/grav),2)
z1=round(((working_z-z)/dis/grav),2)

' Display Data
Wscript.echo " "&x1&" "&y1&" "&z1

' Add vector length to sum
vec_x=vec_x+x1
vec_y=vec_y+y1
vec_z=vec_z+z1

End If
End If
Loop

' Make corrections on possition
x=x+vec_x
y=y+vec_y
z=z+vec_z

' Write to Files
set objFSO=CreateObject("Scripting.FileSystemObject")
outFile=cd & "pos_x"
Set objFile = objFSO.CreateTextFile(outFile,True)
objFile.Write x & vbCrLf
objFile.Close

outFile=cd & "pos_y"
Set objFile = objFSO.CreateTextFile(outFile,True)
objFile.Write y & vbCrLf
objFile.Close

outFile=cd & "pos_z"
Set objFile = objFSO.CreateTextFile(outFile,True)
objFile.Write z & vbCrLf
objFile.Close
Code: (pt.vbs) [Select]' cscript //nologo pt.vbs "%vel%" "%theta_x%" "%theta_y%" "%cd%\Pos_x" "%cd%\Pos_y" "%cd%\Pos_z" "%pos_x%" "%pos_y%" "%pos_z%"
'
' x = vel * cos(theta_x) * cos(theta_y)
' y = vel * cos(theta_x) * sin(theta_y)
' z = vel * sin(theta_x)
'
' Changes the position of the ship by using theta_x, theta_y, and vel to
' determine the end point of that movement.  Is applied before gravity.


dim x,y,z,vel,xTheta,yTheta,cd1,cd2,cd3,px,py,pz,log,pi
vel = Wscript.Arguments(0)
xTheta = Wscript.Arguments(1)
yTheta = Wscript.Arguments(2)
cd1 = Wscript.Arguments(3)
cd2 = Wscript.Arguments(4)
cd3 = Wscript.Arguments(5)
px = Wscript.Arguments(6)
py = Wscript.Arguments(7)
pz = Wscript.Arguments(8)
pi = 4 * ATN(1)

' convert degree's to radians
xTheta = xTheta * pi / 180
yTheta = yTheta * pi / 180


x = round((vel*cos(yTheta)*cos(xTheta)),2)+px
z = round((vel*cos(yTheta)*sin(xTheta)),2)+pz
y = round((vel*sin(yTheta)),2)+py


set objFSO=CreateObject("Scripting.FileSystemObject")
outFile=cd1
Set objFile = objFSO.CreateTextFile(outFile,True)
objFile.Write x & vbCrLf
objFile.Close

outFile=cd2
Set objFile = objFSO.CreateTextFile(outFile,True)
objFile.Write y & vbCrLf
objFile.Close

outFile=cd3
Set objFile = objFSO.CreateTextFile(outFile,True)
objFile.Write z & vbCrLf
objFile.Close
Code: (reset.bat) [Select]:: Resets the game.  Does not call any other functions.

if exist contr del contr
if exist last del last
if exist turn del turn
if exist cmd del cmd
if exist crashrep del crashrep

echo 0 >pos_x
echo 0 >pos_y
echo 0 >pos_z
echo 0 >vel
echo 0 >theta_x
echo 0 >theta_y
echo 0 >turn
:: echo delta_theta=10 >settings
:: echo delay=50 >>settings
:: echo grav=1 >>settings
echo vel=0 >last
echo .>cmd
Code: (settings.) [Select]delta_theta=10
delay=50
display=1
wvec_lim=2
crash=1
Code: (chkcrsh.vbs) [Select]' chkcrsh.vbs "%cd%" %pos_x% %pos_y% %pos_z% "%cd%\planets" "%cd%\crashrep"
'
' Checks for possition conflict between ship and the planets found in the planets file.

dim x,y,z,working_x,working_y,working_z,cd,errorlevel,file,arrline,cd1,lastX,lastY,lastZ,working_name,line,listFile

errorlevel=0
cd=Wscript.Arguments(0)
x=round(Wscript.Arguments(1),0)
y=round(Wscript.Arguments(2),0)
z=round(Wscript.Arguments(3),0)
file=Wscript.Arguments(4)
cd1=Wscript.Arguments(5)

Set fso = CreateObject("Scripting.FileSystemObject")
Set listFile = fso.OpenTextFile(file)
do until listFile.AtEndOfStream
line = listFile.ReadLine()

'setup variables
arrline=Split(line,",")
working_x=round(arrline(0),0)
working_y=round(arrline(1),0)
working_z=round(arrline(2),0)
working_name=arrline(3)
working_dang=arrline(4)

if x=working_x then
if y=working_y then
if z=working_z then
if working_dang <> 0 Then
set objFSO=CreateObject("Scripting.FileSystemObject")
outFile=cd1
Set objFile = objFSO.CreateTextFile(outFile,True)
objFile.Write working_name & vbCrLf
objFile.Close
end if
end if
end if
end if
loop
Code: (com.bat) [Select]:: Checks file cmd generated by cont.bat for which command to execute
:: and then executes that command.  Uses values in controls file for
:: key to commnand bindings.

setlocal EnableDelayedExpansion

set /p cmd=<cmd
set /p pos_x=<pos_x
set /p pos_y=<pos_y
set /p pos_z=<pos_z
set /p vel=<vel
set /p theta_y=<theta_y
set /p theta_x=<theta_x
for /f "delims=" %%A in (controls) do set %%A

if "%cmd%"=="." goto :end

if /i "%cmd%"=="%move_+_y_theta%" (
set /a theta_y+=%delta_theta%
echo !theta_y!>theta_y
)
if /i "%cmd%"=="%move_-_y_theta%" (
set /a theta_y-=%delta_theta%
echo !theta_y!>theta_y
)
if /i "%cmd%"=="%move_+_x_theta%" (
set /a theta_x+=%delta_theta%
echo !theta_x!>theta_x
)
if /i "%cmd%"=="%move_-_x_theta%" (
set /a theta_x-=%delta_theta%
echo !theta_x!>theta_x
)
if /i "%cmd%"=="%move_+_vel%" (
set /a vel+=1
echo !vel!>vel
)
if /i "%cmd%"=="%move_-_vel%" (
set /a vel-=1
echo !vel!>vel
)
if /i "%cmd%"=="%move_ping%" call ping.bat
if /i "%cmd%"=="%move_quit%" (
echo .>contr
timout /t 1 /nobreak >nul
exit
)

echo .>cmd

:end
Code: (chkcrsh.bat) [Select]:: Checks for a conflict in possition with ship and any planets
:: calls upon chkcrsh.vbs for math and comparison.

set crashrep=
set /p pos_x=<pos_x
set /p pos_y=<pos_y
set /p pos_z=<pos_z
set /p vel=<vel

cscript //nologo chkcrsh.vbs "%cd%" %pos_x% %pos_y% %pos_z% "%cd%\planets" "%cd%\crashrep"


REM for after planet based movement is possable
if exist crashrep if %vel% GTR 0 call crash.bat
if exist crashrep if %vel% EQU 0 call land.bat

*I used dbenham's snake game to write cont.bat, he gets all credit for the controls input technique. Quote from: Lemonilla on January 07, 2015, 06:50:19 PM
Here's a start.    Post if I missed a file.

Just a suggestion:

It would aid people to get this, with no typos and saving errors, if you could attach a zip file with the entire shebang.

Quote from: foxidrive on January 07, 2015, 09:23:27 PM
Just a suggestion:

It would aid people to get this, with no typos and saving errors, if you could attach a zip file with the entire shebang.
>.< Now I feel stupid.  Here's the file.

[attachment deleted by admin to conserve space]If you want to properly collaborate on a project together, use a hosted version control system such as Github.  It will make managing changes and who did what much easier than copying and pasting code in a forum post.  Each person can then fork the repo, make the changes they want and then submit a pull request.Well, never (successfully) used github before, but here it is.  I plan on continuing this alone anyway and should probably get into the habit of backing my stuff up more often.Looking good so far!  Just remember, commit little, commit often.

Github is also great since if you end up going for a job that will involve some SORT of programming, it can act as a CV of sorts.
997.

Solve : mode woes?

Answer»

Hello all.

I need a hand with mode command.

Using MS-DOS 5.0 on an HP 8000 Elite SFF.  Have a Raven 2406 parallel printer attached to COM1 via a 6 foot long Black Box PIO45A DB9 to Centronics serial to parallel converter. COM1 is set in the autoexec.bat file to "mode com1:48,n,8,1,p" and the converter (DIP switches) to flow control=hardware, no parity, 8 bits, stop bit=1, data rate=4800. The printer works just fine for days on end, even after daily shutdowns and restarts, but then nothing is printed. No error messages, it just doesn't print. Nothing is changed in the hardware or software. Tried reissuing the same mode command just before printing to no avail. Several restarts later it works again for days, then nothing. Changing COM1 and adapter settings is not an option, as 7bits (1 or 2 stop bits) results in lost print content.

My question: Is there a way to get MS-DOS 5.0 to report the current COM1 setting (without issuing a command to change it)?

Thanks for any help in solving this mystery.


Did you happen to try typing MODE /? at the DOS prompt and notice any options to display the status of the com port.
Maybe even try just typing MODE at the dos prompt by itself.Unfortunately, neither of those options reports the current COM1 setting Quote from: student0101 on January 20, 2015, 11:03:14 AM

Unfortunately, neither of those options reports the current COM1 setting

When you type MODE /? at the dos prompt, what do you see?My own memory is a bit rusty but to my recollection you cannot actually view the current settings, the "STATUS" shown for it will only include the RETRY=NONE for some stupid reason. Further googling as you've likely attempted as well doesn't reveal anything.

I was able to see the current COM port settings by running MSD (Microsoft DIAGNOSTICS) However this is new in MS-DOS 6 so isn't in MS-DOS 5. I don't know of a in-box way of viewing the settings without a tool like MSD. (MSD also came with Windows 3.x as I recall, possibly other MS Software as well).

Also, if you are printing, I would expect you are using redirection to redirect an LPT port to the serial port? If that is the case, than it is worth noting that if you change the settings on the serial port you need to re-issue the redirection command. (MODE LPT1=COM1), otherwise printing won't work. (I don't know if it resets the redirection itself or perhaps has it using the old values for the redirect).


I unfortunately can't REMEMBER that far back to know what the OPTIONS were for the MODE command back then. That is why I have been trying to get him to tell us what it is because he has access to it.mode /? shows the command syntax and lists available options.

I'm trying to talk to the com port directly, e.g. "dir > com1". When it works, it prints the directory OK.

Quote from: student0101 on January 20, 2015, 12:19:28 PM
mode /? shows the command syntax and lists available options.
Yes, but I am LITERALLY asking to the the output of MODE /?.
I don't have access to any version of DOS anymore so I need to see what the options are.This is what "mode /?" displays:

Configures system devices.

Printer port:      MODE LPTn[:] [COLS=c] [LINES=l] [RETRY=r]
Serial port:       MODE COMm[:] [BAUD=b] [PARITY=p] [DATA=d] [STOP=s] [RETRY=r]
Device Status:     MODE [device] [/STATUS]
Redirect printing: MODE LPTn[:]=COMm[:]
Prepare code page: MODE device CP PREPARE=((yyy[...]) [drive:][PATH]filename)
Select code page:  MODE device CP SELECT=yyy
Refresh code page: MODE device CP REFRESH
Code page status:  MODE device CP [/STATUS]
Display mode:      MODE [display-adapter][,n]
                   MODE CON[:] [COLS=c] [LINES=n]
Typematic rate:    MODE CON[:] [RATE=r DELAY=d] Quote from: Squashman on January 20, 2015, 09:42:32 AM
Did you happen to try typing MODE /? at the DOS prompt and notice any options to display the STATUS of the com port.
Quote from: student0101 on January 20, 2015, 12:34:14 PM
Device Status:     MODE [device] [/STATUS]

Did you try that?Yes I did. It only says:

Status for device COM1:
-------------------------------------
Retry=NONE Quote from: student0101 on January 20, 2015, 12:47:16 PM
Yes I did. It only says:

Status for device COM1:
-------------------------------------
Retry=NONE
Why did it take me 5 posts to get that information out of you? I feel like a Dentist today. Is there any way I could have worded my comments better?I don't know. I think I detailed my problem and how I tried to solve it sufficiently in my initial post. If the answer were in the DOS manual I wouldn't need to bother you. Quote from: BC_Programmer on January 20, 2015, 12:07:41 PM
My own memory is a bit rusty but to my recollection you cannot actually view the current settings, the "STATUS" shown for it will only include the RETRY=NONE for some stupid reason. Further googling as you've likely attempted as well doesn't reveal anything.

I was able to see the current COM port settings by running MSD (Microsoft Diagnostics) However this is new in MS-DOS 6 so isn't in MS-DOS 5. I don't know of a in-box way of viewing the settings without a tool like MSD. (MSD also came with Windows 3.x as I recall, possibly other MS Software as well).

Also, if you are printing, I would expect you are using redirection to redirect an LPT port to the serial port? If that is the case, than it is worth noting that if you change the settings on the serial port you need to re-issue the redirection command. (MODE LPT1=COM1), otherwise printing won't work. (I don't know if it resets the redirection itself or perhaps has it using the old values for the redirect).

Thanks, BC_Programmer. I was able to download MSD.EXE and run it on MS-DOS 5.0. Under COM Ports it reports COM1 is correctly set for Port Address, Baud rate, Parity, Data Bits and Stop Bits. Carrier Detect=Yes, Ring Indicator=No, Data Set Ready=Yes, Clear to Send=Yes, UART chip Used=16550AF. Printer working OK at the moment. I'll see what it says next time the printer isn't printing.



Quote from: student0101 on January 20, 2015, 01:03:56 PM
If the answer were in the DOS manual I wouldn't need to bother you.
You must not HANG out on a lot of Tech Help Forums.
If I had a dime for every time someone didn't bother to check the help file or manual for a program, I could quit my day job and do this as my full-time job if they decided to pay me.  Most of the time we act like Dentists trying to extract information from the person posting the question. We can't assume anything about the person posting the question.
998.

Solve : Industrial DOS Projection?

Answer»

hi

i have a backup from a DOS system and want to convert it to software workable in windows XP/7/8/Linux ...

Can help me to complete this ?


requirement files:
1. Back up file in GHO :
http://www.mediafire.com/download/9hlx4v08axqdjww/RTM.iso

2. Ghost bootable to restore :
http://www.mediafire.com/download/44xaxj27bivgxau/Ghost__11.5.1_SATA.iso

3. dos 3.22 :
http://www.mediafire.com/download/wh75b3y4ydr7bj0/DOS6.22_bootdisk.isoNot sure what you are asking. If you want to extract the files from the gho image, it is easy in Windows. I doubt if you can do this in Linux.

You should not post copyright stuff you have put on download sites (e.g. MS-DOS).

1. Mount the RTM.ISO with a free ISO reader, for example WinCDemu

http://wincdemu.sysprogs.org/download/

2. Download the freely available Symantec Ghost Explorer

ftp://ftp.norton.com/public/english_us_canada/products/symantec_ghost_solution_suite/2.5/updates/Ghostexp-B1597.zip

3. Open the gho file

4. Extract the contents

gho contains:

14/02/2015  14:10    <DIR>          .
14/02/2015  14:10    <DIR>          ..
14/02/2015  14:10    <DIR>          als
14/02/2015  14:10    <DIR>          vm386
14/02/2015  14:10    <DIR>          trio
14/02/2015  14:10    <DIR>          setup
14/02/2015  14:10    <DIR>          nwlite
14/02/2015  14:10    <DIR>          cpqdos
14/02/2015  14:10    <DIR>          database
14/02/2015  14:10    <DIR>          nwclient
14/02/2015  14:10    <DIR>          dos
14/02/2015  14:10    <DIR>          novell
14/02/2015  14:10    <DIR>          vmprintq
14/02/2015  14:10    <DIR>          intel
02/07/2002  14:22               616 install.bat
02/04/1999  06:27                14 host.bat
02/04/1999  06:27            23,583 ipx.com
02/04/1999  06:27            24,817 ipx2000.com
02/04/1999  06:27            23,583 ipx501.com
02/04/1999  06:27            29,428 ipx503.com
02/04/1999  06:27            27,890 ipx509.com
11/09/2000  15:10                 0 m
11/09/2000  15:10                84 m.tmp
02/04/1999  06:27            16,658 ma.com
18/07/2002  17:32               139 gsetup.bat
02/04/1999  06:27            10,804 mar.com
11/09/2000  15:02                44 nbihw.cfg
02/04/1999  06:27            52,443 netx.com
02/04/1999  06:27                34 getletr.com
29/04/2010  07:58             1,130 datatrck.inf
29/08/2009  08:37               658 config.sys
09/11/2006  15:23            84,078 options.fic
09/11/2006  15:23               432 options.tbl
02/04/1999  06:27            16,934 rtm_rtg.dun
01/05/2011  10:58            18,696 rtm_rtg.fic
20/07/2000  18:14            14,371 rtm_rtg.org
02/04/1999  06:27             9,430 rtm_rtg.ref
02/04/1999  06:27             5,000 rtm_rtg.sav
12/10/2001  16:00            14,706 rtm_rtg.ser
01/05/2011  10:58               192 rtm_rtg.tbl
12/10/2001  15:49            21,846 rtm_rtg.tcp
20/07/2000  18:10            18,922 rtm_rtg.ubd
02/04/1999  06:27            54,645 command.com
02/04/1999  06:27            42,073 smartdrv.exe
02/04/1999  06:27            32,684 btrieveb.exe
07/11/2003  10:24                65 version.txt
10/11/2006  13:18             2,286 autoexec.bat
02/04/1999  06:27             1,432 madrive.doc
02/04/1999  06:27             9,349 wina20.386
              35 File(s)        559,066 bytes
your answer is not wrong but not my Answer

this is an OS Base MS-DOS
use this tools to restore ISO file in VMware and see !

i want change these from MS-DOS OS Base to A Program Can be used in Win XP/7/8 or Linux and need to be CONECTED TO NETWARE SERVER ...

 

====================================================
Guide :

After restore RUN os
select 1 and Enter
select DAP 1 and Enter
to SEE ...

this is an industrial system
.......  NOT EASY .........
You (or your employer) need to spend some money here. On specialist IT ADVICE. You want to migrate a mission-critical (?) industrial system so you make the whole MS-DOS system disk image available on a free-help forum, and want some sparetime volunbteers to do it all for you? Good luck, but personally I think you are barking up the wrong tree. Does your employer know you are sharing their system with the whole world?

i just want found about files on this file

for example how can CONNECT this to a to specified server
i want to found about network files on this file and how config to other server ...
How this system detect server (where is file for this)

"this system is very old about 1983-1990"
and this is Personal work because we have very free time not for employer
Connect what? A virtual machine running the MS-DOS system?
run server (Novell netware 3.12) on VMware and use LAN segment on it
after start complete

start this system
this system just could be run after detect server

i want found where is the file used for detect server file and config it

================================================
I test windows XP and Newer version of SQL and Work good and connected to Novell netware 6.5
but this system need work on it.
There are miles of differences between Netware 3.x and Netware 6.x.
One uses bindery and the other does not. I am not sure what your intended goal is.a complete description is :
PSQL 8.7 Workgroup
This file
A Server For Store Database and be shared between all PC

this file is just for real time data for see Graph mode.

Need Help to Make Connection Between this System WITH Server And Other PCs. QUOTE from: Squashman on February 15, 2015, 11:54:03 AM

There are miles of differences between Netware 3.x and Netware 6.x.
One uses bindery and the other does not. I am not sure what your intended goal is.
A footnote:
NetWare 3.12 Server Taken Down After 16 Years of Continuous Duty
Quote
The plug was pulled when noise from the server's hard drives become intolerable.
do you have an idea for server instead netware with max performance !?Hard to give you any TYPE of server os recommendations when we have no idea what your requirements are and what you are planning to do with the server.Am i the only one who has absolutely no idea what the goal is here ? ?I agree. This thread has gone in 8 different directions already.
999.

Solve : Attrib to remove read-only from folder nested within everything else read-only?

Answer»

Trying to figure out a way in batch without going the easy route of windows interface to remove read-only attribute from "Screenshots" folder of this current WoW game CLIENT.

I found that by running a non fully patched client I can play WORLD of Warcraft with the original legacy textures and skins, but once the client is fully patched the new textures and skins enable. I dont care for the new look and Blizzard has yet to make it a option to enable/disable legacy character appearances for those of us who dont care for the new look.

What i am trying to do is make the game client read-only for everything except for the screenshots folder which will have new screenshot pictures ADDED to it from time to time. This should kill blizzard from forcing the newest textures to my system and allow for me to continue to play this way until at some point when they kill off the legacy textures through a clean-up patch. The game client functions fine within a read-only environment, but unable to add new screenshots to the screenshots folder unless I remove the read only attribute to the folder.

I could just simply do this with windows under folder properties to remove the read only attribute, but that i am stumped on how to do it in batch, i figured I'd share what i was doing here to see if someone can point out what i need to do or am doing wrong. Its too bad the ATTRIB doesnt have an EXCLUDE switch to list what to exclude when assigning the Read-Only attribute to a folder and files and folders within it. Maybe there is a better command line tool out there to do this than the regular ATTRIB function built into Windows command shell.

Here is what I have that works in setting everything read-only, but the second instruction to remove the read-only attribute only does this for files within Screenshots and does not remove the read-only attribute from the Screenshots folder itself. 
Code: [Select]attrib +r c:\Wow6\*.* /S /D
attrib -r c:\Wow6\screenshots\*.* /S /D
pause

This is in relation to this: http://www.usgamer.net/articles/the-changing-face-of-world-of-warcraft

Also to note that their battlenet update client searches drives for the location of World of Warcraft and even though masked by the C:\wow6 instead of C:\Program Files\World of Warcraft path no matter where it hides on a hard drive the updater will detect it and try to update its contents even if you dont want it to. So the read-only method is the only thing i could come up with to stop it from updating.

The other oddity is the messages about the "Not resetting hidden file" which i am not sure if I can clean up to resolve, but one of the files looks like a hidden local database and the other looks like a hidden log, so forcing these read-only is probably not critical as for it has nothing to do with texture files etc.


Quote

C:\Documents and Settings\Dave\Desktop>attrib +r c:\Wow6\*.* /S /D
Not resetting hidden file - C:\Wow6\Screenshots\Thumbs.db
Not resetting hidden file - C:\Wow6\.agent.db
Not resetting hidden file - C:\Wow6\.patch.result

C:\Documents and Settings\Dave\Desktop>attrib -r c:\Wow6\screenshots\*.* /S
 /D
Not resetting hidden file - C:\Wow6\screenshots\Thumbs.db

C:\Documents and Settings\Dave\Desktop>pause
Press any key to continue . . .
UPDATE on this:

Still unable to figure out how to attrib to have the screenshots folder the only folder with read/write privileges within WoW6 which everything else is read only, without cheating and just doing it through Windows GUI.

I contacted Blizzard to see if they have been working on a fix for those who dislike the new Character Models. The good thing is that many people flooded them with demands to have a choice to have the original models back. I was pointed to a FEATURE that was slipped into their game client that allowed me to disable the new models and have the game run with the original character models, so the read-only attribute no longer has to be set for the game client and it can fully patch now.

So other than curiosity on how to go about the read only attribute set on a folder, with all files within it read-only, except for 1 sub-folder within it and its contents not set to read-only, I guess the intent for the batch is no longer necessary, but finding out if there is still a way to do this in batch still has my interest if its not going to be a waste of anyones time to show how in case I need to do this with other games in the future to have certain folders and files read-only and others able to be overwritten.

One THOUGHT I had as I was typing this now is, would I have to deconstruct the folders to say xcopy all but the screenshots folder to another location, set the attrib to read-only for all files and folders and then have to slip the screenshots folder back into it as the only means to do this since attrib doesnt have an exclude switch like xcopy has?

Pic attached shows how to change the character model option from within the game client advanced system settings, in case anyone else out there plays wow and wants to know how to go back to the original look of the characters.

This is my one female night elf resto druid that I dislike the new character model and prefer the original appearance.



[attachment deleted by admin to conserve space]Set a folder or a file to read only doesn't keep you from deleting it or replacing it.  You would need to set File Permissions for that. Quote from: DaveLembke on February 12, 2015, 12:09:02 PM
Here is what I have that works in setting everything read-only, but the second instruction to remove the read-only attribute only does this for files within Screenshots and does not remove the read-only attribute from the Screenshots folder itself. 
Code: [Select]attrib +r c:\Wow6\*.* /S /D
attrib -r c:\Wow6\screenshots\*.* /S /D
pause


I didn't follow your post too closely but to change the folder attribute, see if this helps.

Code: [Select]attrib +r c:\Wow6\*.* /S /D
attrib -r c:\Wow6\screenshots\*.* /S
attrib -r c:\Wow6\screenshots /D
pauseHello Foxidrive ... Thanks for helping with this... I will try this out when i get home from work later today. I believe I tried the /D alone as you have on the attrib -r c:\Wow6\screenshots /D and it complained that in order to use /D it had to be in conjunction to /S but not /D alone in which it required to be /S /D and not just /D, but you could use /S alone. The OS version is Windows XP Home SP3 btw in case there were any changes to attrib that I am not aware of between windows versions. Maybe I had a typo in the use of /D alone that caused that error message about /D having to be paired with /S. 



Code: [Select]attrib +r c:\Wow6\*.* /S /D
attrib -r c:\Wow6\screenshots\*.* /S
attrib -r c:\Wow6\screenshots /D
pause
Posted by: Squashman
Quote
Set a folder or a file to read only doesn't keep you from deleting it or replacing it.  You would need to set File Permissions for that.

hmmm.... so I would have to run as a user level account with the game client with restricted permissions then instead of admin while running the game, and your saying that read-only isnt enough to stop an update from changing the game client. 

I was thinking that with updates passing like file name data as updates to a game client that the read-only would stop alteration and removal unless the read-only attribute was removed which would then allow for the changes to take.

So what i really need to be doing is setting up a user account with restricted permissions that do not allow modification of the game installation at c:\wow6 and all sub folders and files contained within.  hmmm  I didnt think I was going to restrict it this far and though a simple attribute change for all files and folders would have been good enough. But i see where you are coming from now.A read-only file can't be deleted or overwritten. Attempting to delete a read-only file causes an Access Denied error. Attempting to overwrite it will also cause an Access Denied Error.

Windows Explorer however "helpfully" removes the attribute before performing the delete or copy operation and Read Only attributes do nothing in that instance.

However, for WoW, it's going to encounter an exception/Error if it tries to overwrite or delete the files. It is possible that the game is designed in the same way as Windows Explorer, and, on encountering an issue overwriting/replacing a file, will remove attributes that are causing it and try again. ACL's are probably a better route to go.

You should be able to right-click the folder and choose "Edit..." in the security tab, then you can "deny" the write permission for your account. This assumes- of course- that the game won't crash or show an error message and quit when it encounters an error trying to write those files.

Strange.  I just created a file.  Set to read only and then right clicked it and it deleted just fine.

and from the cmd line.
Code: [Select]H:\attrib>attrib foo1.txt
A    R       H:\attrib\foo1.txt

H:\attrib>del /f foo1.txt

H:\attrib>dir
 Volume in drive H is DATA
 Volume Serial Number is D2F3-49FA

 Directory of H:\attrib

02/13/2015  09:41 AM    <DIR>          .
02/13/2015  09:41 AM    <DIR>          ..
               0 File(s)              0 bytes
               2 Dir(s)  126,999,040,000 bytes free

H:\attrib> Code: [Select]D:\>mkdir test

D:\>cd test

D:\test>copy con testfile.txt
test file
^Z
        1 file(s) copied.

D:\test>attrib testfile.txt +r

D:\test>del testfile.txt
D:\test\testfile.txt
Access is denied.

D:\test>copy testfile.txt testfile2.txt
        1 file(s) copied.

D:\test>copy testfile2.txt testfile.txt
Overwrite testfile.txt? (Yes/No/All): y
Access is denied.
        0 file(s) copied.

The /f switch on del and erase forces deletion of readonly files by explicitly checking and removing the read only attribute before attempting to delete the file- at which point, the file being deleted is not read-only anymore.

copy doesn't have a similar switch, but xcopy does. (/R).

World of warcraft is not written in batch, of course. If it doesn't explicitly check for and remove the attribute, it will encounter an exception attempting to Delete it or open it to write new contents. Given that extra logic can remove the attribute fairly easily with something like SetFileAttributes(sFilename,GetFileAttributes(sFileName) & ~FILE_ATTRIBUTE_READONLY), some applications will just remove the flag. (Like Windows Explorer). ACLs are 'safer' (for Dave's purpose) because Applications are unlikely to go fiddling with those when they encounter Error 5.


Quote from: DaveLembke on February 13, 2015, 07:31:21 AM
I believe I tried the /D alone as you have on the attrib -r c:\Wow6\screenshots /D and it complained that in order to use /D it had to be in conjunction to /S

You are correct - try this with the extra /S and it should work but this may just be academic.

Code: [Select]attrib +r c:\Wow6\*.* /S /D
attrib -r c:\Wow6\screenshots\*.* /S
attrib -r c:\Wow6\screenshots /D /S
pause
1000.

Solve : batch file to change ini?

Answer»

I have a program installed silently on few windows 7 clients.
But problem is because users need to make some settings before use it and that is problem.
Now I have saved settings and distribute it to clients in settings.ini
but problem is because in settings.ini is folder of my profile, like
c:\users\mike\documents

now I need to CHANGE my name Mike with the name of user on the client pc.

so batch will find in settings.ini mike and change it with current username.Type this in a cmd prompt:

Code: [Select]set u

Without details about your task, that will at least give you a clue.I already tried that to change to change a line in settings.ini
from
c:\users\mike\documents

to

c:\users\%username%\documents

but not working

when I go to software it shows me

c:\users\%username%\documents


instead

c:\users\george\documents

or
c:\users\tina\documents

or

c:\users\sam\documents

So I need to change that with batch when user logs in.settings.ini is not a batch file, right?

If you describe your task in technical terms then you are LIKELY to get a solution.
Or just provide enough details about the task so any readers don't have to guess what you are doing.the thing here is, that I am trying to change that line in settings.ini with a batch.
So batch will find which user is currently logged in and change the line in path to right one.
So after that path will be set for current logged in user.

problem is this path in settings.ini
c:\users\mike\documents


user Tina (username) can not save in that folder so that's why I need batch, to change that.maybe ti will help location of settings.ini in my case
it is under c:\users\mike\appdata\roaming\prts\settings.ini

so some other user have it in
c:\users\tina\appdata\roaming\prts\settings.iniOk, it's easy to find out the current users profile location.

Which line of settings.ini has to be changed?
How will this be changed - will you supply the users the batch file to run to change settings.ini ?

Can you use any tool to perform the editing of settings.ini? Quote from: foxidrive on March 05, 2015, 07:28:53 AM

Ok, it's easy to find out the current users profile location.

Which line of settings.ini has to be changed?
How will this be changed - will you supply the users the batch file to run to change settings.ini ?

Can you use any tool to perform the editing of settings.ini?
Now is in line 42
I am not soure about that line, because line may change if you change settings in software which use settings.ini
I need to test some more for that.

yes I intent to supply batch to user by system and run batch file by system on every user when he logs in

tool for editing settings.ini, I use notepad.If each path is different 1 batch won't suit your needs... Quote from: Blisk on March 05, 2015, 12:07:38 PM
Now is in line 42
I am not soure about that line, because line may change if you change settings in software which use settings.ini
I need to test some more for that.

If you want an exact solution: then providing a sample settings.ini file with a description of which line needs to change will let someone help you.

Quote

yes I intent to supply batch to user by system and run batch file by system on every user when he logs in

tool for editing settings.ini, I use notepad.

Notepad can't be scripted in a batch script.
We need to know what tools can be used to edit your file within a batch script.


here is settings.ini
http://zerobin.povej.net/?91ea09e70c9e153b#bSapGkskui9/Ms46E8+zAnoVZourlGlpRMURDoW0MhA=

about tool don't know what you mean. Installed is windeows 7 system.
If there is needed some extra tool just let me know and I will check if I can install that on clients.

I found some batch which is something like I need if that helps?
But I can not complete it for my task.
maybe can help for making my batch?

Code: [Select]echo off
set "file=%userprofile%\AppData\Local\Lotus\Notes\Data\notes.ini"
if exist "%file%" (
   findstr /v /i "IM_DISABLE= IM_DISABLED=" "%file%" >"%file%.tmp"
   >>"%file%.tmp" echo/IM_DISABLE=1
   >>"%file%.tmp" echo/IM_DISABLED=1
   move /y "%file%.tmp" "%file%" >nul
 )Give this a shot:

Code: [Select]echo off
call jrepl "^OutputFilePath=.*" "OutputFilePath=%userprofile%\documents" /f settings.ini /o -

This uses a helper batch file called `Jrepl.bat` (by dbenham) - DOWNLOAD from:  https://www.dropbox.com/s/4otci4d4s8x5ni4/Jrepl.bat

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

Be aware that Modern Windows protects the user from unknown downloaded files so it may be blocked
 - if you are happy to try it and it is blocked then
* Right click the bat file
* select the properties
* and click unblock.
runas administrator doesn't make any problem so yes I can use that in folder with batch.>Thanks this WORKS great!
I have just one problem, replacing settings ini must be when software is off.
So first I need to do is taskkill
and than run this batch to change settings.ini

Is there a way to check first if that settings is already changed and if it is, than won't change it?
Like if name Mike exist in settings.ini than must be changed if it deosn't exist than it is already changed.
OK I manage that by myself.
Thank you for helping now all works great!