Snippets ( Files & Folders ): Difference between revisions
m (+Snippets Category (+ normalize top)) |
(Edited snippets to conform to template Snippet Header.) |
||
Line 4: | Line 4: | ||
{{Snippet Credit Header}} | {{Snippet Credit Header}} | ||
===== | == _ConvertFileToUTF16 == | ||
{{Snippet Header | |||
| AuthorURL = 35302-guinness | |||
| AuthorName = guinness | |||
}} | |||
<syntaxhighlight lang="autoit"> | <syntaxhighlight lang="autoit"> | ||
Line 27: | Line 32: | ||
</syntaxhighlight> | </syntaxhighlight> | ||
===== | [[#top | ReturnToContents]] | ||
== DropFiles == | |||
{{Snippet Header | |||
| AuthorURL = 35302-guinness | |||
| AuthorName = guinness | |||
| Desc = Dropping multiple files onto a GUI | |||
}} | |||
<syntaxhighlight lang="autoit"> | <syntaxhighlight lang="autoit"> | ||
Line 81: | Line 94: | ||
EndSwitch | EndSwitch | ||
Return $GUI_RUNDEFMSG | Return $GUI_RUNDEFMSG | ||
EndFunc ;==>WM_DROPFILES</syntaxhighlight> | EndFunc ;==>WM_DROPFILES | ||
</syntaxhighlight> | |||
===== | [[#top | ReturnToContents]] | ||
== _ExitCheckTextChange == | |||
{{Snippet Header | |||
| AuthorURL = 8007-negativenrg | |||
| AuthorName = NegativeNrG | |||
}} | |||
<syntaxhighlight lang="autoit"> | <syntaxhighlight lang="autoit"> | ||
Line 108: | Line 129: | ||
</syntaxhighlight> | </syntaxhighlight> | ||
===== | [[#top | ReturnToContents]] | ||
== _FileDeleteEx == | |||
{{Snippet Header | |||
| AuthorURL = 35302-guinness | |||
| AuthorName = guinness | |||
}} | |||
<syntaxhighlight lang="autoit"> | <syntaxhighlight lang="autoit"> | ||
Line 127: | Line 155: | ||
</syntaxhighlight> | </syntaxhighlight> | ||
===== | [[#top | ReturnToContents]] | ||
== _FileCheck == | |||
{{Snippet Header | |||
| AuthorURL = 35302-guinness | |||
| AuthorName = guinness | |||
}} | |||
<syntaxhighlight lang="autoit"> | <syntaxhighlight lang="autoit"> | ||
Line 145: | Line 180: | ||
</syntaxhighlight> | </syntaxhighlight> | ||
===== | [[#top | ReturnToContents]] | ||
== _FileCreateEx == | |||
{{Snippet Header | |||
| AuthorURL = 35302-guinness | |||
| AuthorName = guinness | |||
}} | |||
<syntaxhighlight lang="autoit"> | <syntaxhighlight lang="autoit"> | ||
Line 156: | Line 198: | ||
</syntaxhighlight> | </syntaxhighlight> | ||
===== | [[#top | ReturnToContents]] | ||
== _FileID == | |||
{{Snippet Header | |||
| AuthorURL = 35302-guinness | |||
| AuthorName = guinness | |||
}} | |||
<syntaxhighlight lang="autoit"> | <syntaxhighlight lang="autoit"> | ||
Line 178: | Line 227: | ||
</syntaxhighlight> | </syntaxhighlight> | ||
===== | [[#top | ReturnToContents]] | ||
== _FileExistsWithQuotes == | |||
{{Snippet Header | |||
| AuthorURL = 35302-guinness | |||
| AuthorName = guinness | |||
}} | |||
<syntaxhighlight lang="autoit"> | <syntaxhighlight lang="autoit"> | ||
ConsoleWrite(_FileExistsWithQuotes('"' & @ScriptDir & '"') & @CRLF) | ConsoleWrite(_FileExistsWithQuotes('"' & @ScriptDir & '"') & @CRLF) | ||
Line 190: | Line 247: | ||
EndFunc ;==>_FileExistsWithQuotes | EndFunc ;==>_FileExistsWithQuotes | ||
</syntaxhighlight> | </syntaxhighlight> | ||
===== | [[#top | ReturnToContents]] | ||
== FileLineCount == | |||
{{Snippet Header | |||
| AuthorURL = 71214-mkish | |||
| AuthorName = MKISH | |||
| Desc = Checks the number of lines in a file (useful for larger files as well) | |||
}} | |||
<syntaxhighlight lang="autoit"> | <syntaxhighlight lang="autoit"> | ||
;Author-MKISH | ; Author - MKISH | ||
;Checks the number of lines in a file (useful for larger files as well) | ; Checks the number of lines in a file (useful for larger files as well) | ||
#include <WinAPI.au3> | #include <WinAPI.au3> | ||
Local $FILE = "G:\WIN7\sources\boot.wim" | Local $FILE = "G:\WIN7\sources\boot.wim" | ||
Local $COUNT = 0 | Local $COUNT = 0 | ||
Line 205: | Line 271: | ||
While 1 | While 1 | ||
$res = _HexSearch($FILE, StringToBinary("" & @crlf), $start) | $res = _HexSearch($FILE, StringToBinary("" & @crlf), $start) | ||
$start = $res + 2 | $start = $res + 2 | ||
$COUNT = $COUNT + 1 | $COUNT = $COUNT + 1 | ||
If $res = -1 then exitloop | If $res = -1 then exitloop | ||
Wend | Wend | ||
msgbox(64, "", "Lines count: " & $COUNT) | msgbox(64, "", "Lines count: " & $COUNT) | ||
; _HexSearch function (originally written by Zinthose, modified by MKISH) | |||
Func _HexSearch($FilePath, $BinaryValue, $StartOffset = Default) | Func _HexSearch($FilePath, $BinaryValue, $StartOffset = Default) | ||
Local $Buffer, $ptr, $hFile, $Result, $Read, $SearchValue, $Pos, $BufferSize = 2048 | Local $Buffer, $ptr, $hFile, $Result, $Read, $SearchValue, $Pos, $BufferSize = 2048 | ||
Line 250: | Line 317: | ||
EndIf | EndIf | ||
$Pos += $Read | $Pos += $Read | ||
WEnd | WEnd | ||
_WinAPI_CloseHandle($hFile) | _WinAPI_CloseHandle($hFile) | ||
Line 258: | Line 325: | ||
EndFunc; ==> _HexSearch | EndFunc; ==> _HexSearch | ||
</syntaxhighlight> | </syntaxhighlight> | ||
===== | [[#top | ReturnToContents]] | ||
== _FileOpenDialog == | |||
{{Snippet Header | |||
| AuthorURL = 35302-guinness | |||
| AuthorName = guinness | |||
}} | |||
<syntaxhighlight lang="autoit"> | <syntaxhighlight lang="autoit"> | ||
Local $sFilePath = _FileOpenDialog("", "", "Images (*.jpg;*.bmp)|Videos (*.avi;*.mpg)", Random(1, @DesktopWidth, 1), Random(1, @DesktopHeight, 1), 1 + 4, "") | Local $sFilePath = _FileOpenDialog("", "", "Images (*.jpg;*.bmp)|Videos (*.avi;*.mpg)", Random(1, @DesktopWidth, 1), Random(1, @DesktopHeight, 1), 1 + 4, "") | ||
ConsoleWrite('File = ' & $sFilePath & ', @error = ' & @error & @CRLF) | ConsoleWrite('File = ' & $sFilePath & ', @error = ' & @error & @CRLF) | ||
Line 293: | Line 367: | ||
</syntaxhighlight> | </syntaxhighlight> | ||
===== | [[#top | ReturnToContents]] | ||
== _GetFolderDepth == | |||
{{Snippet Header | |||
| AuthorURL = 35302-guinness | |||
| AuthorName = guinness | |||
}} | |||
<syntaxhighlight lang="autoit"> | <syntaxhighlight lang="autoit"> | ||
; Autoit 3.3.5.4 and Below | ; Autoit 3.3.5.4 and Below | ||
Line 309: | Line 391: | ||
EndFunc ;==>_GetFolderDepth | EndFunc ;==>_GetFolderDepth | ||
</syntaxhighlight> | </syntaxhighlight> | ||
===== | [[#top | ReturnToContents]] | ||
== _GetFolderDepth == | |||
{{Snippet Header | |||
| AuthorURL = 35302-guinness | |||
| AuthorName = guinness | |||
}} | |||
<syntaxhighlight lang="autoit"> | <syntaxhighlight lang="autoit"> | ||
; Autoit 3.3.5.4 and Above | ; Autoit 3.3.5.4 and Above | ||
Line 326: | Line 415: | ||
EndFunc ;==>_GetFolderDepth | EndFunc ;==>_GetFolderDepth | ||
</syntaxhighlight> | </syntaxhighlight> | ||
===== | [[#top | ReturnToContents]] | ||
== _IsDir == | |||
{{Snippet Header | |||
| AuthorURL = 35302-guinness | |||
| AuthorName = guinness | |||
}} | |||
<syntaxhighlight lang="autoit"> | <syntaxhighlight lang="autoit"> | ||
Line 339: | Line 434: | ||
Return Number(FileExists($sFilePath) And StringInStr(FileGetAttrib($sFilePath), "D", 2, 1) > 0) | Return Number(FileExists($sFilePath) And StringInStr(FileGetAttrib($sFilePath), "D", 2, 1) > 0) | ||
EndFunc ;==>IsDir | EndFunc ;==>IsDir | ||
</syntaxhighlight> | |||
[[#top | ReturnToContents]] | |||
== _IsFile == | |||
{{Snippet Header | |||
| AuthorURL = 35302-guinness | |||
| AuthorName = guinness | |||
}} | |||
<syntaxhighlight lang="autoit"> | |||
Func IsFile($sFilePath) | Func IsFile($sFilePath) | ||
Return Number(FileExists($sFilePath) And StringInStr(FileGetAttrib($sFilePath), "D", 2, 1) = 0) | Return Number(FileExists($sFilePath) And StringInStr(FileGetAttrib($sFilePath), "D", 2, 1) = 0) | ||
Line 345: | Line 451: | ||
</syntaxhighlight> | </syntaxhighlight> | ||
===== | [[#top | ReturnToContents]] | ||
== _IsFileDiff == | |||
{{Snippet Header | |||
| AuthorURL = 35302-guinness | |||
| AuthorName = guinness | |||
}} | |||
<syntaxhighlight lang="autoit"> | <syntaxhighlight lang="autoit"> | ||
Line 357: | Line 470: | ||
</syntaxhighlight> | </syntaxhighlight> | ||
===== | [[#top | ReturnToContents]] | ||
== _IsFileOlder == | |||
{{Snippet Header | |||
| AuthorURL = 35302-guinness | |||
| AuthorName = guinness | |||
}} | |||
<syntaxhighlight lang="autoit"> | <syntaxhighlight lang="autoit"> | ||
#include <Date.au3> ; Required for _DateDiff() | #include <Date.au3> ; Required for _DateDiff() | ||
Line 374: | Line 495: | ||
EndFunc ;==>_IsFileOlder | EndFunc ;==>_IsFileOlder | ||
</syntaxhighlight> | </syntaxhighlight> | ||
===== | [[#top | ReturnToContents]] | ||
== _IsFileSame == | |||
{{Snippet Header | |||
| AuthorURL = 35302-guinness | |||
| AuthorName = guinness | |||
}} | |||
<syntaxhighlight lang="autoit"> | <syntaxhighlight lang="autoit"> | ||
Line 388: | Line 515: | ||
</syntaxhighlight> | </syntaxhighlight> | ||
===== | [[#top | ReturnToContents]] | ||
== _IniReadFile == | |||
{{Snippet Header | |||
| AuthorURL = 35302-guinness | |||
| AuthorName = guinness | |||
}} | |||
<syntaxhighlight lang="autoit"> | <syntaxhighlight lang="autoit"> | ||
Line 448: | Line 582: | ||
</syntaxhighlight> | </syntaxhighlight> | ||
===== | [[#top | ReturnToContents]] | ||
== _IniReadInit == | |||
{{Snippet Header | |||
| AuthorURL = 9370-mlowery | |||
| AuthorName = mlowery | |||
}} | |||
<syntaxhighlight lang="autoit"> | <syntaxhighlight lang="autoit"> | ||
Line 474: | Line 615: | ||
</syntaxhighlight> | </syntaxhighlight> | ||
===== | [[#top | ReturnToContents]] | ||
== _IsValidFileType == | |||
{{Snippet Header | |||
| AuthorURL = 35302-guinness | |||
| AuthorName = guinness | |||
}} | |||
<syntaxhighlight lang="autoit"> | <syntaxhighlight lang="autoit"> | ||
Line 487: | Line 635: | ||
</syntaxhighlight> | </syntaxhighlight> | ||
Example 2 | <syntaxhighlight lang="autoit"> | ||
; Example 2 | |||
#include <WinAPIEx.au3> | #include <WinAPIEx.au3> | ||
Line 504: | Line 652: | ||
</syntaxhighlight> | </syntaxhighlight> | ||
== | [[#top | ReturnToContents]] | ||
== File Open/Save/Folder Dialog Box == | |||
{{Snippet Header | |||
| AuthorURL = 2709-mhz | |||
| AuthorName = MHz | |||
| AuthorURL2 = 4997-odklizec | |||
| AuthorName2 = odklizec | |||
| AuthorURL3 = 6756-danny35d | |||
| AuthorName3 = Danny35d | |||
}} | |||
<syntaxhighlight lang="autoit"> | <syntaxhighlight lang="autoit"> | ||
Line 547: | Line 706: | ||
</syntaxhighlight> | </syntaxhighlight> | ||
===== | [[#top | ReturnToContents]] | ||
== _MoveFileOnReboot == | |||
{{Snippet Header | |||
| AuthorURL = 44525-jscript | |||
| AuthorName = JScript | |||
}} | |||
<syntaxhighlight lang="autoit"> | <syntaxhighlight lang="autoit"> | ||
;Author: JScript - Snippet Version No. = 1.0 | ;Author: JScript - Snippet Version No. = 1.0 | ||
Line 555: | Line 722: | ||
Func _MoveFileOnReboot($sSourcePath, $sDestPath = ""); If $sDestPath = "" the file is deleted instead of moved. | Func _MoveFileOnReboot($sSourcePath, $sDestPath = ""); If $sDestPath = "" the file is deleted instead of moved. | ||
Local $iRet | Local $iRet | ||
; PendingFileRenameOperations (HKLM\SYSTEM\CurrentControlSet\Control\Session Manager) | ; PendingFileRenameOperations (HKLM\SYSTEM\CurrentControlSet\Control\Session Manager) | ||
If $DestPath = "" Then | If $DestPath = "" Then | ||
Line 566: | Line 733: | ||
EndFunc ;==>_MoveFileOnReboot | EndFunc ;==>_MoveFileOnReboot | ||
</syntaxhighlight> | </syntaxhighlight> | ||
===== | [[#top | ReturnToContents]] | ||
== _MultipleFileOpenDialog == | |||
{{Snippet Header | |||
| AuthorURL = | |||
| AuthorName = /dev/null | |||
}} | |||
<syntaxhighlight lang="autoit"> | <syntaxhighlight lang="autoit"> | ||
Local $message = "Hold down Ctrl or Shift to choose multiple files." | Local $message = "Hold down Ctrl or Shift to choose multiple files." | ||
Line 612: | Line 784: | ||
</syntaxhighlight> | </syntaxhighlight> | ||
===== | [[#top | ReturnToContents]] | ||
== _OpenFolder == | |||
{{Snippet Header | |||
| AuthorURL = 35302-guinness | |||
| AuthorName = guinness | |||
}} | |||
<syntaxhighlight lang="autoit"> | <syntaxhighlight lang="autoit"> | ||
Line 671: | Line 850: | ||
</syntaxhighlight> | </syntaxhighlight> | ||
===== | [[#top | ReturnToContents]] | ||
== _PathAppendToFilename == | |||
{{Snippet Header | |||
| AuthorURL = 31965-progandy | |||
| AuthorName = ProgAndy | |||
}} | |||
<syntaxhighlight lang="autoit"> | <syntaxhighlight lang="autoit"> | ||
Line 688: | Line 874: | ||
Return StringRegExpReplace($sName, "(\.[^\\/\.]+)$", $sAppend & "\1", 1) | Return StringRegExpReplace($sName, "(\.[^\\/\.]+)$", $sAppend & "\1", 1) | ||
EndFunc | EndFunc | ||
</syntaxhighlight> | |||
[[#top | ReturnToContents]] | |||
== _PathStripRightFromFilename == | |||
{{Snippet Header | |||
| AuthorURL = 31965-progandy | |||
| AuthorName = ProgAndy | |||
}} | |||
<syntaxhighlight lang="autoit"> | |||
Func _PathStripRightFromFilename($sName, $sStrip) | Func _PathStripRightFromFilename($sName, $sStrip) | ||
; Author: ProgAndy | ; Author: ProgAndy | ||
Line 696: | Line 893: | ||
</syntaxhighlight> | </syntaxhighlight> | ||
===== | [[#top | ReturnToContents]] | ||
== _SelfDelete == | |||
{{Snippet Header | |||
| AuthorURL = 2709-mhz | |||
| AuthorName = MHz | |||
}} | |||
<syntaxhighlight lang="autoit"> | <syntaxhighlight lang="autoit"> | ||
Line 717: | Line 921: | ||
</syntaxhighlight> | </syntaxhighlight> | ||
===== | [[#top | ReturnToContents]] | ||
== _ShellExecuteFileSelectFolder == | |||
{{Snippet Header | |||
| AuthorURL = 35302-guinness | |||
| AuthorName = guinness | |||
}} | |||
<syntaxhighlight lang="autoit"> | <syntaxhighlight lang="autoit"> | ||
Line 733: | Line 944: | ||
</syntaxhighlight> | </syntaxhighlight> | ||
===== | [[#top | ReturnToContents]] | ||
== _SuiCide == | |||
{{Snippet Header | |||
| AuthorURL = 28010-larrydalooza | |||
| AuthorName = LarryDalooza | |||
}} | |||
<syntaxhighlight lang="autoit"> | <syntaxhighlight lang="autoit"> | ||
Line 749: | Line 967: | ||
</syntaxhighlight> | </syntaxhighlight> | ||
===== | [[#top | ReturnToContents]] | ||
== _UniqueFilename == | |||
{{Snippet Header | |||
| AuthorURL = 35302-guinness | |||
| AuthorName = guinness | |||
}} | |||
<syntaxhighlight lang="autoit"> | <syntaxhighlight lang="autoit"> | ||
Line 771: | Line 996: | ||
</syntaxhighlight> | </syntaxhighlight> | ||
== | [[#top | ReturnToContents]] | ||
== Windows - Copy With Progress == | |||
{{Snippet Header | |||
| AuthorURL = 19-jos | |||
| AuthorName = Jos | |||
}} | |||
<syntaxhighlight lang="autoit"> | <syntaxhighlight lang="autoit"> | ||
; Windows - Copy With Progress | ; Windows - Copy With Progress | ||
;~ 4 Do not display a progress dialog box. | ;~ 4 Do not display a progress dialog box. | ||
;~ 8 Give the file being operated on a new name in a move, copy, or rename operation if a file with the target name already exists. | ;~ 8 Give the file being operated on a new name in a move, copy, or rename operation if a file with the target name already exists. | ||
;~ 16 Respond with "Yes to All" for any dialog box that is displayed. | ;~ 16 Respond with "Yes to All" for any dialog box that is displayed. | ||
;~ 64 Preserve undo information, if possible. | ;~ 64 Preserve undo information, if possible. | ||
;~ 128 Perform the operation on files only if a wildcard file name (*.*) is specified. | ;~ 128 Perform the operation on files only if a wildcard file name (*.*) is specified. | ||
;~ 256 Display a progress dialog box but do not show the file names. | ;~ 256 Display a progress dialog box but do not show the file names. | ||
;~ 512 Do not confirm the creation of a new directory if the operation requires one to be created. | ;~ 512 Do not confirm the creation of a new directory if the operation requires one to be created. | ||
;~ 1024 Do not display a user interface if an error occurs. | ;~ 1024 Do not display a user interface if an error occurs. | ||
;~ 2048 Version 4.71. Do not copy the security attributes of the file. | ;~ 2048 Version 4.71. Do not copy the security attributes of the file. | ||
;~ 4096 Only operate in the local directory. Don't operate recursively into subdirectories. | ;~ 4096 Only operate in the local directory. Don't operate recursively into subdirectories. | ||
;~ 8192 Version 5.0. Do not copy connected files as a group. Only copy the specified files. | ;~ 8192 Version 5.0. Do not copy connected files as a group. Only copy the specified files. | ||
_FileCopy("C:\Installed Apps\Patches\WindowsXP-KB835935-SP2-ENU.exe","C:\temp") | _FileCopy("C:\Installed Apps\Patches\WindowsXP-KB835935-SP2-ENU.exe","C:\temp") | ||
Line 792: | Line 1,024: | ||
; to copy a directory the destination directory must exist | ; to copy a directory the destination directory must exist | ||
Func _FileCopy($fromFile,$tofile) | Func _FileCopy($fromFile,$tofile) | ||
Local $FOF_RESPOND_YES = 16 | Local $FOF_RESPOND_YES = 16 | ||
Local $FOF_SIMPLEPROGRESS = 256 | Local $FOF_SIMPLEPROGRESS = 256 | ||
Line 799: | Line 1,031: | ||
EndFunc | EndFunc | ||
</syntaxhighlight> | </syntaxhighlight> | ||
[[#top | ReturnToContents]] |
Revision as of 17:23, 18 November 2012
_ConvertFileToUTF16
Author: guinness
_ConvertFileToUTF16(@ScriptDir & "\Example.xml")
Func _ConvertFileToUTF16($sFilePath)
Local $iEncoding = FileGetEncoding($sFilePath)
Local $hFileOpen = FileOpen($sFilePath, $iEncoding)
If $hFileOpen = -1 Then
Return SetError(1, 0, 0)
EndIf
Local $sData = FileRead($hFileOpen)
FileClose($hFileOpen)
$hFileOpen = FileOpen($sFilePath, 2 + 32)
If $hFileOpen = -1 Then
Return SetError(2, 0, 0)
EndIf
FileWrite($hFileOpen, $sData)
Return FileClose($hFileOpen)
EndFunc ;==>_ConvertFileToUTF16
DropFiles
Author: guinness
Dropping multiple files onto a GUI
; Dropping multiple files onto a GUI
#include <APIConstants.au3>
#include <Array.au3>
#include <GUIConstantsEx.au3>
#include <WinAPIEx.au3>
Global $__aDropFiles
Example()
Func Example()
Local $hGUI = GUICreate('', 500, 500, -1, -1, -1, $WS_EX_ACCEPTFILES)
; Create a label that is transparent which will accept 'drop' events.
GUICtrlCreateLabel("", 0, 0, 500, 500)
GUICtrlSetBkColor(-1, $GUI_BKCOLOR_TRANSPARENT)
GUICtrlSetResizing(-1, $GUI_DOCKALL)
GUICtrlSetState(-1, $GUI_DROPACCEPTED)
GUIRegisterMsg($WM_DROPFILES, "WM_DROPFILES")
GUISetState(@SW_SHOW, $hGUI)
While 1
Switch GUIGetMsg()
Case $GUI_EVENT_CLOSE
ExitLoop
Case $GUI_EVENT_DROPPED
If $__aDropFiles[0] > 0 Then
_ArrayDisplay($__aDropFiles)
EndIf
EndSwitch
WEnd
GUIDelete($hGUI)
EndFunc ;==>Example
Func WM_DROPFILES($hWnd, $iMsg, $iwParam, $ilParam)
#forceref $hWnd, $ilParam
Switch $iMsg
Case $WM_DROPFILES
Local $aReturn = _WinAPI_DragQueryFileEx($iwParam)
If IsArray($aReturn) Then
Local $aError[1] = [0]
$__aDropFiles = $aReturn
Else
$__aDropFiles = $aError
EndIf
EndSwitch
Return $GUI_RUNDEFMSG
EndFunc ;==>WM_DROPFILES
_ExitCheckTextChange
Author: NegativeNrG
;Check(when Exit), if Text is not equal to $e_to Then, prompt the user to save or not save.
;_ExitCheckText Change $Edit Handle, $title of messagebox, $message of messagebox, $equal to(default = NULL).
Func _ExitCheckTextChange($E_hnd,$title,$message,$e_to = '')
Local $buffer, $choice, $filetosave, $handle1
$buffer = GUIctrlread($E_hnd)
If $buffer <> $e_to Then
$choice = Msgbox(4,$title,$message)
If $choice = 6 Then
$filetosave = FileSaveDialog('Choose File',@scriptdir,'(*.au3)')
$handle1 = FileOpen($filetosave,2)
FileWrite($handle1,$buffer)
Exit
Elseif $choice <> 6 Then
Exit
EndIf
Else
Exit
EndIf
EndFunc
_FileDeleteEx
Author: guinness
; Ref: http://msdn.microsoft.com/en-us/library/windows/desktop/aa365240(v=vs.85).aspx
#include <APIConstants.au3> ; Included with WinAPIEx.au3
#include <WinAPIEx.au3> ; Download From http://www.autoitscript.com/forum/topic/98712-winapiex-udf/ by Yashied.
ConsoleWrite(_FileDeleteEx("C:\Example.dat") & @LF)
Func _FileDeleteEx($sFilePath)
Local $iReturn = FileDelete($sFilePath)
If $iReturn Then
Return $iReturn
EndIf
Return _WinAPI_MoveFileEx(FileGetShortName($sFilePath), "", $MOVE_FILE_DELAY_UNTIL_REBOOT)
EndFunc ;==>_FileDeleteEx
_FileCheck
Author: guinness
#include <Date.au3>
; Check if the file was modified less than 24 hours ago.
ConsoleWrite( _FileCheck(@ScriptFullPath, 24) & @CRLF)
Func _FileCheck($sFilePath, $iHours = 24)
Local $aTime
If FileExists($sFilePath) = 0 Then
Return SetError(1, 0, 0)
EndIf
$aTime = FileGetTime($sFilePath, 0, 0)
Return Number(_DateDiff("h", $aTime[0] & "/" & $aTime[1] & "/" & $aTime[2] & " " & $aTime[3] & ":" & $aTime[4] & ":" & $aTime[5], @YEAR & "/" & @MON & "/" & @MDAY & " " & @HOUR & ":" & @MIN & ":" & @SEC) < $iHours)
EndFunc ;==>_FileCheck
_FileCreateEx
Author: guinness
_FileCreateEx(@ScriptDir & '\ExampleFile.txt', 42)
; Create a blank file with a certain size in bytes.
Func _FileCreateEx($sFilePath, $iBytes = 0)
Return RunWait(@ComSpec & ' /c fsutil file createnew "' & $sFilePath & '" ' & Int($iBytes), @WorkingDir, @SW_HIDE)
EndFunc ;==>_FileCreateEx
_FileID
Author: guinness
#include <Constants.au3>
FileClose(FileOpen(@ScriptDir & '\ExampleFile.txt', 2))
ConsoleWrite(_FileID(@ScriptDir & '\ExampleFile.txt') & @CRLF)
FileDelete(@ScriptDir & '\ExampleFile.txt')
; Rerieve the file id of a filepath.
Func _FileID($sFilePath)
Local $iPID = Run(@ComSpec & ' /c fsutil file queryfileid "' & $sFilePath & '"', @SystemDir, @SW_HIDE, $STDOUT_CHILD + $STDERR_CHILD), $sReturn = ''
While 1
$sReturn &= StdoutRead($iPID)
If @error Then
ExitLoop
EndIf
WEnd
Return StringStripWS(StringRegExpReplace($sReturn, 'File\sID\sis\s(.*?)', '$1'), 8)
EndFunc ;==>_FileID
_FileExistsWithQuotes
Author: guinness
ConsoleWrite(_FileExistsWithQuotes('"' & @ScriptDir & '"') & @CRLF)
ConsoleWrite(_FileExistsWithQuotes("'" & @ScriptDir & "'") & @CRLF)
ConsoleWrite(_FileExistsWithQuotes(@ScriptDir) & @CRLF)
; Version: 1.00. AutoIt: V3.3.8.1
; Check a filepath ecists even if the path contains quotation marks.
Func _FileExistsWithQuotes($sFilePath)
Return FileExists(StringRegExpReplace($sFilePath, '^("|'')*([^"'']+)("|'')*$', '\2'))
EndFunc ;==>_FileExistsWithQuotes
FileLineCount
Author: MKISH
Checks the number of lines in a file (useful for larger files as well)
; Author - MKISH
; Checks the number of lines in a file (useful for larger files as well)
#include <WinAPI.au3>
Local $FILE = "G:\WIN7\sources\boot.wim"
Local $COUNT = 0
Local $start = default
Local $res, $fLen, $err
While 1
$res = _HexSearch($FILE, StringToBinary("" & @crlf), $start)
$start = $res + 2
$COUNT = $COUNT + 1
If $res = -1 then exitloop
Wend
msgbox(64, "", "Lines count: " & $COUNT)
; _HexSearch function (originally written by Zinthose, modified by MKISH)
Func _HexSearch($FilePath, $BinaryValue, $StartOffset = Default)
Local $Buffer, $ptr, $hFile, $Result, $Read, $SearchValue, $Pos, $BufferSize = 2048
If $StartOffset = Default Then $StartOffset = 0
If Not FileExists($FilePath) Then Return SetError(1, @error, 0)
$fLen = FileGetSize($FilePath)
If $StartOffset > $fLen Then Return SetError(2, @error, 0)
If Not IsBinary($BinaryValue) Then Return SetError(3, @error, 0)
If Not IsNumber($StartOffset) Then Return SetError(4, @error, 0)
$SearchValue = BinaryToString($BinaryValue)
$Buffer = DllStructCreate("byte[" & $BufferSize & "]")
$ptr = DllStructGetPtr($Buffer)
$hFile = _WinAPI_CreateFile($FilePath, 2, 2, 1)
If $hFile = 0 Then Return SetError(5, @error, 0)
$Result = _WinAPI_SetFilePointer($hFile, $StartOffset)
$err = @error
If $Result = 0xFFFFFFFF Then
_WinAPI_CloseHandle($hFile)
Return SetError(5, $err, 0)
EndIf
$Pos = $StartOffset
While True
$Read = 0
$Result = _WinAPI_ReadFile($hFile, $ptr, $BufferSize, $Read)
$err = @error
If Not $Result Then
_WinAPI_CloseHandle($hFile)
Return SetError(6, $err, 0)
EndIf
$Result = DllStructGetData($Buffer, 1)
$Result = BinaryToString($Result)
$Result = StringInStr($Result, $SearchValue)
If $Result > 0 Then ExitLoop
If $Read < $BufferSize Then
_WinAPI_CloseHandle($hFile)
Return -1
EndIf
$Pos += $Read
WEnd
_WinAPI_CloseHandle($hFile)
If Not $Result Then Return SetError(7, @error, 0)
$Result = $Pos + $Result - 1
Return $Result
EndFunc; ==> _HexSearch
_FileOpenDialog
Author: guinness
Local $sFilePath = _FileOpenDialog("", "", "Images (*.jpg;*.bmp)|Videos (*.avi;*.mpg)", Random(1, @DesktopWidth, 1), Random(1, @DesktopHeight, 1), 1 + 4, "")
ConsoleWrite('File = ' & $sFilePath & ', @error = ' & @error & @CRLF)
; #FUNCTION# ====================================================================================================================
; Name ..........: _FileOpenDialog
; Description ...: Initiates a Open File Dialog with the option to set the position of the GUI.
; Syntax ........: _FileOpenDialog($sTitle, $sIntitialDirectory, $sFilter[, $iLeft = -1[, $iTop = -1[, $iOptions = 0[,
; $sDefaultName = ""]]]])
; Parameters ....: $sTitle - Title text of the Dialog GUI.
; $sIntitialDirectory - Initial directory selected in the GUI file tree.
; $sFilter - File type single filter such as "All (*.*)" or "Text files (*.txt)".
; $iLeft - [optional] The left side of the dialog box. By default (-1), the window is centered.
; $iTop - [optional] The top of the dialog box. Default (-1) is centered
; $iOptions - [optional] Dialog Options: To use more than one option, add the required values together. See FileOpenDialog. Default is 0.
; $sDefaultName - [optional] Suggested file name for the user to open. Default is blank ("").
; Return values .: Success: Returns the full path of the file(s) chosen. Results for multiple selections are "Directory|file1|file2|..."
; Failure: Sets @error to non-zero.
; Author ........: guinness
; Remarks........: This doesn't change the working directory of the script like FileOpenDialog does.
; Example .......: Yes
; ===============================================================================================================================
Func _FileOpenDialog($sTitle, $sIntitialDirectory, $sFilter, $iLeft = -1, $iTop = -1, $iOptions = 0, $sDefaultName = "")
Local $hGUI = GUICreate('', -1, -1, $iLeft, $iTop), $sWorkingDir = @WorkingDir
Local $sFilePath = FileOpenDialog($sTitle, $sIntitialDirectory, $sFilter, $iOptions, $sDefaultName, $hGUI)
Local $iError = @error
FileChangeDir($sWorkingDir)
Return SetError($iError, GUIDelete($hGUI), $sFilePath)
EndFunc ;==>_FileOpenDialog()
_GetFolderDepth
Author: guinness
; Autoit 3.3.5.4 and Below
ConsoleWrite(_GetFolderDepth(@ScriptDir & '') & @CRLF)
ConsoleWrite(_GetFolderDepth(@ScriptDir) & @CRLF)
ConsoleWrite(_GetFolderDepth(@ScriptFullPath) & @CRLF)
; Get the folder depth of a filepath.
Func _GetFolderDepth($sFilePath)
If StringInStr($sFilePath, '.', 2, -1) Then
$sFilePath = StringLeft($sFilePath, StringInStr($sFilePath, "", 2, -1) - 1)
EndIf
Local $aArray = StringSplit(StringRegExpReplace($sFilePath, '[/]+z', ''), '')
Return $aArray[0] - 1
EndFunc ;==>_GetFolderDepth
_GetFolderDepth
Author: guinness
; Autoit 3.3.5.4 and Above
ConsoleWrite(_GetFolderDepth(@ScriptDir & '') & @CRLF)
ConsoleWrite(_GetFolderDepth(@ScriptDir) & @CRLF)
ConsoleWrite(_GetFolderDepth(@ScriptFullPath) & @CRLF)
; Get the folder depth of a filepath. Works with V3.3.5.4+
Func _GetFolderDepth($sFilePath)
If StringInStr($sFilePath, '.', 2, -1) Then
$sFilePath = StringLeft($sFilePath, StringInStr($sFilePath, "", 2, -1) - 1)
EndIf
Return StringSplit(StringRegExpReplace($sFilePath, '[/]+z', ''), '')[0] - 1
EndFunc ;==>_GetFolderDepth
_IsDir
Author: guinness
ConsoleWrite("IsDir: Using a file - " & IsDir(@ScriptFullPath) & @CRLF) ; Return 0
ConsoleWrite("IsFile: Using a file - " & IsFile(@ScriptFullPath) & @CRLF) ; Return 1
ConsoleWrite("IsDir: Using a directory - " & IsDir(@ScriptDir) & @CRLF) ; Return 1
ConsoleWrite("IsFile: Using a directory - " & IsFile(@ScriptDir) & @CRLF) ; Return 0
Func IsDir($sFilePath)
Return Number(FileExists($sFilePath) And StringInStr(FileGetAttrib($sFilePath), "D", 2, 1) > 0)
EndFunc ;==>IsDir
_IsFile
Author: guinness
Func IsFile($sFilePath)
Return Number(FileExists($sFilePath) And StringInStr(FileGetAttrib($sFilePath), "D", 2, 1) = 0)
EndFunc ;==>IsFile
_IsFileDiff
Author: guinness
ConsoleWrite(_IsFileDiff(@ScriptFullPath, @ScriptFullPath) & @CRLF) ; This will return False as the files are exactly the same.
ConsoleWrite(_IsFileDiff(@ScriptFullPath, @AutoItExe) & @CRLF) ; This will return True as the files are different.
; Check if a file is different.
Func _IsFileDiff($sFilePath_1, $sFilePath_2)
Return RunWait(@ComSpec & ' /c FC /B /W "' & $sFilePath_1 & '" "' & $sFilePath_2 & '"', @WorkingDir, @SW_HIDE) > 0
EndFunc ;==>_IsFileDiff
_IsFileOlder
Author: guinness
#include <Date.au3> ; Required for _DateDiff()
; Check if the current script is older than 10 days.
If _IsFileOlder(@ScriptFullPath, 10) Then
MsgBox(4096, '', 'File is older than 10 days.')
Else
MsgBox(4096, '', 'File isn''t older than 10 days.')
EndIf
; Is a file older than a certain number of days.
Func _IsFileOlder($sFilePath, $iDays)
Local $aArray = FileGetTime($sFilePath, 0)
Return _DateDiff('D', $aArray[0] & '/' & $aArray[1] & '/' & $aArray[2] & ' ' & $aArray[3] & ':' & $aArray[4] & ':' & $aArray[5], @YEAR & '/' & @MON & '/' & @MDAY & ' ' & @HOUR & ':' & @MIN & ':' & @SEC) >= $iDays
EndFunc ;==>_IsFileOlder
_IsFileSame
Author: guinness
ConsoleWrite(_IsFileSame(@ScriptFullPath, @ScriptFullPath) & @CRLF) ; This will return True as the files are exactly the same.
ConsoleWrite(_IsFileSame(@ScriptFullPath, @AutoItExe) & @CRLF) ; This will return False as the files are different.
; Check if a file is the same.
Func _IsFileSame($sFilePath_1, $sFilePath_2)
Return RunWait(@ComSpec & ' /c FC /B /W "' & $sFilePath_1 & '" "' & $sFilePath_2 & '"', @WorkingDir, @SW_HIDE) = 0
EndFunc ;==>_IsFileSame
_IniReadFile
Author: guinness
#include <Array.au3>
__INIFileFill(@ScriptDir & '\Example.ini') ; Create an INI file with random data.
Local $aArray = _IniReadFile(@ScriptDir & '\Example.ini')
FileDelete(@ScriptDir & '\Example.ini')
_ArrayDisplay($aArray)
Func _IniReadFile($sFilePath)
Local $aReturn[1][3] = [[0, 3]], $aSectionArray, $aSectionNameArray, $iCount = 0
$aSectionNameArray = IniReadSectionNames($sFilePath)
If @error Then
Return SetError(1, 0, $aReturn)
EndIf
For $A = 1 To $aSectionNameArray[0]
$aSectionArray = IniReadSection($sFilePath, $aSectionNameArray[$A])
If @error Then
ContinueLoop
EndIf
For $B = 1 To $aSectionArray[0][0]
$aReturn[0][0] += 1
$iCount += 1
If $aReturn[0][0] <= $iCount + 1 Then
ReDim $aReturn[$aReturn[0][0] * 2][$aReturn[0][1]]
EndIf
$aReturn[$iCount][0] = $aSectionArray[$B][0]
$aReturn[$iCount][1] = $aSectionArray[$B][1]
$aReturn[$iCount][2] = $aSectionNameArray[$A]
Next
Next
ReDim $aReturn[$aReturn[0][0] + 1][$aReturn[0][1]] ; Remove empty entries.
Return $aReturn
EndFunc ;==>_IniReadFile
Func __INIFileFill($sFilePath)
Local $sData = '', $sHeader = ''
For $i = 1 To Random(1, 5, 1)
$sHeader = _RandomText(Random(5, 25, 1))
$sData = ""
For $j = 1 To Random(1, 25, 1)
$sData &= _RandomText(Random(5, 25, 1)) & '=' & _RandomText(Random(5, 25, 1)) & @LF
Next
IniWriteSection($sFilePath, $sHeader, $sData)
Next
EndFunc ;==>__FillINIFile
Func _RandomText($iLength = 10)
Local $sData = '', $sRandom = ''
For $i = 1 To $iLength
$sRandom = Random(55, 116, 1)
$sData &= Chr($sRandom + 6 * ($sRandom > 90) - 7 * ($sRandom < 65))
Next
Return $sData
EndFunc ;==>_RandomText
_IniReadInit
Author: mlowery
;===============================================================================
; Description: Reads values from INI or creates INI with initial values.
; Intended to ensure all available INI settings are exposed
; and editable.
; Parameters are identical to IniRead()
; Parameter(s): $filename = filename of INI
; $section = section name of INI
; $key = key name in section
; $default = default value (written to INI if not exists)
; Requirement(s): None
; Return Value(s): Returns value from INI (or default if not defined)
; Note(s): Chr(127) used to detect non-existing value since won't normally exist in a text file
;===============================================================================
Func _IniReadInit($filename, $section, $key, $default)
Local $value = IniRead($filename, $section, $key, Chr(127))
If $value = Chr(127) Then
IniWrite($filename, $section, $key, $default)
$value = $default
EndIf
Return $value
EndFunc
_IsValidFileType
Author: guinness
ConsoleWrite(@ScriptFullPath & " >> " & _IsValidFileType(@ScriptFullPath, "bat;cmd;au3") & @CRLF)
ConsoleWrite(@AutoItExe & " >> " & _IsValidFileType(@AutoItExe, "bat;cmd;au3") & @CRLF)
; Check if a filepath matches an extension filetype. Based on the idea by guinness - http://www.autoitscript.com/forum/topic/123674-isvalidfiletype/
Func _IsValidFileType($sFilePath, $sList = "bat;cmd;exe") ; By AZJIO - http://www.autoitscript.com/forum/topic/...filetype/page__view__findpost_
Local $iDot = StringInStr($sFilePath, ".", 0, -1)
Return $iDot And StringInStr(';' & $sList & ';', ';' & StringTrimLeft($sFilePath, $iDot) & ';') > 0
EndFunc ;==>_IsValidFileType
; Example 2
#include <WinAPIEx.au3>
ConsoleWrite(@ScriptFullPath & " >> " & _IsValidFileType(@ScriptFullPath, "bat;cmd;au3") & @CRLF)
ConsoleWrite(@AutoItExe & " >> " & _IsValidFileType(@AutoItExe, "bat;cmd;au3") & @CRLF)
; Check if a filepath matches an extension filetype. Based on the idea by guinness - http://www.autoitscript.com/forum/topic/123674-isvalidfiletype/
Func _IsValidFileType($sFilePath, $sList = "bat;cmd;exe", $iOpFast = 1) ; By Yashied.
If StringStripWS($sList, 8) = "" Then
$sList = "*"
EndIf
Return _WinAPI_PathMatchSpec($sFilePath, StringReplace(';' & $sList, ';', ';*.', 0, $iOpFast * 2))
EndFunc ;==>_IsValidFileType
File Open/Save/Folder Dialog Box
Author: MHz
Author: odklizec
Author: Danny35d
; Center - File Open/Save/Folder Dialog Box
; Author - odklizec, MHz, Danny35d
If StringInStr($cmdlineraw, '/MoveWin') Then
Local $size, $PosX, $PosY
$cmdlineraw = StringSplit(StringMid($cmdlineraw, StringInStr($cmdlineraw, '/MoveWin')), ':')
While 1
Select
Case WinExists($cmdlineraw[2])
$size=WinGetPos ($cmdlineraw[2])
$PosX=@DesktopWidth/2 - $size[2]/2
$PosY=@DesktopHeight/2 - $size[3]/2
WinMove($cmdlineraw[2], "", $PosX, $PosY)
WinActivate($cmdlineraw[2])
ExitLoop
EndSelect
Sleep(50)
WEnd
Exit
EndIf
Global $PID, $Read_File, $Save_File
$PID = _FindBrowseWin('Open file Dialog Box')
$Read_File = FileOpenDialog ( "Open file Dialog Box", @ScriptDir & "\", "AutoIt Files (*.au3)",3,@ScriptFullPath)
ProcessClose($PID)
$PID = _FindBrowseWin('Save file Dialog Box')
$Save_File = FileSaveDialog( "Save file Dialog Box", @ScriptDir, "Scripts (*.aut;*.au3)", 3)
ProcessClose($PID)
$PID = _FindBrowseWin('Browse for Folder')
FileSelectFolder("Choose a folder with plugins..", "","4","c:\")
ProcessClose($PID)
Func _FindBrowseWin($sTitle)
If @Compiled Then
Return(Run(@ScriptFullPath & ' /MoveWin:' & $sTitle))
Else
Return(Run(@AutoItExe & ' "' & @ScriptFullPath & '" /MoveWin:' & $sTitle))
EndIf
EndFunc
_MoveFileOnReboot
Author: JScript
;Author: JScript - Snippet Version No. = 1.0
;Snippet was Created Using AutoIt Version = 3.3.2.0, Creation Date = 21/03/12.
; Function to Move or Delete a file on next reboot!
Func _MoveFileOnReboot($sSourcePath, $sDestPath = ""); If $sDestPath = "" the file is deleted instead of moved.
Local $iRet
; PendingFileRenameOperations (HKLM\SYSTEM\CurrentControlSet\Control\Session Manager)
If $DestPath = "" Then
$iRet = DllCall("kernel32.dll", "int", "MoveFileExA", "str", $sSourcePath, "int", 0, "dword", 4)
Else
$iRet = DllCall("kernel32.dll", "int", "MoveFileExA", "str", $sSourcePath, "str", $sDestPath, "dword", 4)
EndIf
Return $iRet
EndFunc ;==>_MoveFileOnReboot
_MultipleFileOpenDialog
/dev/null
Local $message = "Hold down Ctrl or Shift to choose multiple files."
Local $filename = _MultipleFileOpenDialog($message,300,300)
Local $var = FileOpenDialog($message, @WindowsDir & "\", "Images (*.jpg;*.bmp)", 1 + 4 )
If @error Then
MsgBox(4096,"","No File(s) chosen")
Else
$var = StringReplace($var, "|", @CRLF)
MsgBox(4096,"","You chose " & $var)
EndIf
FileDelete($filename)
func _MultipleFileOpenDialog($title,$posx,$posy)
Local $temp = EnvGet("temp")
Local $filename = $temp & "\move_file_open_dialog.au3"
Local $script = 'Global $title = "' & $title & '"' & @CRLF
$script &= 'Global $pos_x = ' & $posx & @CRLF
$script &= 'Global $pos_y = ' & $posy & @CRLF
$script &= 'AdlibRegister("_Move",10)' & @CRLF
$script &= 'while 1' & @CRLF
$script &= ' sleep(1000)' & @CRLF
$script &= 'wend' & @CRLF
$script &= 'Func _Move()' & @CRLF
$script &= ' if (WinActive($title)) Then' & @CRLF
$script &= ' WinMove($title,"",$pos_x,$pos_y)' & @CRLF
$script &= ' Exit' & @CRLF
$script &= ' EndIf' & @CRLF
$script &= 'EndFunc' & @CRLF
FileWrite($filename,$script)
;MsgBox(0,"",$script & @CRLF & $filename)
Run(@AutoItExe & " /AutoIt3ExecuteScript " & $filename)
sleep(250)
Return $filename
EndFunc ;==>_MultipleFileOpenDialog()
_OpenFolder
Author: guinness
#cs
These have been declared in Global scope as you may wish to use them elsewhere in your script.
#ce
Global $ALTSTARTUP = 0x1d
Global $APPDATA = 0x1a
Global $BITBUCKET = 0x0a
Global $COMMONALTSTARTUP = 0x1e
Global $COMMONAPPDATA = 0x23
Global $COMMONDESKTOPDIR = 0x19
Global $COMMONFAVORITES = 0x1f
Global $COMMONPROGRAMS = 0x17
Global $COMMONSTARTMENU = 0x16
Global $COMMONSTARTUP = 0x18
Global $CONTROLS = 0x03
Global $COOKIES = 0x21
Global $DESKTOP = 0x00
Global $DESKTOPDIRECTORY = 0x10
Global $DRIVES = 0x11
Global $FAVORITES = 0x06
Global $FONTS = 0x14
Global $HISTORY = 0x22
Global $INTERNETCACHE = 0x20
Global $LOCALAPPDATA = 0x1c
Global $MYPICTURES = 0x27
Global $NETHOOD = 0x13
Global $NETWORK = 0x12
Global $PERSONAL = 0x05
Global $PRINTERS = 0x04
Global $PRINTHOOD = 0x1b
Global $PROFILE = 0x28
Global $PROGRAMFILES = 0x26
Global $PROGRAMFILESx86 = 0x30
Global $PROGRAMS = 0x02
Global $RECENT = 0x08
Global $SENDTO = 0x09
Global $STARTMENU = 0x0b
Global $STARTUP = 0x07
Global $SYSTEM = 0x25
Global $SYSTEMx86 = 0x29
Global $TEMPLATES = 0x15
Global $WINDOWS = 0x24
ConsoleWrite(_OpenFolder(@ScriptDir) & @CRLF)
ConsoleWrite(_OpenFolder($PRINTERS) & @CRLF)
; Open a folder or special folder variable, similar to using ShellExecute.
Func _OpenFolder($sFolderPath)
Local $oShell = ObjCreate('shell.application')
If @error Then
Return SetError(1, 0, 0)
EndIf
$oShell.Open($sFolderPath)
Return 1
EndFunc ;==>_OpenFolder
_PathAppendToFilename
Author: ProgAndy
$sOrg = "C:\Some.Folder\some.file.ext"
$sAdd = "_backup"
$sNew = _PathAppendToFilename($sOrg, $sAdd)
$sStripped = _PathStripRightFromFilename($sNew, $sAdd)
MsgBox(0, "", $sOrg & @CRLF & $sAdd & @CRLF & $sNew & @CRLF & $sStripped)
Func _PathAppendToFilename($sName, $sAppend)
; Author: ProgAndy
If StringRegExp($sAppend, '[\/\\:\?"<>\|\*]') Then Return SetError(1, 0, $sName)
Return StringRegExpReplace($sName, "(\.[^\\/\.]+)$", $sAppend & "\1", 1)
EndFunc
_PathStripRightFromFilename
Author: ProgAndy
Func _PathStripRightFromFilename($sName, $sStrip)
; Author: ProgAndy
If StringRegExp($sStrip, '[\/\\:\?"<>\|\*]') Then Return SetError(1, 0, $sName)
Return StringRegExpReplace($sName, "\Q" & $sStrip & "\E(\.[^\\/\.]+)$", "\1", 1)
EndFunc
_SelfDelete
Author: MHz
; This also removes the directory which the file is in
; Author MHz with the directory delete addition by The Kandie Man
Func _SelfDelete($iDelay = 0)
Local $sCmdFile
FileDelete(@TempDir & "\scratch.bat")
$sCmdFile = 'ping -n ' & $iDelay & '127.0.0.1 > nul' & @CRLF _
& ':loop' & @CRLF _
& 'del "' & @ScriptFullPath & '"' & @CRLF _
& 'if exist "' & @ScriptFullPath & '" goto loop' & @CRLF _
& ':loop2' & @CRLF _
& 'rmdir /q "' & $dirToDelete & '"' & @CRLF _
& 'if exist "' & $dirToDelete & '" goto loop2' & @CRLF _
& 'del ' & @TempDir & '\scratch.bat'
FileWrite(@TempDir & "\scratch.bat", $sCmdFile)
Run(@TempDir & "\scratch.bat", @TempDir, @SW_HIDE)
EndFunc
_ShellExecuteFileSelectFolder
Author: guinness
ConsoleWrite(_ShellExecuteFileSelectFolder('Select a Folder', @HomeDrive) & @CRLF)
; Shell Execute a selected folder.
Func _ShellExecuteFileSelectFolder($sText, $sRoot, $iFlag = 0, $sInitialDir = '', $hWnd = '')
Local $sFolder = FileSelectFolder($sText, $sRoot, $iFlag, $sInitialDir, $hWnd)
If @error Then
Return SetError(@error, @extended, '')
EndIf
ShellExecute($sFolder)
Return $sFolder
EndFunc ;==>_ShellExecuteFileSelectFolder
_SuiCide
Author: LarryDalooza
; IMPORTANT MAKE A COPY OF SCRIPT BEFORE DELETION
; Deletes the running script
Func SuiCide()
Local $sFilePath = @TempDir & '\SuiCide.bat'
FileDelete($sFilePath)
FileWrite($sFilePath, 'loop:' & @CRLF & 'del "' & @ScriptFullPath & '"' & @CRLF & _
'ping -n 1 -w 250 zxywqxz_q' & @CRLF & 'if exist "' & @ScriptFullPath & _
'" goto loop' & @CRLF & 'del SuiCide.bat' & @CRLF)
Exit Run($sFilePath, @TempDir, @SW_HIDE)
EndFunc ;==>SuiCide
_UniqueFilename
Author: guinness
ConsoleWrite(_UniqueFilename(@ScriptDir, '.au3') & @CRLF)
Func _UniqueFilename($sFilePath, $sExtension)
Local $iRandom = 0, $sUnqiueFileName = ''
$sExtension = '.' & StringRegExpReplace($sExtension, '\A[\.]+', '')
$sFilePath = StringRegExpReplace($sFilePath, '[\\/]+\z', '') & '\'
While 1
$iRandom = Random(55, 116, 1)
$sUnqiueFileName &= Chr($iRandom + 6 * ($iRandom > 90) - 7 * ($iRandom < 65))
If FileExists($sFilePath & $sUnqiueFileName & $sExtension) = 0 And StringLen($sUnqiueFileName) > 7 Then
ExitLoop
EndIf
WEnd
Return $sFilePath & $sUnqiueFileName & $sExtension
EndFunc ;==>_UniqueFilename
Windows - Copy With Progress
Author: Jos
; Windows - Copy With Progress
;~ 4 Do not display a progress dialog box.
;~ 8 Give the file being operated on a new name in a move, copy, or rename operation if a file with the target name already exists.
;~ 16 Respond with "Yes to All" for any dialog box that is displayed.
;~ 64 Preserve undo information, if possible.
;~ 128 Perform the operation on files only if a wildcard file name (*.*) is specified.
;~ 256 Display a progress dialog box but do not show the file names.
;~ 512 Do not confirm the creation of a new directory if the operation requires one to be created.
;~ 1024 Do not display a user interface if an error occurs.
;~ 2048 Version 4.71. Do not copy the security attributes of the file.
;~ 4096 Only operate in the local directory. Don't operate recursively into subdirectories.
;~ 8192 Version 5.0. Do not copy connected files as a group. Only copy the specified files.
_FileCopy("C:\Installed Apps\Patches\WindowsXP-KB835935-SP2-ENU.exe","C:\temp")
; to copy a directory the destination directory must exist
Func _FileCopy($fromFile,$tofile)
Local $FOF_RESPOND_YES = 16
Local $FOF_SIMPLEPROGRESS = 256
$winShell = ObjCreate("shell.application")
$winShell.namespace($tofile).CopyHere($fromFile,$FOF_RESPOND_YES)
EndFunc