script to build 9 letter filename from ra

January 7, 2011 at 01:59:34
Specs: Windows XP, 2Gb
i need a filename to be renamed to a 9 character filename from a randomly generated filename length less than 9 characters. ie. 4567 needs to be 000004567, 123 needs to be 000000123. This would need to be added to the miidle of a file name. ie.
AC123456_IF_SAS-GLACVT-<random>_CCYYMMDD_000.csv so the random part needs to be bulked out to 9 characters as above. If this makes any sense at all. thanks

See More: script to build 9 letter filename from ra

Report •

#1
January 7, 2011 at 02:44:28
This should get your number:

set var=00000000%random%
set var=%var:~-9%
echo %var%

P.S:

Windows xp cmd/bat scripting != dos.


Report •

#2
January 7, 2011 at 02:56:57
If it boils down to 'pad to 9' try this:

==============================================
@echo off & setLocal enableDELAYedeXpansion

set /p R=string of 1 to 8 chars ? :

if !R! lss 100000000 set N=0!R!
if !R! lss 10000000 set N=00!R!
if !R! lss 1000000 set N=000!R!
if !R! lss 100000 set N=0000!R!
if !R! lss 10000 set N=00000!R!
if !R! lss 1000 set N=000000!R!
if !R! lss 100 set N=0000000!R!
if !R! lss 10 set N=00000000!R!

echo.!N!


=====================================
Life is too important to be taken seriously.

M2


Report •

#3
January 7, 2011 at 03:00:21
Hi Judago,

kewl


=====================================
Life is too important to be taken seriously.

M2


Report •

Related Solutions

#4
January 7, 2011 at 03:22:18
Hi M2,

I missed something anyway, 32767 is only 5 chars...

set var=0000000%random%
set var=%var%%random%
set var=%var:~-9%
echo %var%


Report •

Ask Question