1 (изменено: AHK_on, 2020-02-10 18:08:14)

Тема: AHK: Скопировать свойства файла, название и содержимое файла

Доброго времени суток!
Нужна помощь!

Алгоритм действий который хочу автоматизировать:
Вручную выделяю мышкой текстовый файл (.txt .odt)
Копировать в буфер обмена:
- Дату изменения,
- Название файла,
- Содержимое файла.
Дальше я ставляю полученный массив данных в текстовое поле текстового редактора.

У меня есть текстовые файлы. Я хочу скопировать их в один единый текстовый файл с датой модификации с сортировкой от поздней к ранней.

2

Re: AHK: Скопировать свойства файла, название и содержимое файла

AHK_on, если пишете ТЗ, размещайте сразу в Коммерческий раздел.

Разработка AHK-скриптов:
e-mail dfiveg@mail.ru
Telegram jollycoder

3 (изменено: AHK_on, 2020-02-10 18:13:00)

Re: AHK: Скопировать свойства файла, название и содержимое файла

Спасибо за обратную связь. Не думал что это так выглядит. Наоборот хотел очень коротко написать, без воды.

Я хотел узнать у знающих людей, куда копать?
А может у кого-то уже была такая проблема и уже есть готовое решение по копированию свойств у выделенного файла.

4

Re: AHK: Скопировать свойства файла, название и содержимое файла

Разбейте задачу на составляющие. Ту часть, которая понятна, делаете сами, что непонятно — сначала ищете поиском на форуме, потом спрашиваете.

Разработка AHK-скриптов:
e-mail dfiveg@mail.ru
Telegram jollycoder

5 (изменено: svoboden, 2020-02-11 02:53:43)

Re: AHK: Скопировать свойства файла, название и содержимое файла

Во-первых, содержимое файла - это не свойство этого файла. Есть небольшой скрипт, который получает дату модификации, названия, и много другой информации любого типа файла под курсором мыши. Думаю, можно переделать для выделенных файлов. Есть еще функции для склеивания файлов в один: "https://www.autohotkey.com/boards/viewt … ified+Date".

#NoEnv

CoordMode, Mouse, Screen  ; Required when the active window is not the desktop
SetTimer, Timer, 10
Return

Timer:
   if (Icon := GetDesktopIconUnderMouse())
      ToolTip, % "Icon Coordinates`nX: " Icon.left "`tY: " Icon.top "`nW: " Icon.right - Icon.left "`tH: " Icon.bottom - Icon.top
               . "`nName: " Icon.name "`nSize: " (Icon.type = "File folder" ? GetFolderSize(A_Desktop "\" Icon.name) : Icon.size)
               . "`nType: " Icon.type "`nDate modified: " Icon.date
   else
      ToolTip
Return

Esc::
   ExitApp

; ===============================================================================================================================
; GetDesktopIconUnderMouse()
; Function:       Gets the desktop icon under the mouse. See the "Return values" section below for more information about the
;                 icon and associated file data retrieved.
; Parameters:     None
; Return values:  If there is an icon under the mouse, an associative array with the following keys:
;                 - left: the left position of the icon in screen coordinates
;                 - top: the top position of the icon in screen coordinates
;                 - right: the right position of the icon in screen coordinates
;                 - bottom: the bottom position of the icon in screen coordinates
;                 - name: the name of the file represented by the icon, e.g. New Text Document.txt
;                 - size: the size of the file represented by the icon, e.g. 1.72 KB. Note: this value is blank for folders
;                 - type: the type of the file represented by the icon, e.g. TXT File, JPEG image, File folder
;                 - date: the modified date of the file represented by the icon, e.g. 9/9/2016 10:39 AM
;                 Otherwise, a blank value
; Global vars:    None
; Dependencies:   None
; Tested with:    AHK 1.1.30.01 (A32/U32/U64)
; Tested on:      Win 7 (x64)
; Written by:     iPhilip
; ===============================================================================================================================

GetDesktopIconUnderMouse() {
   static MEM_COMMIT := 0x1000, MEM_RELEASE := 0x8000, PAGE_READWRITE := 0x04
        , PROCESS_VM_OPERATION := 0x0008, PROCESS_VM_READ := 0x0010
        , LVM_GETITEMCOUNT := 0x1004, LVM_GETITEMRECT := 0x100E
   
   Icon := ""
   MouseGetPos, x, y, hwnd
   if not (hwnd = WinExist("ahk_class Progman") || hwnd = WinExist("ahk_class WorkerW"))
      Return
   ControlGet, hwnd, HWND, , SysListView321
   if not WinExist("ahk_id" hwnd)
      Return
   WinGet, pid, PID
   if (hProcess := DllCall("OpenProcess" , "UInt", PROCESS_VM_OPERATION|PROCESS_VM_READ, "Int",  false, "UInt", pid)) {
      VarSetCapacity(iCoord, 16)
      SendMessage, %LVM_GETITEMCOUNT%, 0, 0
      Loop, %ErrorLevel% {
         pItemCoord := DllCall("VirtualAllocEx", "Ptr", hProcess, "Ptr", 0, "UInt", 16, "UInt", MEM_COMMIT, "UInt", PAGE_READWRITE)
         SendMessage, %LVM_GETITEMRECT%, % A_Index-1, %pItemCoord%
         DllCall("ReadProcessMemory", "Ptr", hProcess, "Ptr", pItemCoord, "Ptr", &iCoord, "UInt", 16, "UInt", 0)
         DllCall("VirtualFreeEx", "Ptr", hProcess, "Ptr", pItemCoord, "UInt", 0, "UInt", MEM_RELEASE)
         left   := NumGet(iCoord,  0, "Int")
         top    := NumGet(iCoord,  4, "Int")
         right  := NumGet(iCoord,  8, "Int")
         bottom := NumGet(iCoord, 12, "Int")
         if (left < x and x < right and top < y and y < bottom) {
            ControlGet, list, List
            RegExMatch(StrSplit(list, "`n")[A_Index], "O)(.*)\t(.*)\t(.*)\t(.*)", Match)
            Icon := {left:left, top:top, right:right, bottom:bottom
                   , name:Match[1], size:Match[2], type:Match[3]
                     ; Delete extraneous date characters (https://goo.gl/pMw6AM):
                     ; - Unicode LTR (Left-to-Right) mark (0x200E = 8206)
                     ; - Unicode RTL (Right-to-Left) mark (0x200F = 8207)
                   , date:RegExReplace(Match[4], A_IsUnicode ? "[\x{200E}-\x{200F}]" : "\?")}
            Break
         }
      }
      DllCall("CloseHandle", "Ptr", hProcess)
   }
   Return Icon
}

; This function returns the total size of the specified folder
; in the same format used when selecting an icon on the desktop,
; e.g. 438 bytes, 1022 bytes, 1.72 KB, 666 KB, 15.6 MB.

GetFolderSize(Folder) {
   static Units := ["bytes","KB","MB","GB"]
        , objFSO := ComObjCreate("Scripting.FileSystemObject")
   
   Size := objFSO.GetFolder(Folder).Size
   Index := 1
   while (Size >= 1024) {
      Size /= 1024.
      Index++
   }
   N := StrLen(Round(Size))
   N := N < 3 ? 4 : N
   Return SubStr(Size, 1, N) " " Units[Index]
}