Jump to content

Drag and Drop many files to a compiled script


 Share

Recommended Posts

@Tosyk what follows looks simple, without the use of a GUI and a droppable zone. It's based on jchd's $CF_HDROP
1) Select all the files you need
2) Copy their paths & names to the clipboard (Ctrl+C)
3) Double click on your exe icon (after you added these lines at the very beginning of the script and recompiled it)

#include <Array.au3>
#include <Clipboard.au3>
#include <WinAPISysWin.au3>

_ClipBoard_Open(0)
Local $aSelected = _WinAPI_DragQueryFileEx(_ClipBoard_GetDataEx($CF_HDROP), 1) ; 1 = files only
_ClipBoard_Empty()
_ClipBoard_Close()

If Not IsArray($aSelected) Then Exit MsgBox(262144, "Nothing to process", "No files selected"); $MB_TOPMOST = 262144
_ArrayDisplay($aSelected, $aSelected[0] & " files selected", "1:") ; "1:" to mask element 0 (contains number of files selected)
; process your files here

This seems a very simple way to process any number of selected files, bypassing Windows limitation, without adding a GUI or a droppable zone to your script.

Note: to make it safer, in case you selected wrong files and don't want them processed at all, I suggest you display their path & names not with _ArrayDisplay, but with _DebugArrayDisplay, at least you'll have a native additional button "Exit Script" found in _DebugArrayDisplay, allowing you to immediately exit the script if you mistakely selected a bunch of wrong files, very useful at times.

And if you don't want _ArrayDisplay or _DebugArrayDisplay at all, then you can bypass them, blindly processing the selection you made. Good luck :)
Link to comment
Share on other sites

a different approach, with a Jobs_Folder, where you can throw the shortcuts of  files

Dragging files with Right button and choose 'Create shortcuts here'
or   hold ctrl + shift while dragging

 

; https://www.autoitscript.com/forum/topic/210647-drag-and-drop-many-files-to-a-compiled-script/page/2/#comment-1522542
;----------------------------------------------------------------------------------------
; Title...........: Jobs_Handler.au3
; AutoIt Version..: 3.3.16.1
;----------------------------------------------------------------------------------------
#AutoIt3Wrapper_Au3Check_Parameters=-d -w 1 -w 2 -w 3 -w 4 -w 5 -w 6 -w 7
#include <File.au3>

Global $sJobsDir = @ScriptDir & "\Jobs_Folder"
Global $JobsDir_hWnd, $iTimeOut = 30

;if not exist Jobs_Folder then make it.
If Not FileExists($sJobsDir) Then DirCreate($sJobsDir)

;~ MsgBox(64, "info", "Draging files with Rihgt button and choose" & @CRLF & _
;~      "'Create shortcuts here'" & @CRLF & @TAB & "or" & @CRLF & "hold ctrl + shift while draging")

$JobsDir_hWnd = _OpenJobsDir()
ConsoleWrite("$JobsDir_hWnd=" & $JobsDir_hWnd & @CRLF)

While WinExists($JobsDir_hWnd)
    _FindAllJobs()
    Sleep(1000)
WEnd

GoToExit()

;----------------------------------------------------------------------------------------
Func GoToExit()
    If WinExists($JobsDir_hWnd) Then WinClose($JobsDir_hWnd)
    Exit
EndFunc   ;==>GoToExit
;----------------------------------------------------------------------------------------
Func _OpenJobsDir()
    Local $hWnd
    If WinActivate("[TITLE:Jobs_Folder; CLASS:CabinetWClass]", "") Then
        $hWnd = WinGetHandle("[TITLE:Jobs_Folder; CLASS:CabinetWClass]")
        ; Set the active window as being ontop using the handle returned by WinGetHandle.
        WinSetOnTop($hWnd, "", $WINDOWS_ONTOP)
        Sleep(50)
    Else
        ConsoleWrite("ShellExecute" & @CRLF)
        ShellExecute($sJobsDir)
        Sleep(300)
        $hWnd = WinGetHandle("[TITLE:Jobs_Folder; CLASS:CabinetWClass]")
        ; Set the active window as being ontop using the handle returned by WinGetHandle.
        WinSetOnTop($hWnd, "", $WINDOWS_ONTOP)
        Sleep(50)
    EndIf

    Local $aW = @DesktopWidth / 3
    Local $aH = @DesktopHeight / 3
    Local $aX = @DesktopWidth - $aW
    Local $aY = @DesktopHeight - $aH

    WinMove($hWnd, "", $aX, $aY, $aW, $aH)

    Sleep(50)
    Return $hWnd

