Jump to content
Sign in to follow this  
careca

Search for file in folder

Recommended Posts

careca

Hi, been searching around, and many asked a similar question, tried some solutions on my problem, but couldn't do it.

Problem is, got a path, and want the script to search for a file (prefs.js) in a folder, but one of the folders change it's name every now and then,

well, i do, and don't want to change the script every time, so i thought someone could help me out.

Path is: Drive\PROGS\01 INSTALL\**VariableFolderName**\Profiles\Profiles\default.default\prefs.js

FileFindFirstFile doesn't support wilcards on the path, only the file, meaning im stuck.

$aArray = DriveGetDrive('FIXED')
If @error Then
MsgBox(4096, "DriveGetDrive", "It appears an error occurred.")
Else
For $i = 1 To $aArray[0]
FileFindFirstFile($aArray[$i] & '\PROGS\01 INSTALL\'& * &'\Profiles\Profiles\default.default\prefs.js')
If FileExists($aArray[$i] & '\PROGS\01 INSTALL\'& * &'\Profiles\Profiles\default.default\prefs.js') Then
Else
MsgBox(0, "Error", "No files/directories matched the search pattern")
EndIf
Next
EndIf

Spoiler

Paster - Main function is to paste text, but has more functions. (No longer mantained, switched to String Trigger)

Renamer - Rename files and folders, remove portions of text from the filename etc.

GPO Tool - Export/Import Group policy settings.

MirrorDir - Synchronize/Backup/Mirror Folders

BeatsPlayer - Music player.

Params Tool - Right click an exe to see it's parameters or execute them.

String Trigger - Triggers pasting text or applications or internet links on specific strings.

Inconspicuous - Hide files in plain sight, not fully encrypted.

Regedit Control - Registry browsing history, quickly jump into any saved key.

Time4Shutdown - Write the time for shutdown in minutes.

Power Profiles Tool - Set a profile as active, delete, duplicate, export and import.

Firefox Profile Backup - Backup/restore previously saved profile.

Finished Task Shutdown - Shuts down pc when specified window/Wndl/process closes.

NetworkSpeedShutdown - Shuts down pc if download speed goes under "X" Kb/s.

IUIAutomation - Topic with framework and examples

Au3Record.exe

Share this post


Link to post
Share on other sites
Melba23

careca,

My RecFileListToArray UDF can help you here. Just search all the possible subfolders for the file like this: ;)

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

$aList = _RecFileListToArray("DrivePROGS01 INSTALL", "prefs.js", 1, 1, 0, 2)

If IsArray($aList) Then
    ; The array will contain all the "prefs.js" files found
    _ArrayDisplay($aList, "Found")
Else
    MsgBox(0, "Ooops", "File not found")
EndIf

I hope it helps. :)

M23


Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______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

 

Share this post


Link to post
Share on other sites
careca

Hello, thanks for the answer, this seems to send me in the right track, but i need to retrieve the path and it doesn't seem to work. like so:

#include 
#include 

$aArray = DriveGetDrive('FIXED')
For $i = 1 To $aArray[0]
$aList = _RecFileListToArray($aArray[$i]&"PROGS01 INSTALL", "prefs.js", 1, 1, 0, 2)
If IsArray($aList) Then
; The array will contain all the "prefs.js" files found
MsgBox(0, 'Info', "Found in: "& $aArray[$i])
;_ArrayDisplay($aList, "Found")
MsgBox(0, 'Info', $aList)
Else
MsgBox(0, "Error", "Not found in: " &$aArray[$i])
EndIf
Next

From $aList I get an empty msgbox, yes, it is supposed to send the data to an array, but then again, tried with an array and it still

didn't show the data in that array, here it only shows the drive letter, where it found the file, so it seems to work in part, what have i messed up?

#region ;**** Directives created by AutoIt3Wrapper_GUI ****
#AutoIt3Wrapper_Icon=ResourcesFox.ico
#AutoIt3Wrapper_Res_Icon_Add=ResourcesFox.ico
#AutoIt3Wrapper_Run_Tidy=y
#endregion ;**** Directives created by AutoIt3Wrapper_GUI ****
#include <Array.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <ButtonConstants.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
#include <ListViewConstants.au3>
#include <RecFileListToArray.au3>
Opt("GUIOnEventMode", 1)
Opt("TrayAutoPause", 0)
Opt("TrayIconDebug", 1)
Local $sPath
$Profile = StringReplace(@DesktopDir, 'Desktop', '')
$Form1 = GUICreate("Firefox Profile Backup", 380, 255, 190, 125)
GUISetOnEvent($GUI_EVENT_CLOSE, "Close")
$Backup = GUICtrlCreateButton("Backup", 10, 220, 75, 25)
GUICtrlSetOnEvent($Backup, "Backup")
$Restore = GUICtrlCreateButton("Restore", 120, 220, 75, 25)
GUICtrlSetOnEvent($Restore, "Restore")
$Exit = GUICtrlCreateButton("Exit", 230, 220, 75, 25)
GUICtrlSetOnEvent($Exit, "Close")

