Page 1 of 1 1
Topic Options
#192918 - 2009-03-16 04:42 PM run function on file in searched sub directories
jeff_eisenberg Offline
Fresh Scripter

Registered: 2009-02-26
Posts: 45
Loc: CA
I have a function you guys helped me with and I just realized I need to search sub directoris for a specific named file and run the function on the file in each of those sub directories.

So I need to search each subdirectory of %AppData%\Skype\, and no deeper, for the file Config.xml. And then run my fuction on that file.

I've looked for scripts for searching for files in sub directories and couldn't find anything. Any help putting this together would be great

Here is the function I'm calling with some variables (AppDataDirectory and SubDir) that would need to be looped in somehow?

Break On
$FILENAME = "@AppDataDirectory\Skype\@SubDir\Config.XML"
$XML = LoadXML($FILENAME)
WriteXMLValue($XML, "config/Lib/Chat/HistoryDays", 123)
SaveXML($XML, $FILENAME)
Exit 0

Top
#192919 - 2009-03-16 05:45 PM Re: run function on file in searched sub directories [Re: jeff_eisenberg]
Shawn Administrator Offline
Administrator
*****

Registered: 1999-08-13
Posts: 8611
Might give the FindFile udf a try, here's some sample code:

 Code:
Break On

$MATCH = "*.xml"
$FOLDER = "c:\YourFolder"

$Array = FindFile($MATCH,1,$FOLDER)

For Each $Filename In $Array
 ?"Found = " + $Filename
Next

Exit 0

