Jump to content

Help! Read Directory, List Folders, Select Folder, Create|Delete Folder!


Go to solution Solved by pixelsearch,

Recommended Posts

Posted (edited)

Good day one-and-all!

I really, really, really...could use some assistance here is getting a start on the above...

1) I need to read a directory of existing folders
2) I then need to list those read folders
3) I then need to be able to select a single folder from that listing
4) After I have selected that folder, I then need to perform an "action" on that previously selected folder,[copy data to, create, and|or delete]

Any assistance in this "project" would be greatly, greatly, greatly appreciated!

Note: See here for a sampling...

Edited by mr-es335
  • mr-es335 changed the title to Help! Read Directory, List Folders, Select Folder, Create|Delete Folder!
Posted

How about this:

  • Open the AutoIt help file
  • Select "Content"
  • Click on "Function Reference"
  • Click on "File, Directory and Disk Management"

or

  • Open the AutoIt help file
  • Select "Content"
  • Click on "User Defined Functions Reference"
  • Click on "File Management"

There you'll find all you need.

If you have problems with a function we will be happy to help. In this case provide as much information as possible.

The main goal of the forum is to help coders solve their problems not to spoon feed them with solutions.

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2024-07-28 - Version 1.6.3.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

Posted (edited)

Jos,
Thank you for the reply...appreciated!

You noted, "Assistance with what exactly ?"

In short, to backup predetermined source data to either a1) a previously determined backup location, or b1) to a new backup location.

Well, in the following excerpt, the "ListBackupFolders()" function lists the folders from a per-determined location. This is fine!

However, I would prefer to be able to a2) select from the listing, employing that selection as the backup path [thus, (a1) above], or b2) to create a new destination backup path [thus (b1) above].

I do hope that this all makes sense?

Here is the excerpt:

; -----------------------------------------------
#include <Array.au3>
#include <AutoItConstants.au3>
#include <File.au3>
#include <FileConstants.au3>
#include <GUIConstantsEx.au3>
#include <MsgBoxConstants.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
; -----------------------------------------------
Opt("MustDeclareVars", 1)
; -----------------------------------------------
ListBackupFolders()
; -----------------------------------------------
Func ListBackupFolders()
    Local $sBackupFolderPath = "E:\Text\Native Instruments\Guitar Rig 5\Presets"
    ; -----------------
    Local $ArrayFolders = _FileListToArrayRec($sBackupFolderPath, "*", $FLTAR_FOLDERS)
    ; -----------------
    Local $verify = MsgBox(68, "Notice!", "List the backup folders?!")
    ; -----------------------------------------------
    While True
        Select
            Case $verify = 6
                _ArrayDisplay($ArrayFolders, "Folder Listing", Default, 64)
            Case $verify = 7
                MsgBox($MB_ICONINFORMATION, "Notice!", "The operation was cancelled. Exiting!", 1)
        EndSelect
        Return
    WEnd
    ; -----------------------------------------------
    EnterSetName()
