1.

Solve : Formatting FOR Loop Value?

Answer»

Hi All,

Am curious to know how I'd format the %%i value to display two digits. (01, 02, 03, ..., 09)
I currently have ...Code: [Select]for /l %%i in (1,1,%MonitorLoops%) do (
if %%i LEQ 9 (set %%i=0%%i)
echo Check %%i - Performed at %TIME%
)And not surprisingly, not getting the result I was looking for.
Can ANYONE part with suggestion on how I'd answer this formatting query ??

Cheers,
CameronI'm sure this could be done in a very clever way, but down and dirty also works:

Code: [Select]@echo off
setlocal enabledelayedexpansion
for /l %%i in (1,1,%MonitorLoops%) do (
set num=%%i
if %%i LEQ 9 set num=0%%i
echo Check !num! - Performed at %TIME%
)

How's the project coming Cameron?

How about this...

using set /a avoids a string comparison

Code: [Select]@echo off
setlocal enabledelayedexpansion
set Monitorloops=20
for /l %%i in (1,1,%MonitorLoops%) do (
set /a num=%%i
set pad=
if !num! LEQ 9 set pad=0
set num=!pad!!num!
echo Check !num! - Performed at %TIME%
)

Or do the padding in a loop

Code: [Select]@echo off
setlocal enabledelayedexpansion
set Monitorloops=20
REM 1=no padding, 2 upwards=pad with zeros
set digits=2
for /l %%i in (1,1,%MonitorLoops%) do (
set /a num=%%i
set max=&set pad=
for /l %%p in (2,1,%digits%) do set max=9!max!&if !num! LEQ !max! set pad=0!pad!
set num=!pad!!num!
echo Check !num! - Performed at %TIME%
)
Many thanks SIDEWINDER & Dias ,

Took a snippet from each of your offerings to keep it short & sweet ...Code: [Select]for /l %%i in (1,1,%MonitorLoops%) do (
set /a num=%%i
if !num! LEQ 9 set num=0!num!
@echo Check !num! - Performed at %TIME% >> %OutputLog%
Quote from: Sidewinder on JUNE 03, 2008, 11:32:23 AM

How's the project coming Cameron?
All done (well kinda).

Have finished preliminary testing and all is working as it should. The task is an sftp monitor and transport script using Bitvise's sftpc.exe application.

Intent is that files come to a sftp server (where this script is located) from a HP-UX box. This script will monitor for the existance of a trigger file and when found, attempts to CONNECT and push the received 'data' file (received prior the trigger) to a remote sftp service. This is to maintain PCI complience - Both the HP-UX server & Remote SFTP server have Security POLICY & Practises that neither allow direct transfer (push & pull) of data .. and the same type of direct transfers are not permitted under PCI.

I've just to code the clean up after each transfer (won't take long).

And then to wait on the guys in Europe to get their end ready for some end-to-end testing.

Cheers,
Cameron


Discussion

No Comment Found