Must AutoIt
Сообщения: 3054
Благодарности: 1009
|
Профиль
|
Сайт
|
Отправить PM
| Цитировать
Вообщем вот ещё одна версия, если путь не найден, путь определяется методом создания временного файла с использованием буфера обмена. Есть также метод где происходит откат адресной строки, для этого нужно установить 1 у переменной $iGet_Path_Method. Так или иначе, оба метода не самые надёжные
* Также добавил поддержку очерёдности запуска функции - По идее, если нажимать заветные горячие клавиши несколько раз подряд, то папки будут создаваться по очерёдно, в логе будет это записано (попытка двойного вызова, и запись с очереди).
Код: 
#NoTrayIcon
#include <File.au3>
#include <Misc.au3>
_Singleton("_CreateFolder_Proc")
Opt("WinWaitDelay", 1)
Global $i_CreateFolder_Proc_IsRuning = False
Global $iQueue_Calls = 0
Global $iDebug = True
Global $sDebug_LogFile = @ScriptDir & "\DebugLog.log"
Global $iGet_Path_Method = -1
Global $sFileNameFormat = "New_%i"
HotKeySet("^+n", "_CreateFolder_Proc") ;Ctrl + Shift + n
HotKeySet("^+т", "_CreateFolder_Proc") ;Ctrl + Shift + n
HotKeySet("^+w", "_Quit") ;Ctrl + Shift + w
HotKeySet("^+ц", "_Quit") ;Ctrl + Shift + w
OnAutoItStart_Init()
While 1
Sleep(1000)
If $iQueue_Calls > 0 Then
For $i = 1 To $iQueue_Calls
_CreateFolder_Proc($i)
Next
EndIf
WEnd
Func _CreateFolder_Proc($iQueue_Call=0)
If $i_CreateFolder_Proc_IsRuning Then
$iQueue_Calls += 1
Return _DebugToLog_Proc("_CreateFolder_Proc Call: ### Double Call Try... Added to the Queue (#" & $iQueue_Calls & ").")
EndIf
$i_CreateFolder_Proc_IsRuning = True
Local $s_CreateFolder_Proc_DebugData = "_CreateFolder_Proc Call: Called by HotKey(" & @HotKeyPressed & ")"
If IsDeclared("iQueue_Call") And $iQueue_Call > 0 Then
$s_CreateFolder_Proc_DebugData &= " ==> Queue Call #" & $iQueue_Call
$iQueue_Calls -= 1
EndIf
_DebugToLog_Proc($s_CreateFolder_Proc_DebugData & ".")
Local $sExplorer_Title = "[CLASS:CabinetWClass]"
Local $sPath, $iFolder_Created = 0
If Not WinActive($sExplorer_Title) Then $sExplorer_Title = "[CLASS:ExploreWClass]"
If Not WinActive($sExplorer_Title) Then $sExplorer_Title = "[CLASS:Progman]"
If Not WinActive($sExplorer_Title) Then
$i_CreateFolder_Proc_IsRuning = False
Return _DebugToLog_Proc("_CreateFolder_Proc Call: Dir creation is not possible in currently active window: " & _
WinGetTitle("[ACTIVE]") & @CRLF)
EndIf
Switch $sExplorer_Title
Case "[CLASS:CabinetWClass]", "[CLASS:ExploreWClass]"
Local $sWin_Title = WinGetTitle($sExplorer_Title)
Local $sWin_Text = WinGetText($sExplorer_Title)
$sPath = StringRegExpReplace($sWin_Text, "(?s).*(\r\n|)(\w+:\\.*" & $sWin_Title & ")(\r\n|.*)", "\2")
Case "[CLASS:Progman]"
$sPath = @DesktopDir
Case Else
$i_CreateFolder_Proc_IsRuning = False
Return _DebugToLog_Proc( _
"_CreateFolder_Proc Call: " & _
"Unexpected error (can not get window class name, perhaps a memory unavailable)." & @CRLF)
EndSwitch
_DebugToLog_Proc("_CreateFolder_Proc Call: Found active window with following Class Name: " & $sExplorer_Title)
_DebugToLog_Proc("_CreateFolder_Proc Call: And with the following Title: " & WinGetTitle($sExplorer_Title))
If Not StringInStr(FileGetAttrib($sPath), "D") Then $sPath = ControlGetText($sExplorer_Title, "", "Edit1")
If Not StringInStr(FileGetAttrib($sPath), "D") Then
_DebugToLog_Proc("_CreateFolder_Proc Call: Path for creating folder was not found... ")
_DebugToLog_Proc("_CreateFolder_Proc Call: Trying to get path in a hard way :)... (MODE: " & $iGet_Path_Method & ")")
Switch $iGet_Path_Method
Case 1
ControlSend($sExplorer_Title, "", "ToolbarWindow322", "!в{Right}{Down}{Enter}")
Sleep(200)
$sPath = ControlGetText($sExplorer_Title, "", "Edit1")
ControlSend($sExplorer_Title, "", "ToolbarWindow322", "!в{Right}{Down}{Enter}")
Case Else
Local $sTmp_File = _TempFile(@TempDir, "~__Au3_DirCreate_Tmp_Module__")
Local $sTmp_FileName = StringRegExpReplace($sTmp_File, "^.*\\|\.[^\.]*$", "")
Local $hOpenFile = FileClose(FileOpen($sTmp_File, 2))
_ClipPutFile($sTmp_File)
If @error Then _DebugToLog_Proc("_CreateFolder_Proc Call: _ClipPutFile Failed.")
ControlSend($sExplorer_Title, "", "SysListView321", "+{Insert}")
Sleep(500)
$iItem = ControlListView($sExplorer_Title, "", "SysListView321", "FindItem", $sTmp_FileName)
ControlListView($sExplorer_Title, "", "SysListView321", "SelectClear")
ControlListView($sExplorer_Title, "", "SysListView321", "Select", $iItem, $iItem)
Sleep(200)
ControlSend($sExplorer_Title, "", "SysListView321", "^{Insert}")
Sleep(500)
$sPath = ClipGet()
If @error Then _DebugToLog_Proc("_CreateFolder_Proc Call: ClipGet() Failed (ERROR: " & @error & ").")
If StringInStr($sPath, @CRLF) Then _
$sPath = StringLeft($sPath, StringInStr($sPath, @CRLF)-1)
$sPath = StringLeft($sPath, StringInStr($sPath, "\", 0, -1)-1)
FileDelete($sPath & "\" & $sTmp_FileName & ".tmp")
FileDelete($sTmp_File)
EndSwitch
If Not StringInStr(FileGetAttrib($sPath), "D") Then
$i_CreateFolder_Proc_IsRuning = False
Return _DebugToLog_Proc("_CreateFolder_Proc Call: Path for creating folder was not found: " & $sPath)
EndIf
EndIf
_DebugToLog_Proc("_CreateFolder_Proc Call: Detected path for creating folder in: " & $sPath)
Local $iFolder_Num = 1
Local $sNewFolderName = StringFormat($sFileNameFormat, $iFolder_Num)
While StringInStr(FileGetAttrib($sPath & "\" & $sNewFolderName), "D")
$iFolder_Num += 1
$sNewFolderName = StringFormat($sFileNameFormat, $iFolder_Num)
WEnd
_DebugToLog_Proc("_CreateFolder_Proc Call: Creating folder with the following name: " & $sNewFolderName & "...")
$iFolder_Created = DirCreate($sPath & "\" & $sNewFolderName)
_DebugToLog_Proc("_CreateFolder_Proc Call: Folder created(?): " & ($iFolder_Created = 1) & @CRLF)
$i_CreateFolder_Proc_IsRuning = False
EndFunc ;==>_CreateFolder_Proc
Func _DebugToLog_Proc($sDebug_Info)
If Not $iDebug Then Return
_FileWriteLogEx($sDebug_LogFile, $sDebug_Info & @CRLF)
EndFunc ;==>_DebugToLog_Proc
Func _FileWriteLogEx($sLogPath, $sLogMsg, $iFlag = -1)
Local $sDateNow, $sTimeNow, $sMsg, $iWriteFile, $hOpenFile, $iOpenMode = 1
$sDateNow = @YEAR & "-" & @MON & "-" & @MDAY
$sTimeNow = @HOUR & ":" & @MIN & ":" & @SEC
$sMsg = $sDateNow & " " & $sTimeNow & ">> " & $sLogMsg
If $iFlag <> -1 Then
$sMsg &= FileRead($sLogPath)
$iOpenMode = 2
EndIf
$hOpenFile = FileOpen($sLogPath, $iOpenMode)
If $hOpenFile = -1 Then Return SetError(1, 0, 0)
$iWriteFile = FileWriteLine($hOpenFile, $sMsg)
If $iWriteFile = -1 Then Return SetError(2, 0, 0)
Return FileClose($hOpenFile)
EndFunc ;==>_FileWriteLogEx
Func _Quit()
Exit
EndFunc ;==>_Quit
Func OnAutoItStart_Init()
If $iDebug Then
If FileRead($sDebug_LogFile) <> "" Then
_FileWriteLogEx($sDebug_LogFile, _
StringFormat("============ Debug Log For [%s] Started ============\r\n\r\n...\r\n\r\n", @ScriptName))
Else
_FileWriteLogEx($sDebug_LogFile, StringFormat("============ Debug Log For [%s] Started...", @ScriptName))
_FileWriteLogEx($sDebug_LogFile, StringFormat("============ Operating System: %s\r\n", @OSVersion))
_FileWriteLogEx($sDebug_LogFile, StringFormat("============ Service Pack: %s\r\n", @OSServicePack))
_FileWriteLogEx($sDebug_LogFile, _
StringFormat("============ File System: %s ============\r\n\r\n...\r\n\r\n", DriveGetFileSystem(@HomeDrive)))
EndIf
EndIf
EndFunc ;==>OnAutoItStart_Init
Func OnAutoItExit()
If $iDebug Then
_FileWriteLogEx($sDebug_LogFile, _
StringFormat("============ Debug Log Finished (EXIT CODE: %i) ============\r\n\r\n\r\n", @ScriptName, @exitCode))
$iOpen_LogFile = MsgBox(36, @ScriptName & " - Attention", "Open Debug Log File?" & @CRLF & @CRLF & $sDebug_LogFile)
If $iOpen_LogFile = 6 Then ShellExecute($sDebug_LogFile, "", "", "Open", @SW_SHOWNORMAL)
EndIf
EndFunc ;==>OnAutoItExit
|