EndFunc   ;==>ListBackupFolders
; -----------------------------------------------
Func EnterSetName()
    Local $sPrompt = "Create A New Backup Folder!"
    Local $sMessage = "Enter The Backup folder name..."
    Local $sSelectedSessionPath = InputBox($sPrompt, $sMessage, "", " M", 275, 130)
    ; -----------------
    Local $SplitPath = StringSplit($sSelectedSessionPath, "\")
    ; -----------------------------------------------
    If $SplitPath[0] <= 5 Or $SplitPath[0] >= 7 Then
        MsgBox($MB_TOPMOST, "Error!", "The Entered Path Name Is Incorrect! Please Try Again...")
        EnterSetName()
    Else
        CreateFolder($sSelectedSessionPath)
    EndIf
EndFunc   ;==>EnterSetName
; -----------------------------------------------
Func CreateFolder($sSelectedSessionPath)
    Local $sSrcWavDataPath = "E:\Text\Native Instruments\Guitar Rig 5\Presets"
    ; -----------------------------------------------
    DirCreate($sSelectedSessionPath)
    ; -----------------------------------------------
    Local $sBackupPath = $sSelectedSessionPath
    BackupSoundData($sBackupPath)
EndFunc   ;==>CreateFolder
; -----------------------------------------------
Func BackupSoundData($sBackupPath)
    Local $iStart = 2, $iEnd = 1
    Local $sSrcPath[$iStart] = [$iEnd]
    $sSrcPath[1] = "E:\Text\Native Instruments\Guitar Rig 5\Sounds\*.ngrr"
    ; -----------------
    Local $sDstPath[$iStart] = [$iEnd]
    $sDstPath[1] = $sBackupPath
    ; -----------------
    Local $sMessage = "Backup All Sound File data..." & @CRLF & @CRLF, $iWidth = 450, $iHeight = 135
    Local $iOpt = 5, $sFontName = "FuturaBQ-DemiBold", $iFontSize = 14
    ; -----------------------------------------------
    SplashTextOn("", $sMessage, $iWidth, $iHeight, -1, -1, $iOpt, $sFontName, $iFontSize)
    ; -----------------------------------------------
    For $i = 1 To $sSrcPath[0]
        Local $sResult = FileCopy($sSrcPath[$i], $sDstPath[$i], $FC_OVERWRITE)
        ; -----------------------------------------------
        Switch $sResult
            Case 0
                $sResult = "The Sound  file data DOES NOT exist!"
            Case 1
                $sResult = "The Sound  file data WAS backed-up successfully!"
        EndSwitch
        ; -----------------------------------------------
        $sMessage &= $sResult & @CRLF
    Next
    ; -----------------------------------------------
    $sMessage &= @CRLF & "Backup All Sound  File data is now completed..." & @CRLF
    ; -----------------------------------------------
    SplashTextOn("", $sMessage, $iWidth, $iHeight, -1, -1, $iOpt, $sFontName, $iFontSize)
    Sleep(2000)
    SplashOff()
EndFunc   ;==>BackupSoundData
; -----------------------------------------------

As always...any assistance in this matter would be greatly appreciated!

Edited by mr-es335
  • Solution
Posted

Why not simply use the native FileSelectFolder() function to achieve your goal ?
Just select any existing folder you like, or create a new folder where you like, all this with a single line code.

The full path of the chosen (or created) folder will be returned by the function, unless you cancel the function window.

"I think you are searching a bug where there is no bug... don't listen to bad advice."

Posted (edited)

pixelsearch,

Thanks for the "tip"!! How is this [...greatly simplified...]:

; -----------------------------------------------
#include <File.au3>
; -----------------------------------------------
Opt("MustDeclareVars", 1)
; -----------------------------------------------
BrowseForFolder()
; -----------------------------------------------
Func BrowseForFolder()
    Local $sSelectedFolderPath = FileSelectFolder("Select an existing folder, or create a new folder.", "E:\Text\Native Instruments\Guitar Rig 5\Presets")
    Local $iFileExists = FileExists($sSelectedFolderPath)
    ; -----------------------------------------------
    If $iFileExists Then
        BackupSoundData($sSelectedFolderPath)
    EndIf
EndFunc   ;==>BrowseForFolder
; -----------------------------------------------
Func BackupSoundData($sSelectedFolderPath)
    Local $sSrcPath = "E:\Text\Native Instruments\Guitar Rig 5\Sounds\*.ngrr"
    ; -----------------
    Local $sDstPath = $sSelectedFolderPath
    ; -----------------
    FileCopy($sSrcPath, $sDstPath, $FC_OVERWRITE)
EndFunc   ;==>BackupSoundData
; -----------------------------------------------

Question, "What do I do if the "Select Folder" option is selected - with no folder previously selected?"

Edited by mr-es335
Posted
42 minutes ago, mr-es335 said:

Question, "What do I do if the "Select Folder" option is selected - with no folder previously selected?"

Does the presence of a 4th parameter in the function answers your new question, for example :

Local $sInitialFolderPath = "E:\Text\Native Instruments\Guitar Rig 5\Presets"
Local $sSelectedFolderPath = FileSelectFolder("Select an existing folder, or create a new folder.", _
    $sInitialFolderPath, 0, $sInitialFolderPath)

If not, I hope a reader of this thread will have a correct answer :)

"I think you are searching a bug where there is no bug... don't listen to bad advice."

Posted (edited)

pixelsearch,

You stated, "Does the presence of a 4th parameter in the function answers your new question?"
• Firstly, I do observe that, "Using a nonexistent root dir will also cause the Desktop folder to be used."
• The employment of the 4th parameter does redirect the path from the Desktop to the redirected path.

Just to note:

Func AboutMe()
    MsgBox(64, "About!", "Guitar Rig 5 Development Menu" & @CRLF & _
            "" & @CRLF & "Version 2.0" & @CRLF & _
            "" & @CRLF & _
            "Copy Right© 2025 Dell Krauchi" & @CRLF & _
            "" & @CRLF & _
            "Original concept by Dell Krauchi" & @CRLF & _
            "Developed specifically for use with the Live_Rig..." & @CRLF & _
            "...and Gutar Rig 5!" & @CRLF & _
            "" & @CRLF & _
            "Many, many, many thanks to pixelsearch!" & @CRLF & _
            "His fortitude and assistance was invaluable..." & @CRLF & _
            "...to the completion of this project!" & @CRLF & _
            "" & @CRLF & _
            "April 19th, 2025" & @CRLF & _
            "")
EndFunc   ;==>AboutMe
; -----------------------------------------------

Thank you!

Edited by mr-es335

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
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...