Jump to content

Help need for Selection or Drag and Drop for Folders & files. - (Moved)


Go to solution Solved by rakibdepu,

Recommended Posts

Hi Everyone,

I need help. I have been searching help files and browsing forums about this for the past 7 days.

I am trying to create gui for Images Convert to PDF and ZIP in the basis of Drag and Drop or Select multi Files or Select Folder. I am using Trong's exmple "dragging and dropping folder/files into the GUI".

But I'm stuck on the drag and drop folder and select folder part. When I select multi files it processes, but when I select folders, it processes the folder and not the files inside the folder.

It's either I don't understand, or it's going over my head.

Here is part of my script.

If IsArray($aCmdLine) And $aCmdLine[0] > 0 Then
    _GUI_OnProgress()
    For $i = 1 To $aCmdLine[0]
        _Main_Processing($aCmdLine[$i], $i, $aCmdLine[0])
    Next
    _GUI_OnStandby()
    GUICtrlSetData($idLabel_Status, "Everything is done!")
    Sleep(3000) ; Pause 4s
    Exit
Else
    While 1
        ;_GUI_SwitchMsg()
        Switch $guiMsg
            Case $idButton_SelectFolder
                _GUI_OnProgress()
                ; Display an open dialog to select a folder.
                Local $zFolderIN = FileSelectFolder("Select a folder", "", Default, Default, $hGUI)
                If Not @error Then
                    _Main_Processing($zFolderIN, 1, 1)
                EndIf
                _GUI_OnStandby()
            Case $idButton_BrowseFiles
                _GUI_OnProgress()
                ; Display an open dialog to select files.
                Local $zListFileIN, $zFileIN = FileOpenDialog("Select Files", @WorkingDir, "All File (*)", $FD_FILEMUSTEXIST + $FD_MULTISELECT, "", $hGUI) ;1+4
                If Not @error Then
                    If StringInStr($zFileIN, "|") Then
                        $zListFileIN = StringSplit($zFileIN, "|")
                        If IsArray($zListFileIN) Then
                            For $i = 2 To $zListFileIN[0]
                                _Main_Processing($zListFileIN[$i], $i - 1, $zListFileIN[0] - 1)
                            Next
                        EndIf
                    Else
                        _Main_Processing($zFileIN, 1, 1)
                    EndIf
                EndIf
                _GUI_OnStandby()
            Case $GUI_EVENT_DROPPED
                _GUI_OnProgress()
                If $__aDropFiles[0] > 0 Then
                    For $i = 1 To $__aDropFiles[0]
                        _Main_Processing($__aDropFiles[$i], $i, $__aDropFiles[0])
                    Next
                EndIf
                _GUI_OnStandby()
        EndSwitch
        ;_TRAY_SwitchMsg()
    WEnd
EndIf
; * -----:|
Func _Main_Processing($sFilePath, $nCurrent = 0, $nTotal = 0)
    ;_GUI_SwitchMsg()
    ;_TRAY_SwitchMsg()
    $sPercent = Round(($nCurrent / $nTotal) * 100, 2)
    GUICtrlSetData($idProgress_Total, $sPercent)
    ConsoleWrite("Total Progress: " & $sPercent & "%" & @CRLF)
    GUICtrlSetData($idProgress_Current, 0)
    GUICtrlSetData($idLabel_Titles, "Total selected " & $nTotal & " files. (" & $sPercent & "%)")

    Local $sDrive, $sParentDir, $sCurrentDir, $sFileNameNoExt, $sExtension, $sFileName, $sPathParentDir, $sPathCurrentDir, $sPathFileNameNoExt
    Local $aPathSplit = _SplitPath($sFilePath, $sDrive, $sParentDir, $sCurrentDir, $sFileNameNoExt, $sExtension, $sFileName, $sPathParentDir, $sPathCurrentDir, $sPathFileNameNoExt)
    ;Local $sCurrentDirPath= $sDrive&$sCurrentDir;StringRegExpReplace($aPathSplit, '\\[^\\]*$', '')
    ;Local $sCurrentDirName =StringRegExpReplace(_PathRemoveBackslash($sCurrentDirPath), '.*\\', '')
    ConsoleWrite("[1] Drive: " & $sDrive & @CRLF)
    ConsoleWrite("[2] ParentDir: " & $sParentDir & @CRLF)
    ConsoleWrite("[3] CurrentDir: " & $sCurrentDir & @CRLF)
    ConsoleWrite("[4] FileName NoExt: " & $sFileNameNoExt & @CRLF)
    ConsoleWrite("[5] Extension: " & $sExtension & @CRLF)
    ConsoleWrite("[6] FileName: " & $sFileName & @CRLF)
    ConsoleWrite("[7] PathParentDir: " & $sPathParentDir & @CRLF)
    ConsoleWrite("[8] PathCurrentDir: " & $sPathCurrentDir & @CRLF)
    ConsoleWrite("[9] PathFileName NoExt: " & $sPathFileNameNoExt & @CRLF)
    ConsoleWrite("Total selected " & $nTotal & " files. (" & $sPercent & "%)" & @CRLF)
    If _IsFile($sFilePath) Then
        ConsoleWrite("Processing now: (" & $nCurrent & ") " & $sFileName & @CRLF)
        GUICtrlSetData($idLabel_Task, "Processing now: (" & $nCurrent & ") " & $sFileName)
        ; Your file handler is here!
    Else
        If (FileExists($sPathCurrentDir)) Then ; Is Root Drive
            ; Your drive handler is here!
            ConsoleWrite("Processing directory: " & _PathRemove_Backslash($sPathCurrentDir) & @CRLF)
            GUICtrlSetData($idLabel_Task, "Currently Folder: " & _PathRemove_Backslash($sCurrentDir))
        Else
            ; Your directory handler is here!
            ConsoleWrite("Processing drive: " & $sDrive & @CRLF)
            GUICtrlSetData($idLabel_Task, "Currently Drive: " & $sDrive)
        EndIf
    EndIf

    ; Code section for GUI testing only
    GUICtrlSetData($idProgress_Current, 40)
    Sleep(100) ; test gui
    GUICtrlSetData($idProgress_Current, 60)
    Sleep(100) ; test gui
    GUICtrlSetData($idProgress_Current, 80)
    Sleep(100) ; test gui
    GUICtrlSetData($idProgress_Current, 100)
    GUICtrlSetData($idLabel_Status, "Everything is done!")
    Sleep(600) ; test gui
    ; End code test GUI

