Jump to content

File Finding Help


Go to solution Solved by jguinch,

Recommended Posts

Hello everyone,

I'm trying to make a script that tells me the location of a specified file, in this case lets say I'm searching for a file named "hamster.jpg"

So I want to search my entire computer for this file, so I'm using Melba's UDF (RecFileListToArray).

My problem is that I seem to only be able to find hamster.jpg if I do a search for ".jpg" (as seen in my code below). This also shows me all the other .jpg's I have on my computer, which is fine.

If I do a search for "hamster", I won't see any results. So it seems like I can only search file extensions and not the file name itself. Can anyone guide me on how to make my code search for file names as well?

Thank you,

Brian

#include <Array.au3> 
#include <RecFileListToArray.au3>

Example() 

Func Example()    
   Local $aArray, $aDrives = DriveGetDrive("FIXED") ;Makes sure all the drives are searched 
   If @error = 0 Then     
      For $i = 1 To $aDrives[0]         
         $aArray = _RecFileListToArray($aDrives[$i] & "", "*.jpg", 1, 1, 0, 2)          
         If @error Then            
            ContinueLoop        
         EndIf           
         For $j = 1 To $aArray[0]                
            ConsoleWrite($aArray[$j] & @CRLF)      
         Next   
      Next  
   EndIf 
   EndFunc   ;==>Example

So in the above code, if I change the "*.jpg" to "*hamster", I won't be able to find my hamster picture D:.

EDIT: I figured it out. Wow.. The only different thing I had to do in order to find the file name was write "hamster" on the left side of the * instead of the right side of the *

Edited by BlazerV60
Link to comment
Share on other sites

 

you can also use _FileListToArrayRec :

$aArray =_FileListToArrayRec ( $aDrives[$i] , "hamster.jpg" , 1 , 1 )

 

Thanks for your feedback,

The _FileListToArrayRec seems to be doing the same thing for me.

If I change the "hamster.jpg" parameter to "hamster" i can't find the picture, but if i change it to ".jpg" or "hamster.jpg" then I can find it. Is there a way to find it without having to enter in the extension?

Link to comment
Share on other sites

  • Moderators

BlazerV60,

 

Is there a way to find it without having to enter in the extension?

If a file has an extension you need to tell the function that it exists - by searching for simply "hamster" you will only get files of that name with no extension returned. ;)

Try this:

$aArray =_FileListToArrayRec($aDrives[$i], "hamster.*", 1, 1)
Now the function will return all files which are named hamster and have (or indeed do not have) an extension - which should include the one for which you are looking, but might well include others too. :)

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
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
 Share

×
×
  • Create New...