Sign in to follow this  
Followers 0
gregnottage

Find files, check extensions and take action based on extension

4 posts in this topic

Hi,

Please can someone give me some pointers on how to check a known folder path for the files it contains, check the file extensions of the files found in the folder and then take action based on what file extension is detected?

I tried looking at _PathSplit() but that didn't quite do what I needed.

Thanks,

Greg.

Share this post


Link to post
Share on other sites



You could probably use this, it counts the occurences of all file extensions in a path and displays each extension and its count.

#433158

Share this post


Link to post
Share on other sites

WeaponX: I've tried amending your code as follows:

CODE
$extensionsObj = ObjCreate("Scripting.Dictionary")

recursiveExtensionStats("C:\IMG")

If $key In $extensionsObj.Keys() = "wim" Then

Msgbox(0, "Normal WIM", $key)

ElseIf $key In $extensionsObj.Keys() = "swm" Then

Msgbox(0, "Split WIM", $key)

Next

Func recursiveExtensionStats($startDir)

$search = FileFindFirstFile($startDir & "\*.*")

If @error Then Return

;Search through all files and folders in directory

While 1

$next = FileFindNextFile($search)

If @error Then Return

;If folder, recurse

If FileGetAttrib($startDir & "\" & $next) = "D" Then

recursiveExtensionStats($startDir & "\" & $next)

Else

$tempSplit = StringSplit($next,".")

$ext = StringLower($tempSplit[$tempSplit[0]])

;If the extension already exists in the dictionary, increment

If $extensionsObj.Exists($ext) Then

$extensionsObj.Item($ext) = $extensionsObj.Item($ext) + 1

Else

$extensionsObj.Add($ext, 1)

EndIf

EndIf

WEnd

FileClose($search)

EndFunc

But that isn't working?

Not sure what I'm doing wrong here??

Thanks,

Greg.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0