$cListView = GUICtrlCreateListView("Hdd|Path", 10, 80, 360, 130)
GUICtrlSendMsg(-1, $LVM_SETCOLUMNWIDTH, 0, 50)
GUICtrlSendMsg(-1, $LVM_SETCOLUMNWIDTH, 1, 300)

$Label1 = GUICtrlCreateLabel("Profile Folder", 10, 10, 130, 17)
$Label2 = GUICtrlCreateLabel("Backup/Restore Folder(s)", 10, 60, 130, 17)
$Input1 = GUICtrlCreateInput($Profile & 'AppDataRoamingMozillaFirefox', 10, 30, 360, 21)

$aArray = DriveGetDrive('FIXED')
If @error Then
MsgBox(4096, "DriveGetDrive", "It appears an error occurred.")
Else
For $i = 1 To $aArray[0]
$aList = _RecFileListToArray($aArray[$i] & "PROGS01 INSTALL", "prefs.js", 1, 1, 0, 2)
If IsArray($aList) Then
GUICtrlCreateListViewItem(StringUpper($aArray[$i]) & '|' & $aList, $cListView)
EndIf
Next
EndIf

GUISetState(@SW_SHOW)

Spoiler

Paster - Main function is to paste text, but has more functions. (No longer mantained, switched to String Trigger)

Renamer - Rename files and folders, remove portions of text from the filename etc.

GPO Tool - Export/Import Group policy settings.

MirrorDir - Synchronize/Backup/Mirror Folders

BeatsPlayer - Music player.

Params Tool - Right click an exe to see it's parameters or execute them.

String Trigger - Triggers pasting text or applications or internet links on specific strings.

Inconspicuous - Hide files in plain sight, not fully encrypted.

Regedit Control - Registry browsing history, quickly jump into any saved key.

Time4Shutdown - Write the time for shutdown in minutes.

Power Profiles Tool - Set a profile as active, delete, duplicate, export and import.

Firefox Profile Backup - Backup/restore previously saved profile.

Finished Task Shutdown - Shuts down pc when specified window/Wndl/process closes.

NetworkSpeedShutdown - Shuts down pc if download speed goes under "X" Kb/s.

IUIAutomation - Topic with framework and examples

Au3Record.exe

Share this post


Link to post
Share on other sites
Melba23

careca,

what have i messed up?

This:

;_ArrayDisplay($aList, "Found")
MsgBox(0, 'Info', $aList)

You cannot display an array in a MsgBox - that is why I used _ArrayDisplay. ;)

Try using this:

MsgBox(0, 'Info', $aList[1])

Now you display the first file found - which should be the one you are looking for. :)

M23


Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______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

 

Share this post


Link to post
Share on other sites
careca

Now you display the first file found - which should be the one you are looking for. :)

M23, ok, thanks, that covers the msgbox, any hope for the second case? To display in my ListViewItem?


Spoiler

Paster - Main function is to paste text, but has more functions. (No longer mantained, switched to String Trigger)

Renamer - Rename files and folders, remove portions of text from the filename etc.

GPO Tool - Export/Import Group policy settings.

MirrorDir - Synchronize/Backup/Mirror Folders

BeatsPlayer - Music player.

Params Tool - Right click an exe to see it's parameters or execute them.

String Trigger - Triggers pasting text or applications or internet links on specific strings.

Inconspicuous - Hide files in plain sight, not fully encrypted.

Regedit Control - Registry browsing history, quickly jump into any saved key.

Time4Shutdown - Write the time for shutdown in minutes.

Power Profiles Tool - Set a profile as active, delete, duplicate, export and import.

Firefox Profile Backup - Backup/restore previously saved profile.

Finished Task Shutdown - Shuts down pc when specified window/Wndl/process closes.

NetworkSpeedShutdown - Shuts down pc if download speed goes under "X" Kb/s.

IUIAutomation - Topic with framework and examples

Au3Record.exe

Share this post


Link to post
Share on other sites
Melba23

careca,

Now you know how to get the string I would have thought you could have worked that out for yourself. ;)

Try this;

