News:

Building a 3D Ray Tracer  By stevmjon

Main Menu

Function To Create Sequential Filenames

Started by kevin, June 29, 2008, 09:18:23 AM

Previous topic - Next topic

kevin

Create Sequential Filenames


  This function replaces the HASH characters within a filename with a number.   You can use this to help you load files that number filenames.

  Eg  Picture1.bmp,  Picture2,bmp  etc   Picture10.bmp

 or

  Eg  Picture01.bmp,  Picture02,bmp  etc  Picture10.bmp



 You can use it in two different ways.

   1 Hash                  = replace single Hash with number (no matter how many digits in number)

   More than one hash  = insert zero padded number in place of hash characters  




PlayBASIC Code: [Select]
   //  Example of replacing a single hash character (within the filename) with a number
Print "Example #1 --------------------------------------"
name$="Picture#.bmp"
For lp=0 to 10
print CreateSequentialFilename(Name$,lp)
next


// Example of replacing a formated zero padded number into a file name$
Print "Example #2 --------------------------------------"
name$="Picture####.bmp"
For lp=0 to 10
print CreateSequentialFilename(Name$,lp)
next



Sync
waitkey

;*=-----------------------------------------------------------------------------=*
; >> Create Sequential Filenames <<
;*=-----------------------------------------------------------------------------=*

; This function replaces the HASH character with the number.
; You can use it in two different ways.
;
; 1 Hash = replace Hash with number (no matter how many digits)
;
; More than one hash = insert zero padded number in place of hash characters
;
;*=-----------------------------------------------------------------------------=*


Function CreateSequentialFilename(Name$,Index)
local Pos=Instring(Name$,"#",1,false)
local Start=0
local RunLengh=0
For lp=1 to len(Name$)
local ThisChr=mid(Name$,lp)
if ThisChr=asc("#")
if Start=0
Start=lp
Endif
inc runlength
else
If Start then ExitFor
endif
next
if RunLength>0
local HashString$=Make$("#",RunLength)
if RunLength=1
local D$=Str$(Index)
else
local D$=Digits$(Index,RunLength)
endif
Name$=replace$(Name$,HashString$,d$,1,false,false)
endif
EndFunction Name$