EndFunc   ;==>_Main_Processing

Full script and others extra files in zip attachment.

 

Images to PDF & ZIP.zip

Edited by rakibdepu
Update Attachment
Link to comment
Share on other sites

  • Developers

Moved to the appropriate AutoIt General Help and Support forum, as the AutoIt Example Scripts forum very clearly states:

Quote

Share your cool AutoIt scripts, UDFs and applications with others.


Do not post general support questions here, instead use the AutoIt Help and Support forums.

Moderation Team

SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource   Forum etiquette  Forum Rules 
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Link to comment
Share on other sites

At first glance, your Case $GUI_EVENT_DROPPED passes name of folders instead of name of files.  You would need to use _FileListToArray to get all files from each folder then pass file name to your function.

Link to comment
Share on other sites

Well, it depends how you want to work it.  But it could be easier to add the code into _Main_Processing function where it says ; Your directory handler is here!

Look into help file for an example of how to use _FileListToArray.  Then use a For...Next loop to handle each file individually.

 

Link to comment
Share on other sites

As you said, it worked but some problems remained.

Func _Main_Processing($sFilePath, $nCurrent = 0, $nTotal = 0)
    ;_GUI_SwitchMsg()
    ;_TRAY_SwitchMsg()
    $sPercent = Round(($nCurrent / $nTotal) * 100, 2)
    GUICtrlSetData($idProgress_Total, $sPercent)
    ConsoleWrite("Total Progress: " & $sPercent & "%" & @CRLF)
    GUICtrlSetData($idProgress_Current, 0)
    GUICtrlSetData($idLabel_Titles, "Total selected " & $nTotal & " files. (" & $sPercent & "%)")

    Local $sDrive, $sParentDir, $sCurrentDir, $sFileNameNoExt, $sExtension, $sFileName, $sPathParentDir, $sPathCurrentDir, $sPathFileNameNoExt
    Local $aPathSplit = _SplitPath($sFilePath, $sDrive, $sParentDir, $sCurrentDir, $sFileNameNoExt, $sExtension, $sFileName, $sPathParentDir, $sPathCurrentDir, $sPathFileNameNoExt)
    ;Local $sCurrentDirPath= $sDrive&$sCurrentDir;StringRegExpReplace($aPathSplit, '\\[^\\]*$', '')
    ;Local $sCurrentDirName =StringRegExpReplace(_PathRemoveBackslash($sCurrentDirPath), '.*\\', '')
    ConsoleWrite("[1] Drive: " & $sDrive & @CRLF)
    ConsoleWrite("[2] ParentDir: " & $sParentDir & @CRLF)
    ConsoleWrite("[3] CurrentDir: " & $sCurrentDir & @CRLF)
    ConsoleWrite("[4] FileName NoExt: " & $sFileNameNoExt & @CRLF)
    ConsoleWrite("[5] Extension: " & $sExtension & @CRLF)
    ConsoleWrite("[6] FileName: " & $sFileName & @CRLF)
    ConsoleWrite("[7] PathParentDir: " & $sPathParentDir & @CRLF)
    ConsoleWrite("[8] PathCurrentDir: " & $sPathCurrentDir & @CRLF)
    ConsoleWrite("[9] PathFileName NoExt: " & $sPathFileNameNoExt & @CRLF)
    ConsoleWrite("Total selected " & $nTotal & " files. (" & $sPercent & "%)" & @CRLF)
    If _IsFile($sFilePath) Then
        ConsoleWrite("Processing now: (" & $nCurrent & ") " & $sFileName & @CRLF)
        GUICtrlSetData($idLabel_Task, "Processing now: (" & $nCurrent & ") " & $sFileName)
        ; Your file handler is here!
    Else
        If IsDir($sFilePath) Then
            $aList = _FileListToArray($__aDropFiles[$i], '*', 1)
            For $f = 1 To $aList[0]
            ConsoleWrite("Processing now: (" & $nCurrent & ") " & $sFileName & @CRLF)
            GUICtrlSetData($idLabel_Task, "Processing now: (" & $nCurrent & ") " & $sFileName)
            Next
        EndIf
    EndIf

    ; Code section for GUI testing only
    GUICtrlSetData($idProgress_Current, 40)
    Sleep(100) ; test gui
    GUICtrlSetData($idProgress_Current, 60)
    Sleep(100) ; test gui
    GUICtrlSetData($idProgress_Current, 80)
    Sleep(100) ; test gui
    GUICtrlSetData($idProgress_Current, 100)
    GUICtrlSetData($idLabel_Status, "Everything is done!")
    Sleep(600) ; test gui
    ; End code test GUI

