AutoHotKey:如何计算活动文件夹中的文件数并复制到剪贴板?
AutoHotKey: How to Count number of files in active folder and copy to clipboard?
我有一个很长的文件夹列表,我需要将以下两条信息自动电子表格化到我们现有的 excel 文档中:
- 文件夹名称
- 该文件夹中的文件数
我已经编写了脚本,现在我需要 AHK 来获取活动资源管理器的文件数 window,复制到剪贴板,然后 ALT+TAB/Paste 将其放入电子表格。我计划使用 'goto' 循环此脚本并仅监视它直到它到达最后一个文件夹并使用 ESC 目视结束脚本。
获取活动 window 的数值文件数并将其复制到剪贴板的最简单方法是什么?
到目前为止我的代码基本上是使用 F2 到 'rename' 因此复制文件夹名称,alt+tab 到电子表格,粘贴它,移动到电子表格上的文件计数单元格,alt+tab 回到活动资源管理器 window,进入所述文件夹 - 现在我卡住了(我需要在剪贴板上获取文件计数)。值得注意的是,我希望文件计数忽略像 .DS_Store 这样的系统文件(如果它们存在的话)。
`::
{
Send, {F2}
Sleep, 200
Send, {Ctrl Down}
Sleep, 50
Send, c
sleep, 50
Send, {Ctrl Up}
Sleep, 100
Send, {Alt Down}
Sleep, 50
Send, {Tab}
Sleep, 50
Send, {Alt Up}
Sleep, 100
Send, {Ctrl Down}
Sleep, 50
Send, v
sleep, 50
Send, {Ctrl Up}
Sleep, 100
Send, {Right}
Sleep, 50
Send, {Right}
Sleep, 50
Send, {Right}
Sleep, 100
Send, {Alt Down}
Sleep, 50
Send, {Tab}
Sleep, 50
Send, {Alt Up}
Sleep, 100
Send, {Enter}
^^^^^^^^^^^^^ Need my file count / copy to clipboard here
Esc::ExitApp
}
也许看看这样的东西(并在评论中跟进):
; Calculate the number of files in a folder and its subfolders:
SetBatchLines, -1 ; Make the operation run at maximum speed.
FileNum = 0
; FileSelectFolder, WhichFolder ; Ask the user to pick a folder.
WhichFolder := Clipboard ; assumes full path to folder is in clipboard
Loop, Files, %WhichFolder%\*.*, R
{
if A_LoopFileAttrib contains H,R,S ; Skip Hidden, Read-only, or System files
continue ; Skip this file and move on to the next one
FileNum += 1
}
Clipboard := FileNum
ClipWait ; Wait for the clipboard to contain text.
MsgBox %WhichFolder% has %FileNum% files in it (incl. subfolders).
然后,看看下面的内容,其中解释了如何读取和循环遍历目录和文件:
https://autohotkey.com/docs/commands/LoopFile.htm.
Hth,让我们知道你是怎么做出来的。 . .
我有一个很长的文件夹列表,我需要将以下两条信息自动电子表格化到我们现有的 excel 文档中:
- 文件夹名称
- 该文件夹中的文件数
我已经编写了脚本,现在我需要 AHK 来获取活动资源管理器的文件数 window,复制到剪贴板,然后 ALT+TAB/Paste 将其放入电子表格。我计划使用 'goto' 循环此脚本并仅监视它直到它到达最后一个文件夹并使用 ESC 目视结束脚本。
获取活动 window 的数值文件数并将其复制到剪贴板的最简单方法是什么?
到目前为止我的代码基本上是使用 F2 到 'rename' 因此复制文件夹名称,alt+tab 到电子表格,粘贴它,移动到电子表格上的文件计数单元格,alt+tab 回到活动资源管理器 window,进入所述文件夹 - 现在我卡住了(我需要在剪贴板上获取文件计数)。值得注意的是,我希望文件计数忽略像 .DS_Store 这样的系统文件(如果它们存在的话)。
`::
{
Send, {F2}
Sleep, 200
Send, {Ctrl Down}
Sleep, 50
Send, c
sleep, 50
Send, {Ctrl Up}
Sleep, 100
Send, {Alt Down}
Sleep, 50
Send, {Tab}
Sleep, 50
Send, {Alt Up}
Sleep, 100
Send, {Ctrl Down}
Sleep, 50
Send, v
sleep, 50
Send, {Ctrl Up}
Sleep, 100
Send, {Right}
Sleep, 50
Send, {Right}
Sleep, 50
Send, {Right}
Sleep, 100
Send, {Alt Down}
Sleep, 50
Send, {Tab}
Sleep, 50
Send, {Alt Up}
Sleep, 100
Send, {Enter}
^^^^^^^^^^^^^ Need my file count / copy to clipboard here
Esc::ExitApp
}
也许看看这样的东西(并在评论中跟进):
; Calculate the number of files in a folder and its subfolders:
SetBatchLines, -1 ; Make the operation run at maximum speed.
FileNum = 0
; FileSelectFolder, WhichFolder ; Ask the user to pick a folder.
WhichFolder := Clipboard ; assumes full path to folder is in clipboard
Loop, Files, %WhichFolder%\*.*, R
{
if A_LoopFileAttrib contains H,R,S ; Skip Hidden, Read-only, or System files
continue ; Skip this file and move on to the next one
FileNum += 1
}
Clipboard := FileNum
ClipWait ; Wait for the clipboard to contain text.
MsgBox %WhichFolder% has %FileNum% files in it (incl. subfolders).
然后,看看下面的内容,其中解释了如何读取和循环遍历目录和文件: https://autohotkey.com/docs/commands/LoopFile.htm.
Hth,让我们知道你是怎么做出来的。 . .