#region: - Options Opt('MustDeclareVars', 1) Opt('TrayIconDebug', 1) Opt('TrayIconHide', 0) #endregion HotKeySet('{ESC}', '_Pro_Exit') Local $sSerchInDirPath = 'd:\Обмен' Local $sFilesSerchRegMask = '.+\.lnk'; Фильтр поиса файлов, заданный в виде регулярного выражения. Local $sDirsSerchRegMask = '.*'; Фильтр поиса директорий, заданный в виде регулярного выражения. Local $sDirCreateLnkPath = 'd:\qweqwe\'; Директория, в которой будут созданы ярлыки. Если 0, -1 или пустая строка, то ярлыки будут созданны в той же директории, в которой был найден файл, на который ссылается ярлык. Local $fSaveDirStrct = 1; Восстановить в $sDirCreateLnkPath структуру папок, в которых были найденны искомые файлы Local $sAutoItFilePath = 'd:\test2\Shortcut.au3'; Директория, в которой будет создан результирующий AutoIt файл. Если 0, -1 или пустая строка, то будет путь: @ScriptDir\Shortcut.au3 _CreatShortcutAU3File($sSerchInDirPath, $sFilesSerchRegMask, $sDirsSerchRegMask, $sDirCreateLnkPath, $fSaveDirStrct, $sAutoItFilePath) If @error Then MsgBox(48, 'Ошибка: ' & @error, 'Искомые файлы не найдены') Func _CreatShortcutAU3File($sSerchInDirPath, $sFilesSerchRegMask, $sDirsSerchRegMask, $sDirCreateLnkPath, $fSaveDirStrct, $sAutoItFilePath) Local $i, $j, $aFilesList[1], $sFileName, $sDirPath, $sLnkName, $sLnkDirPath, $aLnkInfo[7], $hFile, $sResult, $aResultVar, $sResultVar = '|' $sSerchInDirPath = StringStripWS(StringRegExpReplace($sSerchInDirPath, '\\+$', ''), 1+2) $sDirCreateLnkPath = StringStripWS(StringRegExpReplace($sDirCreateLnkPath, '\\+$', ''), 1+2) $sAutoItFilePath = StringStripWS($sAutoItFilePath, 1+2) $aFilesList = _GetFilesDirsList($sSerchInDirPath, $sFilesSerchRegMask, $sDirsSerchRegMask) If NOT $aFilesList[0] Then Return SetError(1) For $i=1 To UBound($aFilesList)-1 $sFileName = StringRegExpReplace($aFilesList[$i], '.+\\(.+)$', '\1') $sDirPath = StringRegExpReplace($aFilesList[$i], '(.+)\\.+$', '\1') $sLnkName = StringRegExpReplace($sFileName, '(.+)\.+.*$', '\1') & '.lnk' $sLnkDirPath = '' If $sDirCreateLnkPath AND $sDirCreateLnkPath <> -1 Then If $fSaveDirStrct Then $sLnkDirPath = StringTrimLeft($sDirPath, 3) $sLnkDirPath = $sDirCreateLnkPath & '\' & $sLnkDirPath Else $sLnkDirPath = $sDirPath EndIf $sLnkDirPath = StringRegExpReplace($sLnkDirPath, '\\+$', '\1') If StringRegExpReplace($aFilesList[$i], '.+\\.*\.(.+)$', '\1') == 'lnk' Then $aLnkInfo = FileGetShortcut($aFilesList[$i]) Else $aLnkInfo[0] = $aFilesList[$i]; Путь к целевому файлу $aLnkInfo[1] = $sDirPath ; Рабочая директория $aLnkInfo[2] = '' ; Аргументы $aLnkInfo[3] = $aFilesList[$i]; Описание EndIf $aLnkInfo[4] = $sLnkDirPath $aLnkInfo[5] = $sLnkDirPath & '\' & $sLnkName For $j=0 To 5 $aLnkInfo[$j] = StringReplace(StringStripCR($aLnkInfo[$j]), @LF, ' ') $aLnkInfo[$j] = StringReplace($aLnkInfo[$j], '''', '''''') If $j < 2 OR $j > 3 Then $aLnkInfo[$j] = StringReplace($aLnkInfo[$j], '"', '') If NOT StringInStr($sResultVar, '|' & $aLnkInfo[$j] & '|') Then $sResultVar &= $aLnkInfo[$j] & '|' Next $sResult &= 'If NOT FileExists(''' & $aLnkInfo[4] & ''') Then DirCreate(''' & $aLnkInfo[4] & ''')' & @CRLF $sResult &= 'FileCreateShortcut(''' & $aLnkInfo[0] & ''', ''' & $aLnkInfo[5] & ''', ''' & $aLnkInfo[1] & ''', ''' & $aLnkInfo[2] & ''', ''' & $aLnkInfo[3] & ''')' If $i < UBound($aFilesList)-1 Then $sResult &= @CRLF & @CRLF Next If $sResult == '' Then Return SetError(2) $aResultVar = StringSplit($sResultVar, '|') If NOT @error Then $sResultVar = '' For $i=1 To $aResultVar[0] SetError(0, 0) StringReplace($sResult, $aResultVar[$i], '') If @extended > 1 Then $sResultVar &= '$sVar' & $i & ' = ''' & $aResultVar[$i] & '''' & @CRLF $sResult = StringReplace($sResult, '''' & $aResultVar[$i] & '''', '$sVar' & $i) EndIf Next EndIf If NOT $sAutoItFilePath OR $sAutoItFilePath == -1 Then $sAutoItFilePath = @ScriptDir & '\' & 'Shortcut.au3' If $sResultVar <> '' Then $sResult = $sResultVar & @CRLF & $sResult $sResult = 'Opt("TrayIconHide", 1)' & @CRLF & @CRLF & $sResult $hFile = FileOpen($sAutoItFilePath, 2+8) FileWrite($hFile, $sResult) FileClose($hFile) EndFunc Func _GetFilesDirsList($sSerchInDirPath, $sFilesSerchRegMask='.*', $sDirsSerchRegMask='.*', $iAddFiles=1, $iAddDirs=0, $fSerchInWrongDir=1, $sRootPath=1, $fAddFromRootDir=1) $sSerchInDirPath = StringRegExpReplace($sSerchInDirPath, '\\+$', '') Local $aResultList[1], $aSubResultList[1], $aSub2ResultList[1], $hSerch, $sFileName, $sFilePath, $fAddToResult, $fIsDir, $fDirsSerchRegMask, $fFilesSerchRegMask, $fSerchInWrongDirSub, $fAddFromRootDirSub, $i $aResultList[0] = 0 $hSerch = FileFindFirstFile($sSerchInDirPath & '\' & '*') If @error Then Return SetError(1, 0, $aResultList) If $sRootPath == 1 AND $iAddDirs == 1 AND $fAddFromRootDir Then $aResultList[0] += 1 ReDim $aResultList[$aResultList[0]+1] $aResultList[$aResultList[0]] = $sSerchInDirPath EndIf While 1 $sFileName = FileFindNextFile($hSerch) If @error == 1 Then ExitLoop $sFilePath = $sSerchInDirPath & '\' & $sFileName $fAddToResult = 0 $fIsDir = StringInStr(FileGetAttrib($sFilePath), 'D') $fDirsSerchRegMask = StringRegExp(StringRegExpReplace($sFilePath, '.+\\(.+)$', '\1'), $sDirsSerchRegMask) $fFilesSerchRegMask = StringRegExp(StringRegExpReplace($sFilePath, '.+\\(.+)$', '\1'), $sFilesSerchRegMask) $fAddFromRootDirSub = 1 If NOT $fDirsSerchRegMask Then $fAddFromRootDirSub = 0 If $fIsDir Then If $iAddDirs == 1 AND $fDirsSerchRegMask Then $fAddToResult = 1 Else If $iAddFiles == 1 AND $fFilesSerchRegMask AND $fAddFromRootDir Then $fAddToResult = 1 EndIf If $fAddToResult Then If $sRootPath == 1 AND NOT $fIsDir Then $aResultList[0] += 1 ReDim $aResultList[$aResultList[0]+1] $aResultList[$aResultList[0]] = $sFilePath Else $aSubResultList[0] += 1 ReDim $aSubResultList[$aSubResultList[0]+1] $aSubResultList[$aSubResultList[0]] = $sFilePath EndIf EndIf $fSerchInWrongDirSub = 1 If NOT $fSerchInWrongDir AND $fIsDir AND NOT $fDirsSerchRegMask Then $fSerchInWrongDirSub = 0 $aSub2ResultList[0] = 0 If $fIsDir Then If $fSerchInWrongDirSub Then _ $aSub2ResultList = _GetFilesDirsList($sFilePath, $sFilesSerchRegMask, $sDirsSerchRegMask, $iAddFiles, $iAddDirs, $fSerchInWrongDir, 0, $fAddFromRootDirSub) EndIf If $aSub2ResultList[0] Then For $i = 1 To $aSub2ResultList[0] $aSubResultList[0] += 1 ReDim $aSubResultList[$aSubResultList[0]+1] $aSubResultList[$aSubResultList[0]] = $aSub2ResultList[$i] Next EndIf WEnd FileClose($hSerch) For $i=1 To UBound($aSubResultList)-1 $aResultList[0] += 1 ReDim $aResultList[$aResultList[0]+1] $aResultList[$aResultList[0]] = $aSubResultList[$i] Next Return SetError(0, 0, $aResultList) EndFunc Func _Pro_Exit() Exit EndFunc |