EndFunc   ;==>_Main_Processing

Here is output:
+>Setting Hotkeys...--> Press Ctrl+Alt+Break to Restart or Ctrl+BREAK to Stop.
Total Progress: 50%
[1] Drive: C:\
[2] ParentDir: \Users\*****\Desktop\Images to PDF & ZIP\
[3] CurrentDir: New folder\
[4] FileName NoExt: New Text Document (1)
[5] Extension: .txt
[6] FileName: New Text Document (1).txt
[7] PathParentDir: C:\Users\*****\Desktop\Images to PDF & ZIP\
[8] PathCurrentDir: C:\Users\*****\Desktop\Images to PDF & ZIP\New folder\
[9] PathFileName NoExt: C:\Users\*****\Desktop\Images to PDF & ZIP\New folder\New Text Document (1)
Total selected 2 files. (50%)
Processing now: (1) New Text Document (1).txt
Total Progress: 100%
[1] Drive: C:\
[2] ParentDir: \Users\*****\Desktop\Images to PDF & ZIP\New folder\
[3] CurrentDir: New folder\
[4] FileName NoExt:                                                                                                                                   <<<<<<<<<<<<<<<<<<<
[5] Extension:                                                                                                                                              <<<<<<<<<<<<<<<<<<<
[6] FileName:                                                                                                                                              <<<<<<<<<<<<<<<<<<<
[7] PathParentDir: C:\Users\*****\Desktop\Images to PDF & ZIP\New folder\
[8] PathCurrentDir: C:\Users\*****\Desktop\Images to PDF & ZIP\New folder\New folder\
[9] PathFileName NoExt: C:\Users\*****\Desktop\Images to PDF & ZIP\New folder\New folder\
Total selected 2 files. (100%)
Processing now: (2)                                                                                                                                   <<<<<<<<<<<<<<<<<<<
Processing now: (2)                                                                                                                                   <<<<<<<<<<<<<<<<<<<
Processing now: (2)                                                                                                                                   <<<<<<<<<<<<<<<<<<< 
+>13:51:10 AutoIt3.exe ended.rc:0

 

Please guide me.

Edited by rakibdepu
Link to comment
Share on other sites

Try this instead :

If IsDir($sFilePath) Then
            $aList = _FileListToArray($sFilePath, '*', $FLTA_FILES)
            if not @error then
                For $i = 1 To $aList[0]
                    ConsoleWrite("Processing now: (" & $i & ") " & $aList[$i] & @CRLF)
                    GUICtrlSetData($idLabel_Task, "Processing now: (" & $i & ") " & $aList[$i])
                Next
            else
              ConsoleWrite("No file found in directory " & $sFilePath
            endif
        EndIf

Untested.  But you should get the idea.

Link to comment
Share on other sites

Thanks, it works the way it's supposed to, but not the way I wanted it to.

The task I will be using it for requires separate single file output.
The input file can be in different locations from different folders and multi selections.

That's why I choose this GUI. It features drag and drop, multi file selection and folder selection.

Suppose, I am searching images with prefix "_P-" in 'Everything Search' window. Then results showed 5 files, 2 in desktop, 1 in downloads and others 2 in D:\New Folder. Then I drag and drop those files in GUI. Each images in its source directory will be converted to pdf and compressed to zip files.

Actually I am very poor in speaking English, hence using google translator.

Link to comment
Share on other sites

IMHO -- You are having issues because you are not mastering AutoIt very well.  And maybe you are trying to fit your needs to a pre-written script you found.  You will need to think how you want to proceed and create/adapt your own script.

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...