GUICtrlCreateListViewItem(StringUpper($aArray[$i]) & "|" & StringTrimLeft($aList[1], 3), $cListView)

We need to trim the path to get rid of the leading drive letter and the ":". :)

M23


Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______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

 

Share this post


Link to post
Share on other sites
careca

Im sorry, failed to explain correctly the problem, what i need is to display all paths for the file that were found,

in ListViewItem, not just the first found, because i have more than one hdd, so i got to check if there are those files in other hdd's,

tried to use your function as an array, and that doesn't seem to work.

Can your function be used as an array? as im using DriveGetDrive?

Hope i expressed myself right.

Sorry for the mess up.

Example of what im trying

$aArray = DriveGetDrive('FIXED')
If @error Then
MsgBox(4096, "DriveGetDrive", "It appears an error occurred.")
Else
For $i = 1 To $aArray[0]
For $u = 1 To $aList[0]
$aList = _RecFileListToArray($aArray[$i] & "PROGS01 INSTALL", "prefs.js", 1, 1, 0, 2)
GUICtrlCreateListViewItem(StringUpper($aArray[$i])& '|' & StringTrimLeft($aList[$u], 3), $cListView)
Next
Next
EndIf

EDIT: i messed up bad, just noticed, fixing...

EDIT2: nope, still messed up

Edited by careca

Spoiler

Paster - Main function is to paste text, but has more functions. (No longer mantained, switched to String Trigger)

Renamer - Rename files and folders, remove portions of text from the filename etc.

GPO Tool - Export/Import Group policy settings.

MirrorDir - Synchronize/Backup/Mirror Folders

BeatsPlayer - Music player.

Params Tool - Right click an exe to see it's parameters or execute them.

String Trigger - Triggers pasting text or applications or internet links on specific strings.

Inconspicuous - Hide files in plain sight, not fully encrypted.

Regedit Control - Registry browsing history, quickly jump into any saved key.

Time4Shutdown - Write the time for shutdown in minutes.

Power Profiles Tool - Set a profile as active, delete, duplicate, export and import.

Firefox Profile Backup - Backup/restore previously saved profile.

Finished Task Shutdown - Shuts down pc when specified window/Wndl/process closes.

NetworkSpeedShutdown - Shuts down pc if download speed goes under "X" Kb/s.

IUIAutomation - Topic with framework and examples

Au3Record.exe

Share this post


Link to post
Share on other sites
Melba23

careca,

Im sorry, failed to explain correctly the problem

A good explanation always helps. ;)

This should run through all the drives and look for all instances of the file:

$aArray = DriveGetDrive('FIXED')
If @error Then
    MsgBox(4096, "DriveGetDrive", "It appears an error occurred.")
Else
    For $i = 1 To $aArray[0]
        $aList = _RecFileListToArray($aArray[$i] & "PROGS01 INSTALL", "prefs.js", 1, 1, 0, 2)
        If IsArray($aList) Then
            For $j = 1 To $aList[0]
                GUICtrlCreateListViewItem(StringUpper($aArray[$i]) & "|" & StringTrimLeft($aList[$j], 3), $cListView)
            Next
        EndIf
    Next
EndIf

It works for me when I test it - how about you? :)

M23


Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______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

 

Share this post


Link to post
Share on other sites
careca

It works for me when I test it - how about you? :)

Works perfect! Thank you Sir.

I was about to get there, but there was this error, and after a long time i noticed there was a ) missing, and that gave me lots of errors, endif missing, next missing etc. LOL

Greetings,

careca.


Spoiler

Paster - Main function is to paste text, but has more functions. (No longer mantained, switched to String Trigger)

Renamer - Rename files and folders, remove portions of text from the filename etc.

GPO Tool - Export/Import Group policy settings.

MirrorDir - Synchronize/Backup/Mirror Folders

BeatsPlayer - Music player.

Params Tool - Right click an exe to see it's parameters or execute them.

String Trigger - Triggers pasting text or applications or internet links on specific strings.

Inconspicuous - Hide files in plain sight, not fully encrypted.

Regedit Control - Registry browsing history, quickly jump into any saved key.

Time4Shutdown - Write the time for shutdown in minutes.

Power Profiles Tool - Set a profile as active, delete, duplicate, export and import.

Firefox Profile Backup - Backup/restore previously saved profile.

Finished Task Shutdown - Shuts down pc when specified window/Wndl/process closes.

NetworkSpeedShutdown - Shuts down pc if download speed goes under "X" Kb/s.

IUIAutomation - Topic with framework and examples

Au3Record.exe

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  

×