| 1. |
Solve : Fixed width? |
|
Answer» The place I'm starting from is the first stepping stone to a more complex batch file. What I want to have the batch file do at the moment is count from one input number to the second input number by 1. I have it working to get the two numbers and can get it to count up. the issue I run into is trying to zero pad the front of my numbers. This is what I have right now. Pad the number with a larger number of pad characters than you will need (can be any character, not just zero). Then select the rightmost N-1 characters using the syntaxYour code should run much QUICKER. And as I always say time is money. But I wasn't sure if the O/P wanted numbers greater than 99 to be padded with a zero. Too me it looks like they wanted 001 010 100 1000Lemming, I understood about why you used echo. I use the method I showed above in a variety of DIFFERENT batch scripts, including bulk renaming of files and it is just as effective as any other method. It is more efficient, unless you are specifically doing the tests for other reasons and there is other processing involved with each test. If not, and if you were wanting to set a variable for instance, you would just change it to Code: [Select]echo off setlocal enabledelayedexpansion for /l %%a in (%1,1,%2) do ( set num=00000000000000000000%%a set var=!num:~-4! ) But this is more about efficient programming than anything, and showing you another way to accomplish the task you initially wanted done. If your personal preference is to use my originally posted method, then by all means feel free to use it. This is what I'm doing and it makes it a little easier to do the brute force way vs variable. It is easier since I am very new to batch file writing. I have also expanded the batch file to take in two numbers when being called Code: [Select]TG_batch.bat 1 2 Code: [Select]echo off Title TG batch for /l %%A in (%1, 1, %2) do ( if /i %%A LLS 10 ( xcopy t:\!template t:\run\00%%A copy t:\!def\00%%A.atmo t:\00%%A\part1\00%%A.atmo run other program 1 copy output.testcase ..\part2\input.dat run other program 2 ) else ( if...... if...... ) This is for the most part what I am doing with the help initially from Raven. The file structure is only set to run no more than 100 iterations so getting to 1000 was never a concern. Since I am new I don't know how to correctly IMPLEMENT the smaller set of batch code with what I need it to do. I am extactic to see the number of responses to this. It is just that at the time I don't know how to correctly use the new supplied way. Thank you all for your help.another way if you want to see the powers of 10 Code: [Select]echo off setlocal enabledelayedexpansion REM pad with spaces set "padchar= " REM pad with zeroes set padchar=0 for /l %%a in (%1,1,%2) do ( set pad=& for %%b in (10000 1000 100 10) do if %%a lss %%b set pad=%padchar%!pad! echo !pad!%%a ) Quote from: lemming622 on December 29, 2011, 05:28:14 PM This is what I'm doing and it makes it a little easier to do the brute force way vs variable. It is easier since I am very new to batch file writing. I have also expanded the batch file to take in two numbers when being calledIf you do it that way you have to replicate all your commands inside each IF ELSE. Use the IF ELSE to SET a variable with the padded number then do all your commands. |
|