Function findfile($a,optional $b,$c,$d,$e,$f)
	Dim $,$w,$x,$y,$z[0]
	$b=Val($b)
	$d=Val($d)
	$e=Val($e)
	$f=Val($f)
	If ($b & 2) And ($b & 4) $b=$b-4 EndIf
	If $d<1 Or $d>26 $d=3 EndIf
	If $e<1 Or $e>26 $e=26 EndIf
	If $d>$e Exit 1 EndIf
	If $e<1 $e=0 EndIf
	$d=$d+64
	$e=$e+64
	If InStr($a,":") Or InStr($a,"\") Or InStr($a,"/") Or InStr($a,'"') Or InStr($a,"<") Or InStr($a,">") Or InStr($a,"|") Or Len($a)<1
		Exit 1
	EndIf
	If $c
		While Right($c,1)="*" Or Right($c,1)="." Or Right($c,1)="\" $c=Left($c,Len($c)-1) Loop
		If Not Exist($c) Exit 1 EndIf
		$x=$c
	Else
		$x=Chr($d)+":"
		While Not Exist($x+"\*.*")
			$d=$d+1
			If $d>$e Exit 1 EndIf
			$x=Chr($d)+":"
		Loop
	EndIf
	If InStr($a,"?") Or InStr($a,"*") $w=1 Else $w=0 EndIf
	$y=0
	While $y=0
		If Exist($x+"\"+$a)
			If ($b & 1)
				If $w=0
					$z[UBound($z)]=Iif($b & 2,'"','')+Iif($b & 4,"'","")+$x+"\"+$a+Iif($b & 2,'"','')+Iif($b & 4,"'","")
					ReDim Preserve $z[UBound($z)+1]
				Else
					$=Dir($x+"\"+$a,2)
					Do
						If Right($,1)<>"."
							$z[UBound($z)]=Iif($b & 2,'"','')+Iif($b & 4,"'","")+$x+"\"+$+Iif($b & 2,'"','')+Iif($b & 4,"'","")
							ReDim Preserve $z[UBound($z)+1]
						EndIf
						$=Dir(,2)
					Until @Error Or (UBound($z)>=$f And $f<>0)
				EndIf
				If UBound($z)>=$f And $f<>0 $y=1 EndIf
			Else
				If $w=0
					$findfile=Iif($b & 2,'"','')+Iif($b & 4,"'","")+$x+"\"+$a+Iif($b & 2,'"','')+Iif($b & 4,"'","")
					Exit 0
				Else
					$=Dir($x+"\"+$a,2)
					Do
						If Right($,1)<>"."
							$findfile=Iif($b & 2,'"','')+Iif($b & 4,"'","")+$x+"\"+$+Iif($b & 2,'"','')+Iif($b & 4,"'","")
							Exit 0
						EndIf
						$=Dir(,2)
					Until @Error
				EndIf
			EndIf
		EndIf
		$x=DirWalker($x)
		If $c And Left($x,Len($c))<>$c $y=1 EndIf
		If $x=""
			If $d=$e
				$y=1
			Else
				$d=$d+1
				$x=Chr($d)+":"
				While Not Exist($x+"\*.*") And $d<=$e
					$d=$d+1
					$x=Chr($d)+":"
				Loop
				If Not Exist($x+"\*.*") $y=1 EndIf
			EndIf
		EndIf
	Loop
	If ($b & 1)
		If UBound($z)>0 ReDim Preserve $z[UBound($z)-1] EndIf
		$findfile=$z
	EndIf
	Exit 0
EndFunction

Function dirwalker($a)
	Dim $b,$c
	If Not (GetFileAttr($a) & 16) Exit 3 EndIf
	If Right($a,1)="\" $a=Left($a,Len($a)-1) EndIf
	$b=$a+"\"+Dir($a+"\*.*",2)
	While @Error=0
		If Right($b,1)<>"." And (GetFileAttr($b) & 16)
			$dirwalker=$b
			Exit 0
		EndIf
		$b=$a+"\"+Dir("",2)
	Loop
	While Right($a,1)<>":"
		$c=Left($a,InStrRev($a,"\")-1)
		$b=$c+"\"+Dir($c+"\*.*",2)
		While $b<>$a
			$b=$c+"\"+Dir("",2)
		Loop
		$b=$c+"\"+Dir("",2)
		While @Error=0
			If (GetFileAttr($b) & 16) And Right($b,1)<>"."
				$dirwalker=$b
				Exit 0
			EndIf
			$b=$c+"\"+Dir("",2)
		Loop
		$a=$c
	Loop
	$dirwalker=""
	Exit 18
EndFunction


-Shawn

Top
#192922 - 2009-03-16 06:22 PM Re: run function on file in searched sub directories [Re: Shawn]
NTDOC Administrator Offline
Administrator
*****

Registered: 2000-07-28
Posts: 11628
Loc: CA
From our old buddy Gaven eh! He would be proud.
Top
#192925 - 2009-03-16 07:53 PM Re: run function on file in searched sub directories [Re: NTDOC]
jeff_eisenberg Offline
Fresh Scripter

Registered: 2009-02-26
Posts: 45
Loc: CA
Cool. Thanks. So then would the result be passed to my 2nd function like this?

For Each $Filename In $Array
?"Found = " + $Filename
$XML = LoadXML($Found)
WriteXMLValue($XML, "config/Lib/Chat/HistoryDays", 123)
SaveXML($XML, $Found)
Next

Top
#192927 - 2009-03-16 08:16 PM Re: run function on file in searched sub directories [Re: jeff_eisenberg]
Shawn Administrator Offline
Administrator
*****

Registered: 1999-08-13
Posts: 8611
Yip, with a small tweak, like this (un-tested) assuming it would be OK to change every instance found ...

 Code:
For Each $Filename In $Array
 ?"Found = " + $Filename
 $XML = LoadXML($Filename)
 WriteXMLValue($XML, "config/Lib/Chat/HistoryDays", 123)
 SaveXML($XML, $Filename)
Next 

Top
#192929 - 2009-03-16 09:32 PM Re: run function on file in searched sub directories [Re: Shawn]
jeff_eisenberg Offline
Fresh Scripter

Registered: 2009-02-26
Posts: 45
Loc: CA
Beautiful. Thank you very much. Works perfect.
Top
Page 1 of 1 1


Moderator:  Jochen, Allen, Radimus, Glenn Barnas, ShaneEP, Ruud van Velsen, Arend_, Mart 
Hop to:
Shout Box

Who's Online
0 registered and 1188 anonymous users online.
Newest Members
StuTheCoder, M_Moore, BeeEm, min_seow, Audio
17884 Registered Users

Generated in 0.061 seconds in which 0.029 seconds were spent on a total of 13 queries. Zlib compression enabled.

Search the board with:
superb Board Search
or try with google:
Google
Web kixtart.org