EndFunc   ;==>_OpenJobsDir
;----------------------------------------------------------------------------------------
Func _FindAllJobs()
    Local $dir = $sJobsDir
    Local $ArraySrtfiles = _FileListToArrayRec($dir, "*.lnk", $FLTAR_FILES)
    If Not IsArray($ArraySrtfiles) Then
        ;if no jobs 30 times then exit
        $iTimeOut -= 1
        ConsoleWrite("$iTimeOut=" & $iTimeOut & @CRLF)

        If $iTimeOut = 0 Then
            GoToExit()
        Else
            Return
        EndIf
    Else
        For $x = 1 To $ArraySrtfiles[0]
            _JobToDo($sJobsDir & "\" & $ArraySrtfiles[$x])
        Next
        GoToExit()
    EndIf
EndFunc   ;==>_FindAllJobs
;----------------------------------------------------------------------------------------
Func _JobToDo($sFilePath)

    ; Retrieve details about the shortcut.
    Local $aDetails = FileGetShortcut($sFilePath)

    If Not @error Then
        ConsoleWrite("-> " & $aDetails[0] & @CRLF)
    EndIf

    FileDelete($sFilePath) ; Delete the shortcut.

EndFunc   ;==>_JobToDo
;----------------------------------------------------------------------------------------

 

 

Edited by ioa747

I know that I know nothing

Link to comment
Share on other sites

I'm not really sure, if I get your task correctly, but maybe this approach, that I use to ZIP up to a few 100 files to a single archive file might fit your needs:

I start with a excel sheet similar grid of checkboxes, each one representing an existing file. (FullPathFileNames of the found files are known)

There the user can select individual files, or "in-columns" the files of one particular file type from all the matching files found.

Then I put all these files (spread across a lot of different file system folders) into the windows clipboard, all in one time, create a new temporary folder, paste the files from clipboard to this empty temp folder, and finally ZIP them all into one achive file.

Let me know if this might help for your task, then I'll look up the relevant code lines for you.

Have a look to the buildin function _ClipPutFile()

Edited by rudi

Earth is flat, pigs can fly, and Nuclear Power is SAFE!

Link to comment
Share on other sites

  • 2 weeks later...
On 8/8/2023 at 8:40 PM, ioa747 said:

a different approach, with a Jobs_Folder, where you can throw the shortcuts of  files

Dragging files with Right button and choose 'Create shortcuts here'
or   hold ctrl + shift while dragging

 

; https://www.autoitscript.com/forum/topic/210647-drag-and-drop-many-files-to-a-compiled-script/page/2/#comment-1522542
;----------------------------------------------------------------------------------------
; Title...........: Jobs_Handler.au3
; AutoIt Version..: 3.3.16.1
;----------------------------------------------------------------------------------------
#AutoIt3Wrapper_Au3Check_Parameters=-d -w 1 -w 2 -w 3 -w 4 -w 5 -w 6 -w 7
#include <File.au3>

Global $sJobsDir = @ScriptDir & "\Jobs_Folder"
Global $JobsDir_hWnd, $iTimeOut = 30

;if not exist Jobs_Folder then make it.
If Not FileExists($sJobsDir) Then DirCreate($sJobsDir)

;~ MsgBox(64, "info", "Draging files with Rihgt button and choose" & @CRLF & _
;~      "'Create shortcuts here'" & @CRLF & @TAB & "or" & @CRLF & "hold ctrl + shift while draging")

$JobsDir_hWnd = _OpenJobsDir()
ConsoleWrite("$JobsDir_hWnd=" & $JobsDir_hWnd & @CRLF)

While WinExists($JobsDir_hWnd)
    _FindAllJobs()
    Sleep(1000)
WEnd

GoToExit()

;----------------------------------------------------------------------------------------
Func GoToExit()
    If WinExists($JobsDir_hWnd) Then WinClose($JobsDir_hWnd)
    Exit
EndFunc   ;==>GoToExit
;----------------------------------------------------------------------------------------
Func _OpenJobsDir()
    Local $hWnd
    If WinActivate("[TITLE:Jobs_Folder; CLASS:CabinetWClass]", "") Then
        $hWnd = WinGetHandle("[TITLE:Jobs_Folder; CLASS:CabinetWClass]")
        ; Set the active window as being ontop using the handle returned by WinGetHandle.
        WinSetOnTop($hWnd, "", $WINDOWS_ONTOP)
        Sleep(50)
    Else
        ConsoleWrite("ShellExecute" & @CRLF)
        ShellExecute($sJobsDir)
        Sleep(300)
        $hWnd = WinGetHandle("[TITLE:Jobs_Folder; CLASS:CabinetWClass]")
        ; Set the active window as being ontop using the handle returned by WinGetHandle.
        WinSetOnTop($hWnd, "", $WINDOWS_ONTOP)
        Sleep(50)
    EndIf

    Local $aW = @DesktopWidth / 3
    Local $aH = @DesktopHeight / 3
    Local $aX = @DesktopWidth - $aW
    Local $aY = @DesktopHeight - $aH

    WinMove($hWnd, "", $aX, $aY, $aW, $aH)

    Sleep(50)
    Return $hWnd

EndFunc   ;==>_OpenJobsDir
;----------------------------------------------------------------------------------------
Func _FindAllJobs()
    Local $dir = $sJobsDir
    Local $ArraySrtfiles = _FileListToArrayRec($dir, "*.lnk", $FLTAR_FILES)
    If Not IsArray($ArraySrtfiles) Then
        ;if no jobs 30 times then exit
        $iTimeOut -= 1
        ConsoleWrite("$iTimeOut=" & $iTimeOut & @CRLF)

        If $iTimeOut = 0 Then
            GoToExit()
        Else
            Return
        EndIf
    Else
        For $x = 1 To $ArraySrtfiles[0]
            _JobToDo($sJobsDir & "\" & $ArraySrtfiles[$x])
        Next
        GoToExit()
    EndIf
EndFunc   ;==>_FindAllJobs
;----------------------------------------------------------------------------------------
Func _JobToDo($sFilePath)

    ; Retrieve details about the shortcut.
    Local $aDetails = FileGetShortcut($sFilePath)

    If Not @error Then
        ConsoleWrite("-> " & $aDetails[0] & @CRLF)
    EndIf

    FileDelete($sFilePath) ; Delete the shortcut.

EndFunc   ;==>_JobToDo
;----------------------------------------------------------------------------------------

 

 

thank you for the approach, appreciated. but I'm afraid it's too weird and heavy to make shortcuts of thousands of files, sometimes very often just to convert them.

 

On 8/9/2023 at 12:16 AM, rudi said:

I'm not really sure, if I get your task correctly

It's simple. The example is "convert thousands JPGs to PNGs". Your solution might work, but it makes the task too complicated, unfortunately.

 

Is it really impossible to handle the listing of selected files with autoit? It's some sort of autoit limitations because it had using windows limitation? Maybe anyone could give me advice on different language?

 

Link to comment
Share on other sites

3 hours ago, Tosyk said:

It's simple. The example is "convert thousands JPGs to PNGs". Your solution might work, but it makes the task too complicated, unfortunately.

 

Is it really impossible to handle the listing of selected files with autoit? It's some sort of autoit limitations because it had using windows limitation? Maybe anyone could give me advice on different language?

If I were you I'll use AutoIt to automate the conversion by FastStone Resizer (free for personal use and w/o any kind of tracking or malware). I just checked and it's open to full automation by AutoIt, extremely fast and it offers a large number of options: conversion of file format, image size, compression, color depth, DPI, watermark, ...

This wonderful site allows debugging and testing regular expressions (many flavors available). An absolute must have in your bookmarks.
Another excellent RegExp tutorial. Don't forget downloading your copy of up-to-date pcretest.exe and pcregrep.exe here
RegExp tutorial: enough to get started
PCRE v8.33 regexp documentation latest available release and currently implemented in AutoIt beta.

SQLitespeed is another feature-rich premier SQLite manager (includes import/export). Well worth a try.
SQLite Expert (freeware Personal Edition or payware Pro version) is a very useful SQLite database manager.
An excellent eBook covering almost every aspect of SQLite3: a must-read for anyone doing serious work.
SQL tutorial (covers "generic" SQL, but most of it applies to SQLite as well)
A work-in-progress SQLite3 tutorial. Don't miss other LxyzTHW pages!
SQLite official website with full documentation (may be newer than the SQLite library that comes standard with AutoIt)

Link to comment
Share on other sites

How about this? It looks if the first command line parameter is an existing file, and if so it evaluates which files are selected in the topmost instance of "explorer.exe" 😉. Of course depends on how you drag and drop, and where the .exe is going to be located (fine-tuning).

_cmdline.zip

 

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