Search the Community
Showing results for tags 'Directory'.
-
Using the FTP FTPEx.au3 makes communicating with FTP a breeze. With great functions like _FTP_FileGet, _FTP_FilePut, and _FTP_DirPutContents, you can upload and download with ease. But what about the much needed ability to download a folder with a simple _FTP_DirGetContents function? Well I put together a function that will download a folder with ease... _FTP_DirGetContents Function: Func _FTP_DirGetContents($oConn, $opath, $olocal, $orec) If Not FileExists($olocal) Then DirCreate($olocal) If StringRight($opath, 1) <> "/" Then $opath &= "/" If $orec == 1 Then Local $ocurrent = _FTP_DirGetCurrent($oConn) _FTP_DirSetCurrent($oConn, $opath) Local $afolders = _FTP_ListToArray($oConn, 1) _FTP_DirSetCurrent($oConn, $ocurrent) For $o = 1 To $afolders[0] If $afolders[$o] == "." Or $afolders[$o] == ".." Then ContinueLoop If Not FileExists($olocal & "\" & $afolders[$o]) Then DirCreate($olocal & "\" & $afolders[$o]) _FTP_DirGetContents($oConn, $opath & $afolders[$o], $olocal & "\" & $afolders[$o], $orec) Next EndIf Local $hFTPFind Local $aFile = _FTP_FindFileFirst($oConn, $opath, $hFTPFind) While 1 _FTP_FileGet($oConn, $opath & $aFile[10], @ScriptDir & "\tmpdata\" & $aFile[10]) $aFile = _FTP_FindFileNext($hFTPFind) If @error Then ExitLoop WEnd _FTP_FindFileClose($hFTPFind) EndFunc Example Usage: #include <FTPEx.au3> If Not FileExist(@ScriptDir & "\ftptemp") Then DirCreate(@ScriptDir & "\ftptemp") $dir_local = @ScriptDir & "\ftptemp" $dir_remote = "/" Local $iOpen = _FTP_Open('MyFTP Control') Local $iConn = _FTP_Connect($iOpen, "YourFTPServer", "YourUsername", "YourPassword") _FTP_DirGetContents($iConn, $dir_remote, $dir_local, 1) _FTP_Close($iConn) _FTP_Close($iOpen) Function Call Explanation: _FTP_DirGetContents($oConn, $opath, $olocal, $orec) $oConn: session handle as returned by _FTP_Connect. $opath: The remote folder to download $olocal: The local folder to download to. $orec: set to 1 to download folder and subfolders. Set to 0 for non recursive. Enjoy
-
How can you get the downloads folder in AutoIT? As far as i know there isn't a macro for it right? like @Downloads or something? The ugly solution would be typing in the whole path but what if the user has chosen another location? Need to clear that folder regularly on my work and on different accounts.. regards, TheAutomator
-
Good afternoon AutoIt community!, I was on Stackoverflow the other day and came across this question: How To Include Files From A Directory. This got me thinking... There has to be a way to do it... After a bunch of research, I wasn't able to find anything. So, I created this UDF to dynamically include every file from the directory. Of course, there are some bugs that I'd like to fix eventually, but for the most part, it works. Simply call the main function (Shown below) right after the rest of the includes before any of your actual code, and the UDF will include all of the au3 files in the specified directory. Without further ado, here is the _includeDir UDF and how to use it! _includeDir.au3 Download this code (_includeDir.au3 attached as well) and place it into the directory with your current script. Next, include it in your main file. For now, I'm going to be using one called Example.au3. #Include "_includeDir.au3" Now, include whatever else you're going to be including in this script, then call the _includeDir function. NOTE: THIS MUST BE CALLED AT THE TOP OF THE SCRIPT, BEFORE ANY CODE IS WRITTEN! THE FUNCTION FORCES THE SCRIPT TO RESTART SO PUTTING IT LATER IN THE SCRIPT WILL RE-RUN THE CODE! Example.au3 #Include "_includeDir.au3" #Include <File.au3> ; Not needed. Just here as an example of a normal script. #Include <Array.au3> ; Not needed. Just here as example of normal script. _includeDir("Directory to Include") MsgBox(0,"Example","This is just an example!") See how the function is called near the top? This is the proper use of the UDF. If you had a folder called "Directory to Include" and had a bunch of .au3 files inside of it, the function would include them all into the Example.au3 script. If you run the Example.au3 file now, it will most likely tell you "The directory Things to Include does not exist!". Make sure you enter the name of the directory you're trying to include. Just as a side note, when including files, you should put all of the code in the INCLUDED files inside of functions so they aren't automatically run when included. Variables can be outside of the functions so they are automatically set. Remember, if you have a variable in one included file with the same name of variable in another included file, it will be overwritten with whichever include file was included last. Anyways, if you have pointed the directory to include parameter to a folder that exists and run the Example.au3, it will generate a folder called IncludeDirUDF. It will also write a new line inside of Example.au3. It will write the line on line one. Of course, you don't always want it to be written to line one, right? Maybe you want this bit of code to be written on line 3 in order to keep your code organize. Is there a way to do this? Absolutely! Simply add the line number as a second parameter to the function. For example, we want to have this bit of code written on line 3, we would set up our Example.au3 file to look like this. #Include "_includeDir.au3" #Include <File.au3> ; Not needed. Just here as an example of a normal script. #Include <Array.au3> ; Not needed. Just here as example of normal script. _includeDir("Directory to Include", 3) MsgBox(0,"Example","This is just an example!") See how we added the 3 to the end of _includeDir? This will tell the function to write the #Include "IncludeDirUDF\loadIncludes.au3" on line 3 of Example.au3. Note, the line HAS TO EXIST in order to be written to it. For example, if your Example.au3 code only has 6 lines, and you specify to be written on line 7, it WILL NOT WORK. The code is designed to include and restart in order to process the included files. For some reason, if you want to JUST generate the included file and NOT restart, you can add one more parameter to the code. If you don't want the code to restart, simply set your code up to look like this: #Include "_includeDir.au3" #Include <File.au3> ; Not needed. Just here as an example of a normal script. #Include <Array.au3> ; Not needed. Just here as example of normal script. _includeDir("Directory to Include", 3, False) MsgBox(0,"Example","This is just an example!") Note, if you set this last parameter to false, it will simply generate the included file and write to line 3 of Example.au3 (As specified before) and exit before the code reaches the MsgBox() and it will not be displayed. The last important thing to note: In order to re-include a different set of files, you must delete the #Include "IncludeDirUDF\loadIncludes.au3" from your main script (In this case, Example.au3) and delete the generated file, IncludeDirUDF. Now you can simply rerun Example.au3 and it will include any the dir with any changes you made to it. Only .au3 files should be in the directory you're trying to include as it will not process the other files and will generate an error. I hope this UDF helps somebody out! Comment any questions/concerns you may have and I will try to address them as soon as possible! Thanks, Timothy CEO - Amarok Studios _includeDir.au3
-
Never say I don't give this community some little gems once in a while. I came up with the concept of creating a directory structure using nothing but valid HTML5 and CSS3. It uses an unknown "checkbox hack" concept which some HTML5/CSS3 purists consider to be beyond the semantics of the language. But I say if it's supported by all major browsers and it works, then why not! Note: I used >KaFu's idea for the current level and next level, but the rest I came up with myself, albeit I have used this "checkbox hack" before in other projects I have created. #include <File.au3> #include <MsgBoxConstants.au3> #include <WinAPIFiles.au3> MsgBox($MB_SYSTEMMODAL, '', 'This example only uses HTML5 and CSS3, I know, no JavaScript!') ; Thanks to KaFu for the idea: http://www.autoitscript.com/forum/topic/156913-dir2html-create-html-site-with-links-from-a-dir-structure/?p=1136522 Example() Func Example() Local Const $sSaveFilePath = @ScriptDir Local $sHTML = '', $sTab = @TAB _HTML_Add($sHTML, '<!DOCTYPE html>') _HTML_Add($sHTML, '<html lang="en">') _HTML_Add($sHTML, '<head>') _HTML_Add($sHTML, '<meta charset="utf-8">', $sTab) _HTML_Add($sHTML, '<title>Directory To HTML5 Concept</title>', $sTab) _HTML_Add($sHTML, '<style type="text/css">', $sTab) _Tab_Add($sTab) _HTML_Add($sHTML, '@import url(http://weloveiconfonts.com/api/?family=fontawesome);.dirtohtml a{background:transparent;color:#08c;position:relative;text-decoration:none;-webkit-transition:all .3s ease-out;transition:all .3s ease-out}.dirtohtml a:hover{color:#0af}.dirtohtml input[type=checkbox],.dirtohtml input[type=checkbox]+ul{display:none}.dirtohtml input[type=checkbox]:checked+ul{display:block}.dirtohtml label{cursor:pointer}.dirtohtml ul li{list-style:none}[class*="fontawesome-"]:before{font-family:"FontAwesome",sans-serif;margin-right:5px}', $sTab) _Tab_Remove($sTab) _HTML_Add($sHTML, '</style>', $sTab) _Tab_Remove($sTab) _HTML_Add($sHTML, '</head>') _HTML_Add($sHTML, '<body>') _Tab_Add($sTab) Local Const $sDirectorySelection = FileSelectFolder('Select a folder to map to HTML', '') Local $aFileList = _FileListToArrayRec($sDirectorySelection, '*', 0, 1, 2, 2) If @error Then _HTML_Add($sHTML, '<p>No files were present in the selected directory.</p>', $sTab) Else _HTML_Add($sHTML, '<div class="dirtohtml">', $sTab) _Tab_Add($sTab) _HTML_Add($sHTML, '<ul>', $sTab) _Tab_Add($sTab) Local $bIsRelative = False, _ $iCheckboxCount = 1, $iCurrentLevel = 0, $iNestedDepth = 0, $iNextIndex = 0, $iNextLevel = 0, _ $sFileName = '', $sRelativeFilePath = '' For $i = 1 To $aFileList[0] $aFileList[$i] = StringRegExpReplace($aFileList[$i], '(?:\\|/)', '\\') $iCurrentLevel = @extended If $i < $aFileList[0] Then $iNextIndex = $i + 1 $aFileList[$iNextIndex] = StringRegExpReplace($aFileList[$iNextIndex], '(?:\\|/)', '\\') $iNextLevel = @extended EndIf $sFileName = StringRegExpReplace($aFileList[$i], '^.+\\', '') If _WinAPI_PathIsDirectory($aFileList[$i]) = $FILE_ATTRIBUTE_DIRECTORY Then If $iNextLevel > $iCurrentLevel Or $iNextLevel = $iCurrentLevel Then _HTML_Add($sHTML, '<li>', $sTab) _Tab_Add($sTab) _HTML_Add($sHTML, '<label for="dirtohtml_' & $iCheckboxCount & '"><i class="fontawesome-folder-close-alt"></i>' & $sFileName & '</label>', $sTab) _HTML_Add($sHTML, '<input id="dirtohtml_' & $iCheckboxCount & '" type="checkbox">', $sTab) _HTML_Add($sHTML, '<ul>', $sTab) $iCheckboxCount += 1 $iNestedDepth += 1 ElseIf $iNextLevel < $iCurrentLevel Then _HTML_Add($sHTML, '<li>' & $sFileName, $sTab) EndIf _Tab_Add($sTab) Else $sRelativeFilePath = _PathGetRelative($sSaveFilePath, $aFileList[$i]) $bIsRelative = Not @error _HTML_Add($sHTML, '<li><i class="fontawesome-file"></i><a href="' & ($bIsRelative ? '' : 'file://') & StringReplace($sRelativeFilePath, '\', '/') & '">' & $sFileName & '</a></li>', $sTab) If $iNextLevel < $iCurrentLevel Then For $j = 1 To ($iCurrentLevel - $iNextLevel) _Tab_Remove($sTab) _HTML_Add($sHTML, '</ul>', $sTab) _Tab_Remove($sTab) _HTML_Add($sHTML, '</li>', $sTab) $iNestedDepth -= 1 Next EndIf EndIf Next If $iNestedDepth Then For $j = 1 To $iNestedDepth _Tab_Remove($sTab) _HTML_Add($sHTML, '</ul>', $sTab) _Tab_Remove($sTab) _HTML_Add($sHTML, '</li>', $sTab) Next EndIf _Tab_Remove($sTab) _HTML_Add($sHTML, '</ul>', $sTab) _Tab_Remove($sTab) _HTML_Add($sHTML, '</div>', $sTab) EndIf _HTML_Add($sHTML, '</body>') _HTML_Add($sHTML, '</html>') Local Const $sHTMLFilePath = _WinAPI_PathRemoveBackslash($sSaveFilePath) & '\index.html' Local Const $hFileOpen = FileOpen($sHTMLFilePath, BitOR($FO_OVERWRITE, $FO_UTF8)) If $hFileOpen > -1 Then FileWrite($hFileOpen, $sHTML) FileClose($hFileOpen) MsgBox($MB_SYSTEMMODAL, '', 'HTML file created successfully.' & @CRLF & $sHTMLFilePath) Else MsgBox($MB_SYSTEMMODAL, '', 'An error occurred writing to the HTML file.') EndIf ConsoleWrite($sHTML & @CRLF) ; ShellExecute($sHTMLFilePath) Return True EndFunc ;==>Example Func _HTML_Add(ByRef $sHTML, $sData, $sTab = Default) $sHTML &= (($sTab = Default) ? '' : $sTab) & $sData & @CRLF EndFunc ;==>_HTML_Add Func _Tab_Add(ByRef $sTab) $sTab &= @TAB EndFunc ;==>_Tab_Add Func _Tab_Remove(ByRef $sTab) Local Static $TAB_LENGTH = StringLen(@TAB) $sTab = StringTrimRight($sTab, $TAB_LENGTH) EndFunc ;==>_Tab_Remove
-
Hello, I am trying to look into multiple folders for outlook OST's. What I need is if there are more than one, delete the oldest one in that directory then move to the next directory. I am not to sure on how to compare and detect multiple OSTs in a folder. So far my script will search all the subdirectories in a given path and prompt me with the OST's found. How to I check for more than one OST and delete the oldest? Folder structure example: OSTS - user1 - User1.ost - User2 - User2.ost -User2_dup.ost Etc... ; Script Start - Add your code below here #include <Array.au3> ; Only required to display the arrays #include <File.au3> #include <MsgBoxConstants.au3> Local $sOSTDir = "\\server1\osts\" $aArray = _FileListToArrayRec($sOSTDir, "*.ost", $FLTAR_RECUR, $FLTAR_SORT) for $i = 1 to $aArray[0] $time = FileGetTime($sOSTDir & $aArray[$i], 2); 0 if for modified date $dmyyyy = $time[3]& ":" & $time[4] & ":" & $time[5]&'_'&$time[1]& "/" & $time[2] & "/" & $time[0] msgbox(0,"test", $aArray[$i] & " | Date: " & $dmyyyy) next Any help would be appreciated.
-
I'm Trying to get all computers returned in the active domain that have been active within the last 90 days, I'm currently stuck at just getting the full list of computers in the domain. I'm using the ADfunctions UDF. Here's my code: #include "XXX/ADfunctions.au3" _GetADComputers() Func _GetADComputers() Local $aComputers $sOU = $strDNSDomain _ADGetObjectsInOU($aComputers,$sOU,"(objectclass=computer)",2,"name") _ArrayDisplay($aComputers) Return($aComputers) EndFunc Any help is greatly appreciated!
-
#include-once ; #UDF# ======================================================================================================================= ; Title .........: PathSplitEx ; AutoIt Version : 3.3.8.1 ; Language ......: English ; Description ...: Splits a path into the drive, directory, file name and file extension parts ; Author(s) .....: DXRW4E ; Notes .........: ; =============================================================================================================================== ; #CURRENT# ===================================================================================================================== ; _PathSplitEx ; _PathSplitParentDir ; _FileExistsEx ; =============================================================================================================================== ; #FUNCTION# ==================================================================================================================== ; Name...........: _PathSplitEx ; Description ...: Splits a path into the drive, directory, file name and file extension parts. An empty string is set if a part is missing. ; Syntax.........: _PathSplitEx($sFilePath, ByRef $sDrive, ByRef $sDir, ByRef $sFileName, ByRef $sExtension) ; Parameters ....: $sFilePath - The path to be split (Can contain a UNC server or drive letter) ; $sDrive - String to hold the drive ; $sDir - String to hold the directory ; $sFileName - String to hold the file name ; $sExtension - String to hold the file extension ; Return values .: Success - Returns an array with 5 elements where 0 = original path 1 = drive, 2 = directory, 3 = filename, 4 = extension ; Author ........: DXRW4E ; Modified.......: ; Remarks .......: This function does not take a command line string. It works on paths, not paths with arguments. ; Related .......: ; Link ..........: ; Example .......: ; =============================================================================================================================== Func _PathSplitEx($sFilePath, ByRef $sDrive, ByRef $sDir, ByRef $sFileName, ByRef $sExtension) $sFilePath = StringRegExp($sFilePath, "^((?:\\\\\?\\)*(\\\\[^\?\/\\]+|[A-Za-z]:)?(.*[\/\\])?((?:[^\.\/\\]|(?(?=\.[^\/\\]*\.)\.))*)?([^\/\\]*))$", 1) $sDrive = $sFilePath[1] $sDir = StringRegExpReplace($sFilePath[2], "[\/\\]+\h*", "\" & StringLeft($sFilePath[2], 1)) $sFileName = $sFilePath[3] $sExtension = $sFilePath[4] Return $sFilePath EndFunc ; #FUNCTION# ==================================================================================================================== ; Name...........: _PathSplitParentDir ; Description ...: Splits a path into the drive, directory, file name and file extension parts. An empty string is set if a part is missing. ; Syntax.........: _PathSplit($sFilePath, ByRef $sDrive, ByRef $sDir, ByRef $sParentDir, ByRef $sFileName, ByRef $sExtension) ; Parameters ....: $sFilePath - The path to be split (Can contain a UNC server or drive letter) ; $sDrive - String to hold the drive ; $sDir - String to hold the directory ; $sParentDir - String to hold the parent directory ; $sFileName - String to hold the file name ; $sExtension - String to hold the file extension ; Return values .: Success - Returns an array with 6 elements where 0 = original path 1 = drive, 2 = directory, 3 = parentdir, 4 = filename, 5 = extension ; Author ........: DXRW4E ; Modified.......: ; Remarks .......: This function does not take a command line string. It works on paths, not paths with arguments. ; Related .......: ; Link ..........: ; Example .......: ; =============================================================================================================================== Func _PathSplitParentDir($sFilePath, ByRef $sDrive, ByRef $sDir, ByRef $sParentDir, ByRef $sFileName, ByRef $sExtension) $sFilePath = StringRegExp($sFilePath & " ", "^((?:\\\\\?\\)*(\\\\[^\?\/\\]+|[A-Za-z]:)?(.*?[\/\\]+)?([^\/\\]*[\/\\])?[\/\\]*((?:[^\.\/\\]|(?(?=\.[^\/\\]*\.)\.))*)?([^\/\\]*))$", 1) $sDrive = $sFilePath[1] $sFilePath[2] = StringRegExpReplace($sFilePath[2], "[\/\\]+\h*", "\" & StringLeft($sFilePath[2], 1)) $sDir = $sFilePath[2] $sParentDir = $sFilePath[3] $sFileName = $sFilePath[4] $sExtension = $sFilePath[5] Return $sFilePath EndFunc ; #FUNCTION# ==================================================================================================================== ; Name...........: _FileExistsEx ; Description ...: Get New Files Name ; Syntax.........: _FileExistsEx(ByRef $sFilePath[, $iFileExists]) ; Parameters ....: $sFilePath - The Fullpath file ; $iFileExists - Optional ; Author ........: DXRW4E ; Modified.......: ; Remarks .......: ; Related .......: ; Link ..........: ; Example .......: ; =============================================================================================================================== Func _FileExistsEx(ByRef $sFilePath, $iFileExists = 0) While FileExists($sFilePath) $iFileExists += 1 $sFilePath = StringRegExpReplace($sFilePath & " ", "( - \(\d+\))?(\.[^\.\\]*)?(\h)$", " - (" & $iFileExists & ")$2") WEnd EndFunc _PathSplitEx.au3
- 43 replies
-
- _PathSplitEx
- File
- (and 8 more)
-
Code snippet The aim is to enhance the performance of directory discovery part of a network drive, in particular when browsing a directory over a WAN or Cloud. I have noticed a significant (near to tenfold) performance profit by disabling Windows Explorer display pane ( Organize / layout / Details Pane ) Initially the key does not exist when the display pane is enabled (by default) In the example, I opted for deleting the key if $bDisableDetailsPane is set to true I have no clue what the other binary figures are meant for... WindowsExplorerSettings_DisableDetailsPane.au3 Greencan
-
Hi ppl, just made this simple one because sometimes i want to access the wallpaper directory to do some modifications on wallpapers, and in win 7 it's not as easy to go there as i would likem so i made this simple script, got any sugestions of improvement? They're welcome. So here it goes, execute to open dir where the wallpaper you have displayed is: #include <File.au3> Local $Path, $szDrive, $szDir, $szFName, $szExt, $TestPath $Path = RegRead("HKEY_CURRENT_USERSoftwareMicrosoftInternet ExplorerDesktopGeneral", "WallpaperSource") $TestPath = _PathSplit($Path, $szDrive, $szDir, $szFName, $szExt) $Path = $szDrive & $szDir ;MsgBox(4096, "", $Path, 10) ShellExecute ($Path) Hope you like it and that it may become useful for someone. EDIT: Removed the brackets as pointed out by guinness. Thanks, forgot that one. AutoIt Wallpaper.au3
-
Getting the directory from a file?
cheeseandcereal posted a topic in AutoIt General Help and Support
Hey so I was wondering if I had a file string such as "C:/example/file.exe" would there be any way to pull out the directory from that so I could set a variable to be "C:/example/" only knowing "C:/example/file.exe" automatically? So for example, If I had this script: Opt("MustDeclareVars", 1) Global $file1 Global $directory1 $file1 = FileOpenDialog ("", "", "All Files (*.*)") how would I be able to set $directory1 as the directory containing selected $file1