Jump to content
Sign in to follow this  
FuryCell

UDFs

Recommended Posts

here are the udfs i just created:

_FileList()

;===============================================================================
;
; Description:      lists all files and folders in a specified path (Similar to using Dir with the /B Switch)
; Syntax:           _FileList($sPath)

; Parameter(s):        $sPath = Path to generate filelist for
; Requirement(s):   None
; Return Value(s):  On Success - Returns an array containing the list of files and folders in the specified path
;                    On Failure - Returns an empty string "" if no files are found and sets @Error to 1 if the path is not found
; Author(s):        SolidSnake <MetalGearX91@Hotmail.com>
; Note(s):            The array returned is one-dimensional and is made up as follows:
;                    $array[0] = Number of Files\Folders returned
;                    $array[1] = 1st File\Folder
;                    $array[2] = 2nd File\Folder
;                    $array[3] = 3rd File\Folder
;                    $array[n] = nth File\Folder
;================================================================================

_RegValueList()

;===============================================================================
;
; Description:      lists the names of all values in a specified key
; Syntax:           _RegValueList($sKey)

; Parameter(s):        $sKey = Key to generate valuelist for
; Requirement(s):   None
; Return Value(s):  On Success - Returns an array containing the list of values in the specified path
;                    On Failure - Returns an empty string "" if no values are found and sets @Error to 1 if the key is not found
; Author(s):        SolidSnake <MetalGearX91@Hotmail.com>
; Note(s):            The array returned is one-dimensional and is made up as follows:
;                    $array[0] = Number of values returned
;                    $array[1] = 1st value
;                    $array[2] = 2nd value
;                    $array[3] = 3rd value
;                    $array[n] = nth value
;===============================================================================

_RegKeyList()

;===============================================================================
;
; Description:      lists all subkeys in a specified key
; Syntax:           _RegKeyList($sKey)

; Parameter(s):        $sKey = Key to generate keylist for
; Requirement(s):   None
; Return Value(s):  On Success - Returns an array containing the list of subkeys in the specified path
;                    On Failure - Returns an empty string "" if no Keys are found and sets @Error to 1 if the key is not found
; Author(s):        SolidSnake <MetalGearX91@Hotmail.com>
; Note(s):            The array returned is one-dimensional and is made up as follows:
;                    $array[0] = Number of Keys returned
;                    $array[1] = 1st Key
;                    $array[2] = 2nd Key
;                    $array[3] = 3rd Key
;                    $array[n] = nth Key
;===============================================================================

