Kopiere die neueste Datei im Windows-Ordner automatisch in die Zwischenablage

530
John Smith

Ich verwende ein Programm namens " Screenshot-Assistent ", um PNG-Dateien in JPG zu konvertieren. Das Programm gibt die Dateien aus der Zwischenablage in einen bestimmten Ordner aus.

Ich suche nach einer Möglichkeit, das zuletzt hinzugefügte Bild in diesem Ordner zu kopieren und in die Zwischenablage zu kopieren, damit ich es an anderer Stelle einfügen kann.

Vielen Dank für Ihre Zeit!

5
Re: "kopiere es in die Zwischenablage" ... das könnte ein paar verschiedene Dinge bedeuten. Wollen Sie die Datei in einen anderen Ordner verschieben, wenn Sie eine "Einfügen" -Aktion ausführen? (dh Kopieren / Einfügen zwischen Ordnern im Explorer?) Möchten Sie den neuesten Dateipfad als Text einfügen? Oder möchten Sie Grafiken in ein Dokument wie Word oder ähnliches einfügen? Ich glaube, die ersten beiden würden durch den unten angegebenen Code angesprochen werden, und es gibt andere Methoden, um die dritte anzusprechen, wenn der folgende Code dies auch nicht tut, was möglicherweise der Fall ist - ich habe es nicht getestet JJohnston2 vor 6 Jahren 0

1 Antwort auf die Frage

2
user3419297

Kopiere die neueste JPG-Datei im Windows-Ordner automatisch in die Zwischenablage (sobald sie erstellt wurde):

#Persistent SetTimer new_JPG_image_created, 300 return  new_JPG_image_created: Loop, folder_path\*.jpg { now := %A_Now% EnvSub, now, %A_LoopFileTimeCreated%, seconds If now < 2 ; newer as 2 seconds {  SetTimer, new_JPG_image_created, off  ; MsgBox, 262212,,A new file `n%A_Tab%%A_LoopFileFullPath%`nis added in`n%A_Tab%folder_path`nCopy this file? ; IfMsgBox Yes ClipBoardSetFiles(A_LoopFileFullPath) SetTimer, new_JPG_image_created, on } } return  ; ------------------------------------------------------------- ; FUNCTION:  ; https://autohotkey.com/boards/viewtopic.php?p=63914#p63914 ; -------------------------------------------------------------  ClipboardSetFiles(FilesToSet, DropEffect := "Copy") { ; FilesToSet - list of fully qualified file pathes separated by "`n" or "`r`n" ; DropEffect - preferred drop effect, either "Copy", "Move" or "" (empty string) Static TCS := A_IsUnicode ? 2 : 1 ; size of a TCHAR Static PreferredDropEffect := DllCall("RegisterClipboardFormat", "Str", "Preferred DropEffect") Static DropEffects :=  ; ------------------------------------------------------------------------------------------------------------------- ; Count files and total string length TotalLength := 0 FileArray := [] Loop, Parse, FilesToSet, `n, `r { If (Length := StrLen(A_LoopField)) FileArray.Push() TotalLength += Length } FileCount := FileArray.Length() If !(FileCount && TotalLength) Return False ; ------------------------------------------------------------------------------------------------------------------- ; Add files to the clipboard If DllCall("OpenClipboard", "Ptr", A_ScriptHwnd) && DllCall("EmptyClipboard") { ; HDROP format --------------------------------------------------------------------------------------------------- ; 0x42 = GMEM_MOVEABLE (0x02) | GMEM_ZEROINIT (0x40) hDrop := DllCall("GlobalAlloc", "UInt", 0x42, "UInt", 20 + (TotalLength + FileCount + 1) * TCS, "UPtr") pDrop := DllCall("GlobalLock", "Ptr", hDrop) Offset := 20 NumPut(Offset, pDrop + 0, "UInt") ; DROPFILES.pFiles = offset of file list NumPut(!!A_IsUnicode, pDrop + 16, "UInt") ; DROPFILES.fWide = 0 --> ANSI, fWide = 1 --> Unicode For Each, File In FileArray Offset += StrPut(File.Path, pDrop + Offset, File.Len) * TCS DllCall("GlobalUnlock", "Ptr", hDrop) DllCall("SetClipboardData","UInt", 0x0F, "UPtr", hDrop) ; 0x0F = CF_HDROP ; Preferred DropEffect format ------------------------------------------------------------------------------------ If (DropEffect := DropEffects[DropEffect]) { ; Write Preferred DropEffect structure to clipboard to switch between copy/cut operations ; 0x42 = GMEM_MOVEABLE (0x02) | GMEM_ZEROINIT (0x40) hMem := DllCall("GlobalAlloc", "UInt", 0x42, "UInt", 4, "UPtr") pMem := DllCall("GlobalLock", "Ptr", hMem) NumPut(DropEffect, pMem + 0, "UChar") DllCall("GlobalUnlock", "Ptr", hMem) DllCall("SetClipboardData", "UInt", PreferredDropEffect, "Ptr", hMem) } DllCall("CloseClipboard") Return True } Return False }