Archive: Locate and return names multiple similar files


Locate and return names multiple similar files
  MY goal is to be able to look in the Microsoft SQL data folder for databases file that my installer detached and tagged (file tage=<Dbname>_DateTimeStamp.mdf) when the software was uninstalled and display them to the user when they are reinstalling so they can select if they want to use them or not.

So far I am able to do this for one file but I need to display all DB files in the SQL data directory. I'm have problems figuring out how to do this with the locate function. It only returns the last found file. Is there a way to loop the locate function and return the file name for each file it finds until there are no more file by the name its searching? I have been searching like this:

${Locate} "c:\test" "/L=F /M=dbname2311*.mdf" "FileParse"

Also, Is there a string function that allows you to insert characters at a specific point in a string. Like this.

String = "11122006"

insert "/" after 2 charactor

Now I Have 11/122006


Is there a way to loop the locate function and return the file name for each file it finds until there are no more file by the name its searching?
I believe this is similar with the given example on the following forum thread.
All you need to do is to change the empty folders to files.

http://forums.winamp.com/showthread....hreadid=263445

Also, Is there a string function that allows you to insert characters at a specific point in a string. Like this.

String = "11122006"

insert "/" after 2 charactor

Now I Have 11/122006
StrCpy$0 "11122006" # $0 is 11122006

>StrCpy $1 $0 2 # $1 is 11
>StrCpy $1 "$1/" # $1 is 11/
>StrCpy $1 $0 "" 2 # $1 is 11/122006

Originally posted by Comm@nder21
StrCpy$0 "11122006" # $0 is 11122006

>StrCpy $1 $0 2 # $1 is 11
>StrCpy $1 "$1/" # $1 is 11/
>StrCpy $1 $0 "" 2 # $1 is 11/122006
That didnt work it returns 122006

This works tho:
      StrCpy$0 "11122006" # $0 is 11122006

>StrCpy $1 $0 2 # $1 is 11
>StrCpy $3 $0 "" 2 # $3 is 122006
>StrCpy $1 "$1/" # $1 is 11/
>StrCpy $4 "$1$3" # $4 is 11/122006

Heres what I ended up doing for anyone who is interested. Forgive me for the poor commenting I have a deliverable to meet.;)I will update at later time if anyone cares.

This takes a directory path specified in $SQLDATA searches through it for the file value you specified (expamle: watchdb2311*.mdf) and as long as the file is in this format (<name>_MMDDYYYYmmss) it will extract the data and time in the file and return it as MM/DD/YYYY mm:ss to the field number for a DropList you specify in a custom page.

Function FileParse


Push"_" #divider char
Push $R7 #input string
Call SplitFirstStrPart
Pop $Split0 #1st part(Garbage)
Pop $R4 #rest

Push "." #divider char
Push $R4 #input string
Call SplitFirstStrPart
Pop $R5 #1st part
Pop $Split3 #rest (Garbage)

StrCpy $0 "$R5" # $0 is 11122006
StrCpy $1 $0 2 # $1 is 11
StrCpy $2 $0 "" 2 # $3 is 122006
StrCpy $1 "$1/" # $1 is 11/
StrCpy $3 "$1$2" # $4 is 11/122006

StrCpy $4 "$3" 5
StrCpy$5 $3 "" 5
StrCpy$4 "$4/"
StrCpy $6 "$4$5"

StrCpy $7 "$6" 10
StrCpy$8 $6 "" 10
StrCpy$7 "$7 "
StrCpy $9 "$7$8"

StrCpy "$1" "$9" 13
StrCpy"$2" $9 "" 13
StrCpy "$1" "$1:"
StrCpy "$3" "$1$2"

StrCpy $DBDATESTATE $3
StrCpy $DBDATE "$3|$DBDATE"

Push $R0
FunctionEnd

>Function GetDBFiles

Pop $FieldNumber
Pop $FileName

StrCpy $R2 0
StrCpy $R3 0
loop:
StrCpy $R1 0
${Locate} "$SQLDATA" "/L=F /M=$FileName" "FileParse"
IntOp $R3 $R3 + 1
IntOp $R2 $R2+ $R1
StrCmp $R1 0 0 loop

WriteINIStr "$PLUGINSDIR\DBCreate.ini" "Field $FieldNumber" "State" "$DBDATESTATE"
WriteINIStr "$PLUGINSDIR\DBCreate.ini" "Field $FieldNumber" "ListItems" "$DBDATE"
>FunctionEnd

>Function .onInit

Push "dbnameA2311*.mdf"
Push "3"
call GetDBFiles

StrCpy $DBDATESTATE ""
StrCpy $DBDATE ""
Push "dbnameB2311*.mdf"
Push "5"
call GetDBFiles

FunctionEnd
>
;);) ;)

sry, there was a small typo in my script, this one is correct:


StrCpy $0 "11122006" # $0 is 11122006

>StrCpy $1 "$0" 2 # $1 is 11
>StrCpy $1 "$1/" # $1 is 11/
>StrCpy $0 "$0" "" 2 # $0 is 122006
>StrCpy $1 "$1$0" # $1 is 11/122006