Search found 1920 matches
- 08 Feb 2013 22:20
- Forum: DOS Batch Forum
- Topic: Determining the number of lines in a file.
- Replies: 50
- Views: 56573
Re: Determining the number of lines in a file.
Perhaps you may want to test the Batch file below; it use FINDSTR with /O option to get the line length, and divide the file size by line length to correctly get the remainder. FINDSTR /O get the length of the first (any) line in bytes independently if it ends in CR+LF or just LF. @echo off setlocal...
- 08 Feb 2013 00:42
- Forum: DOS Batch Forum
- Topic: Merge and rename duplicate files to incr by 1 ex: fn (1).ext
- Replies: 13
- Views: 15940
Re: Merge and rename duplicate files to incr by 1 ex: fn (1)
I used a different approach to solve this problem via a recursive subroutine that, in my opinion, is clearer and would run faster because the executed code is lesser. The Batch program below was developed in accordance with the pseudo-code you stated at beginning of this topic. @echo off setlocal En...
- 07 Feb 2013 08:39
- Forum: DOS Batch Forum
- Topic: how to add decimal numbers using batch file?
- Replies: 11
- Views: 46723
Re: how to add decimal numbers using batch file?
In the Batch file below I completed the FP conversion routines so they correctly manage fixed point numbers with negative sign and left zeros. I also added a second example. @echo off setlocal EnableDelayedExpansion call :IntAsFP a=2.4 call :IntAsFp b=4.5 set /A c=a+b call :IntToFP c=%c% 1 echo %c% ...
- 06 Feb 2013 20:46
- Forum: DOS Batch Forum
- Topic: how to add decimal numbers using batch file?
- Replies: 11
- Views: 46723
Re: how to add decimal numbers using batch file?
You may write a Batch file that split the available digits of 32-bits signed numbers in integer and fractional parts in a very easy way; the only problem is that you must write numbers with the right number of decimal digits (unless you insert additional code to check and fix this point). At Fractio...
- 29 Jan 2013 09:44
- Forum: DOS Batch Forum
- Topic: How set "delims=quote... in FOR command?
- Replies: 9
- Views: 14095
Re: How set "delims=quote... in FOR command?
Here is the general syntax for quote delimiting for /f tokens^=2^ delims^=^" %%p in (file.txt) do echo "%%p" You forgot to include the second token and escape its comma! for /f tokens^=2^,4^ delims^=^" %%p in (file.txt) do echo "%%p %%q" Thanks a lot! Antonio
- 29 Jan 2013 08:05
- Forum: DOS Batch Forum
- Topic: How set "delims=quote... in FOR command?
- Replies: 9
- Views: 14095
How set "delims=quote... in FOR command?
I am pretty sure this question has been answered before, but I can't find it! I have a file with this line of text: sometext name1="first value" name2="second value" more text I want to take the values enclosed in quotes. I try to escape the quote, but the next command issue a sy...
- 28 Jan 2013 10:14
- Forum: DOS Batch Forum
- Topic: IF curioisity: Delayed expansion of undefined variable = 0
- Replies: 14
- Views: 17402
Re: IF curioisity: Delayed expansion of undefined variable =
I suppose that IF command uses the classical method to convert a string to number before the numeric comparison: set string=12345 set number=0 :nextDigit if not defined string goto completed set /A number=number*10 + %string:~0,1% set string=%string:~1% goto nextDigit :completed Previous method retu...
- 25 Jan 2013 23:59
- Forum: DOS Batch Forum
- Topic: How to question: process display until user presses a key
- Replies: 2
- Views: 3132
Re: How to question: process display until user presses a ke
You may use my GetKey.exe auxiliary program: Get a key from keyboard and return its value in ERRORLEVEL. GetKey [/N] Ascii characters are returned as positive values, extended keys as negative values. If /N switch is given, no wait for a key: immediately return zero if no key was pressed. /N switch ...
- 23 Jan 2013 09:11
- Forum: DOS Batch Forum
- Topic: open most recently saved file in subfolders
- Replies: 10
- Views: 8109
Re: open most recently saved file in subfolders
You may get the last year and file with your method: get the first name in a FOR and break it whit GOTO. The problem are the month names , so they must be converted to a number. @echo off setlocal EnableDelayedExpansion rem Create the array to convert file names to numbers set i=0 for %%a in (Januar...
- 23 Jan 2013 08:02
- Forum: DOS Batch Forum
- Topic: Correcting Decimal to Binary and Hexadecimal converter
- Replies: 9
- Views: 8638
Re: Correcting Decimal to Binary and Hexadecimal converter
You may divide the large number in smaller chunks of digits, so each part can be managed in 32-bits integers. For Dec to Hex conversion you must use groups of 4 digits, but for Dec to Binary you may use groups of up to 9 decimal digits. Full details here: http://www.dostips.com/forum/viewtopic.php?f...
- 23 Jan 2013 07:42
- Forum: DOS Batch Forum
- Topic: batch rename
- Replies: 23
- Views: 23456
Re: batch rename
Perhaps a simpler way to understand previous method is this: set /A parity=number %% 2 In this case, parity is equal to the remainder when the number is divided by two. Of course, such remainder is zero for even numbers and is one for odd numbers. However, this operation is slightly slower than a bi...
- 22 Jan 2013 19:46
- Forum: DOS Batch Forum
- Topic: batch rename
- Replies: 23
- Views: 23456
Re: batch rename
This is the method I use to determine if a number is odd or even: set /A "parity=number & 1" Previous line take the rightmost bit of number and store it in parity variable, so its value is 0 if number is even, otherwise is 1. if %parity% equ 0 ( echo The number is even ) else ( echo Th...
- 22 Jan 2013 19:00
- Forum: DOS Batch Forum
- Topic: Correcting Decimal to Binary and Hexadecimal converter
- Replies: 9
- Views: 8638
Re: Correcting Decimal to Binary and Hexadecimal converter
Now this line won't compute correctly. set finalnumHEX=%chars:~!modulusHEX!,1%%finalnumHEX% When I type in 5 for the number to convert, this is the value of finalnumHEX. chars:~5,1%finalnumHEX That's it. It just won't compute Remember that DELAYED expansion, that is, a variable enclosed in exclamat...
- 22 Jan 2013 08:26
- Forum: DOS Batch Forum
- Topic: batch rename
- Replies: 23
- Views: 23456
Re: batch rename
Yes, the problem is precisely the one you said, but supposedly I have fixed it with the "lastRename" variable (although not correctly ). If the problem is fixed other way then "lastRename" should be removed, but there is another point here. If after inserting the sd card in the c...
- 22 Jan 2013 00:05
- Forum: DOS Batch Forum
- Topic: batch rename
- Replies: 23
- Views: 23456
Re: batch rename
Antonio thank you for your input. I appreciate it. Correct me if I am wrong, but whether the half run (be that the odd pages or the even pages) total file number will be odd or even, it will depend on the number of pages of the original document. For example, for a 10 page document, the half run wi...