Jump to content

Need a FileSelectFolder function that displays the files


JibsMan
 Share

Go to solution Solved by Radiance,

Recommended Posts

The FileSelectFolder function does not appear to display the files in the selected directory. I found many different examples of other FileSelectFolder functions, some by Melba23, which are way cool but not quite what I need.

If the standard FileSelectFolder just displayed the files in the currently selected directory I could move on.  Problem is the user might not know where the files they want to process are located.

A possible solution is to display directories with files and either allow the user to select all the .bat files to copy to an array or just automatically copy all .bat files into the array.

Some of you like to know the "why" of things: This entire exercise is to copy / rename a single file.txt to the same name as the .bat filenames in the selected dir.

File1.bat

File2.bat

File3.bat

Copy TestFile.txt to:

File1.txt

File2.txt

File3.txt

so there are both .bat and .txt files for each .bat filename.

The user must decide which directory they want to process, and needs to see what's in the directory to select it.

Doesn't matter if it's the standard Explorer window or a custom explorer. If you know of one I could try I'd certainly appreciate it!

Thanks in advance!

Jibs :bike:

Link to comment
Share on other sites

How about something like this?

 

#include <FileConstants.au3>
#include <StringConstants.au3>

$batchfiles = FileOpenDialog("test", "c:\tmp", "Batch files (*.bat)", $FD_MULTISELECT)

If @error Then
    MsgBox(16, "Failed", "File selection failed, error: " & @error)
    Exit
EndIf

ConsoleWrite("Chosen batchfiles: " & $batchfiles & @CRLF)

If StringInStr($batchfiles, "|") Then
    ; contains a pipe, means multiple batchfiles were selected
    $chosenArray = StringSplit($batchfiles, "|")
    ; Say we have "c:\tmp|x.bat|y.bat", the array elements after split will be:
    ; [0]: 3
    ; [1]: "c:\tmp"
    ; [2]: "x.bat"
    ; [3]: "y.bat"
    $folder = $chosenArray[1]
    for $i = 2 to $chosenArray[0]
        $file = $chosenArray[$i]
        $filepath = $folder & "\" & $file
        ConsoleWrite("Doing magic on file: " & $filepath & @CRLF)
    Next
Else
    ConsoleWrite("Doing magic on file: " & $batchfiles & @CRLF)
EndIf

Roses are FF0000, violets are 0000FF... All my base are belong to you.

Link to comment
Share on other sites

How do I mark both answers as "Solved"?!  :sorcerer:  I'll mark Radiance since SadBunny has solved so many questions already, and Radiance was first!

Thank You! Missed this function completely!  And Thank You to SadBunny for the code :bye:

Jibs  :bike:

 

No problem friend, we don't do it for the points score here, at least I don't. As we say in Dutch, "small effort, big pleasure".

Roses are FF0000, violets are 0000FF... All my base are belong to you.

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

  • Recently Browsing   0 members

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