Enjoy :(

Edit:See Post Below to download new version.

Edited by SolidSnake

HKTunes:Softpedia | GoogleCodeLyricToy:Softpedia | GoogleCodeRCTunes:Softpedia | GoogleCodeMichtaToolsProgrammer n. - An ingenious device that turns caffeine into code.

Share this post


Link to post
Share on other sites

Tested on Windows 2000 (SP4) and they all seem to work perfectly.

I said "seem to work", because I'm currently on a restricted computer,

so I'm unable to enter the registry to manually check the keys and values.

Anyway.. Nice work SolidSnake !

Share this post


Link to post
Share on other sites

Just an idea..

What about adding another parameter to _FileList where you could

decide if it should return files or folders (or both) ... ?

FileList("c:\",0); Default (shows files and folders)
FileList("c:\",1); Just files
FileList("c:\",2;; Just folders

What do you think ?

Share this post


Link to post
Share on other sites

Just an idea..

What about adding another parameter to _FileList where you could

decide if it should return files or folders (or both) ... ?

FileList("c:\",0); Default (shows files and folders)
FileList("c:\",1); Just files
FileList("c:\",2;; Just folders

What do you think ?

<{POST_SNAPBACK}>

I would like to do that but don't know of anyway to tell files and folders apart. :(

If anyone knows and would like to help me out feel free.

anyway Thanks for the feedback Layer and Helge :(

Edited by SolidSnake

HKTunes:Softpedia | GoogleCodeLyricToy:Softpedia | GoogleCodeRCTunes:Softpedia | GoogleCodeMichtaToolsProgrammer n. - An ingenious device that turns caffeine into code.

Share this post


Link to post
Share on other sites

I would like to do that but don't know of anyway to tell files and folders apart.  :(

FileGetAttrib() ?

Cheers

Kurt


__________________________________________________________(l)user: Hey admin slave, how can I recover my deleted files?admin: No problem, there is a nice tool. It's called rm, like recovery method. Make sure to call it with the "recover fast" option like this: rm -rf *

Share this post


Link to post
Share on other sites

here is a function i just made to determine that! :

Func FileOrFolder($path)
   Local $len = StringLen($path)
   If StringMid($path, $len) = "\" Then
      MsgBox(0, "Folder", $path & " is a folder.")
   Else
      MsgBox(0, "File", $path & " is a file.")
   EndIf
EndFunc  ;==>FileOrFolder

FileOrFolder("C:\Program Files\AutoIt3\AutoIt3.exe")
FileOrFolder("C:\")

good luck! :(

EDIT: Also, FileGetAttrib would work, but my function looks so much cooler! Don't ya think :(

Edited by layer

Share this post


Link to post
Share on other sites

Also, how can the user tell apart a folder and a file ?

One way of doing it is to add a "\" at the end of the folders..

Can't think of another decent method... :(

Share this post


Link to post
Share on other sites

Also, how can the user tell apart a folder and a file ?

One way of doing it is to add a "\" at the end of the folders..

Can't think of another decent method...  :(

<{POST_SNAPBACK}>

I don't understand do you mean for my script to add a "\"?

If so i would need to know how to find the diffrence

Edit:Oops! Didn't see layers post. :">

I will try to update file list with the flags like you said using layers idea of filegetattrib

Edited by SolidSnake

HKTunes:Softpedia | GoogleCodeLyricToy:Softpedia | GoogleCodeRCTunes:Softpedia | GoogleCodeMichtaToolsProgrammer n. - An ingenious device that turns caffeine into code.

Share this post


Link to post
Share on other sites

Here is the new version.  :(  I added the flag Parameters that Helge gave me the idea for to _FileList ().I also made _RegValueList() and _RegKeyList () into one function called _RegList() that uses flags

Now it contains two functions.

_FileList ():

;===============================================================================
;
; Description:      Lists all files and folders in a specified path. (Similar to using Dir with the /B Switch)
; Syntax:           _FileList($sPath,$iFlag=0)

; Parameter(s):        $sPath = Path to generate filelist for
;                   $iFlag = determines weather to return file or folders or both
;                      $iFlag=0(Default) Return both files and folders
;                      $iFlag=1 Return files only
;                      $iFlag=2 Return Folders only
;
; Requirement(s):   None
; Return Value(s):  On Success - Returns an array containing the list of files and folders in the specified path
;                    On Failure - Returns an empty string "" if no files are found and sets @Error on errors
;                      @Error=1 Path Not Found
;                      @Error=2 Invalid $iFlag
; Author(s):        SolidSnake <MetalGearX91@Hotmail.com>
; Note(s):          The array returned is one-dimensional and is made up as follows:
;                   $array[0] = Number of Files\Folders returned
;                   $array[1] = 1st File\Folder
;                   $array[2] = 2nd File\Folder
;                   $array[3] = 3rd File\Folder
;                   $array[n] = nth File\Folder
;
;                   Special Thanks to Helge,Layer and /dev/null for help with the $iFlag update
;===============================================================================

and _RegList ():

;===============================================================================
;
; Description:      lists all entries in a specified key
; Syntax:           _RegList($sKey,$$iFlag=0)

; Parameter(s):       $sKey = Key to generate keylist for
;                       $iFlag=0(Default) Return both keys and values
;                       $iFlag=1 Return values only
;                       $iFlag=2 Return keys only
; Requirement(s):   None
; Return Value(s):  On Success - Returns an array containing the list of entries in the specified key
;                    On Failure - Returns an empty string "" if no entries are found and sets @Error on errors
;                            @Error=1 $sKey not found
;                            @Error=2 Invalid $iFlag
; Author(s):        SolidSnake <MetalGearX91@Hotmail.com>
; Note(s):            The array returned is one-dimensional and is made up as follows:
;                   $array[0] = Number of entries returned
;                   $array[1] = 1st entry
;                   $array[2] = 2nd entry
;                   $array[3] = 3rd entry
;                   $array[n] = nth entry
;===============================================================================

Enjoy :(

EDIT: Updated again. See post further below.

Edited by SolidSnake

HKTunes:Softpedia | GoogleCodeLyricToy:Softpedia | GoogleCodeRCTunes:Softpedia | GoogleCodeMichtaToolsProgrammer n. - An ingenious device that turns caffeine into code.

Share this post


Link to post
Share on other sites

Wow, that's nice.  Btw, the post above yours you have the _RegList() in the _FileList code box...

I know the perfect script to use this too!  Thanks!

<{POST_SNAPBACK}>

Thanks for the feedback. I fixed the post. :(

HKTunes:Softpedia | GoogleCodeLyricToy:Softpedia | GoogleCodeRCTunes:Softpedia | GoogleCodeMichtaToolsProgrammer n. - An ingenious device that turns caffeine into code.

Share this post


Link to post
Share on other sites

SolidSnake, (and anyone else interested)

I wrote similiar routines because I got tired of having to re-write a search routine (using FileFindFirst and FileFindNext) everytime I need to scan for files. I needed a little more powerful filtering (I can filter not only based on file/folder, but on any attributes, like hidden, archive, compressed, etc)

Have a look, I just posted them:

http://www.autoitscript.com/forum/index.php?showtopic=12152

Share this post


Link to post
Share on other sites

Updated. _FileList() now has wildcard ablilities.

CODE
;===============================================================================

;

; Description: lists all files and folders in a specified path (Similar to using Dir with the /B Switch)

; Syntax: _FileList($sPath, $sFilter = "*", $iFlag = 0)

; Parameter(s): $sPath = Path to generate filelist for

; $iFlag = determines weather to return file or folders or both

; $sFilter = The filter to use. Search the Autoit3 manual for the word "WildCards" For details

; $iFlag=0(Default) Return both files and folders

; $iFlag=1 Return files Only

; $iFlag=2 Return Folders Only

;

; Requirement(s): None

; Return Value(s): On Success - Returns an array containing the list of files and folders in the specified path

; On Failure - Returns an empty string "" if no files are found and sets @Error on errors

; @Error=1 Path not found or invalid

; @Error=2 Invalid $sFilter

; @Error=3 Invalid $iFlag

;

; Author(s): SolidSnake <MetalGearX91@Hotmail.com>

; Note(s): The array returned is one-dimensional and is made up as follows:

; $array[0] = Number of Files\Folders returned

; $array[1] = 1st File\Folder

; $array[2] = 2nd File\Folder

; $array[3] = 3rd File\Folder

; $array[n] = nth File\Folder

;

; Special Thanks to Helge and Layer for help with the $iFlag update

;===============================================================================

CODE
;===============================================================================

;

; Description: lists all entries in a specified key

; Syntax: _RegList($sKey,$$iFlag=0)

; Parameter(s): $sKey = Key to generate keylist for

; $iFlag=0(Default) Return both keys and values

; $iFlag=1 Return values Only

; $iFlag=2 Return keys Only

; Requirement(s): None

; Return Value(s): On Success - Returns an array containing the list of entries in the specified path

; On Failure - Returns an empty string "" if no entries are found and sets @Error on errors

; @Error=1 $sKey not found

; @Error=2 Invalid $iFlag

; Author(s): SolidSnake <MetalGearX91@Hotmail.com>

; Note(s): The array returned is one-dimensional and is made up as follows:

; $array[0] = Number of entries returned

; $array[1] = 1st entry

; $array[2] = 2nd entry

; $array[3] = 3rd entry

; $array[n] = nth entry

;===============================================================================

Edit:Updated headers to reflect my new email address.(Previous Downloads 188)

Edited by SolidSnake

HKTunes:Softpedia | GoogleCodeLyricToy:Softpedia | GoogleCodeRCTunes:Softpedia | GoogleCodeMichtaToolsProgrammer n. - An ingenious device that turns caffeine into code.

Share this post


Link to post
Share on other sites

I've written a program very similar to this one, except mine also searches for files inside folders found in the original folder (and files in folders in those folders, etc ) until every single file contained in the specified folder is accounted for. If anyone is interested, I can post details. Perhaps SolidSnake can just implement it into his code, although two arrays are involved. I suppose the information can be condensed into one array, but then it gets messy...

[EDIT]

Okay, so condensing it into one array wasn't as messy as I thought... just complicated to explain. Here goes:

$list[0][0] = number of folders and subfolders

$list[0][x] = x-th folder (a folder's number has no significance as to its location)

$list[x][0] = number of files in the folder $list[0][x]

$list[x][$y] = y-th file in folder $list[0][x]

The path stored in $list[0][x] is enough so that $dir & $list[0][x] will take you where you want. The code isn't documented well, but if anyone wants me to post it just ask.

Edited by HyperChao

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  

×
×
  • Create New...