Hielper Posted December 5, 2016 Share Posted December 5, 2016 I have currently made an array and a forloop that checks a folder path. But what if the folder path has subfolders contained and in the subfolders more subfolders, is there an possibility that i check if it exists and add them to my _Filelist array? Thanks Link to comment Share on other sites More sharing options...
water Posted December 5, 2016 Share Posted December 5, 2016 _FileListToArrayRec? My UDFs and Tutorials: Spoiler UDFs: Active Directory (NEW 2024-07-28 - Version 1.6.3.0) - Download - General Help & Support - Example Scripts - Wiki ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki Task Scheduler (2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki Standard UDFs: Excel - Example Scripts - Wiki Word - Wiki Tutorials: ADO - Wiki WebDriver - Wiki Link to comment Share on other sites More sharing options...
Hielper Posted December 5, 2016 Author Share Posted December 5, 2016 (edited) Could you tell me what is wrong here $test = _FileListToArrayRec($map, "", "", $FLTAR_RECUR, $FLTAR_fullpath) $test = _FileListToArrayRec($map, "", "", $FLTAR_RECUR, $FLTAR_fullpath) Edited December 5, 2016 by Hielper Link to comment Share on other sites More sharing options...
water Posted December 5, 2016 Share Posted December 5, 2016 Define "wrong". Error message, unexpected result ...? My UDFs and Tutorials: Spoiler UDFs: Active Directory (NEW 2024-07-28 - Version 1.6.3.0) - Download - General Help & Support - Example Scripts - Wiki ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki Task Scheduler (2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki Standard UDFs: Excel - Example Scripts - Wiki Word - Wiki Tutorials: ADO - Wiki WebDriver - Wiki Link to comment Share on other sites More sharing options...
Hielper Posted December 5, 2016 Author Share Posted December 5, 2016 (edited) #include <File.au3> #include <Date.au3> $map=("C:\school") $test = _FileListToArrayRec($map, "", "", $FLTAR_RECUR, $FLTAR_fullpath) $lala = 7 $map2= ("C:\test") if IsArray($test) Then For $i = 1 To UBound($test) - 1 $tijd = StringRegExpReplace(FileGetTime($map & $test[$i], 1, 1), "(.{4})(.{2})(.{2})(.{2})(.{2})(.{2})", "${1}/${2}/${3} ${4}:${5}:${6}") If _DateDiff('d', $tijd, _NowCalc()) > $lala Then FileCopy($test, $map2) EndIf Next EndIf I try to run the line in this script, but nothing happens Edited December 5, 2016 by Hielper Link to comment Share on other sites More sharing options...
water Posted December 5, 2016 Share Posted December 5, 2016 You need to add some error checking to your script. What is the value of @error and @extended after _FileListToArrayRec Use _ArrayDisplay to show the array and check if it contains the desired data Write the result of _DateDiff to the Console to check if you get the desired result My UDFs and Tutorials: Spoiler UDFs: Active Directory (NEW 2024-07-28 - Version 1.6.3.0) - Download - General Help & Support - Example Scripts - Wiki ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki Task Scheduler (2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki Standard UDFs: Excel - Example Scripts - Wiki Word - Wiki Tutorials: ADO - Wiki WebDriver - Wiki Link to comment Share on other sites More sharing options...
Hielper Posted December 5, 2016 Author Share Posted December 5, 2016 (edited) thx will try! Edited December 5, 2016 by Hielper Link to comment Share on other sites More sharing options...
Hielper Posted December 5, 2016 Author Share Posted December 5, 2016 (edited) It seems that the problem is in this line, i think about the last parameters Since i was not able to get the dates of the files i want to copy $tijd = StringRegExpReplace(FileGetTime($map & $test[$i], 1, 1), "(.{4})(.{2})(.{2})(.{2})(.{2})(.{2})", "${1}/${2}/${3} ${4}:${5}:${6}") Could you give me an hint for solving it? Edited December 5, 2016 by Hielper Link to comment Share on other sites More sharing options...
water Posted December 5, 2016 Share Posted December 5, 2016 FileGetType returns an array. So StringRegExpReplace does not work in this case. My UDFs and Tutorials: Spoiler UDFs: Active Directory (NEW 2024-07-28 - Version 1.6.3.0) - Download - General Help & Support - Example Scripts - Wiki ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki Task Scheduler (2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki Standard UDFs: Excel - Example Scripts - Wiki Word - Wiki Tutorials: ADO - Wiki WebDriver - Wiki Link to comment Share on other sites More sharing options...
SadBunny Posted December 5, 2016 Share Posted December 5, 2016 (edited) FileGetTime returns an array or a string depending on the third argument being respectively 0 or 1. There's a couple of other things wrong though: The parameters in _FileListToArrayRec (they lead to the function not finding anything, because there is no mask an the parameters are in the wrong order) The _FileListToArrayRec already returns the full path because of the $FLTAR_FULLPATH (one you put it in the right place) so prepending the dir name breaks it again Consider this example (put in your own directory). Check the console logging to see the output. Then add your own code to do with the files what you want. #include <File.au3> #include <Date.au3> $map = ("C:\tmp\3") $test = _FileListToArrayRec($map, "*.*", Default, $FLTAR_RECUR, Default, $FLTAR_FULLPATH) If IsArray($test) Then For $i = 1 To UBound($test) - 1 ConsoleWrite("File: " & $test[$i] & @CRLF) $bareFileTime = FileGetTime($test[$i], 1, 1) ConsoleWrite("Bare filetime: " & $bareFileTime & @CRLF) $tijd = StringRegExpReplace($bareFileTime, "(.{4})(.{2})(.{2})(.{2})(.{2})(.{2})", "${1}/${2}/${3} ${4}:${5}:${6}") ConsoleWrite("Parsed time: " & $tijd & @CRLF) Next EndIf Hopefully superfluously: always remember to make backups of any files you may touch with the script, even when it goes wrong - you never know, especially when copying, renaming or removing files. Edited December 5, 2016 by SadBunny Forgot to actually add the code snippet - all the blood, sweat and tears almost for nothing... Roses are FF0000, violets are 0000FF... All my base are belong to you. Link to comment Share on other sites More sharing options...
Hielper Posted December 5, 2016 Author Share Posted December 5, 2016 (edited) haha thank you very much for your example Could i ask what the point is of using the three consolewrite lines? Edited December 5, 2016 by Hielper Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted December 5, 2016 Moderators Share Posted December 5, 2016 Hielper, When you reply, please use the "Reply to this topic" button at the top of the thread or the "Reply to this topic" editor at the bottom rather than the "Quote" button - responders know what they wrote and it just pads the thread unnecessarily. M23 Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind Open spoiler to see my UDFs: Spoiler ArrayMultiColSort ---- Sort arrays on multiple columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area Link to comment Share on other sites More sharing options...
SadBunny Posted December 5, 2016 Share Posted December 5, 2016 The ConsoleWrites are there for debug logging, so you can see what the script exactly does and what the values of the variables are that you are working on. Had you implemented them yourself, you would for instance have seen that your code put together broken filepaths and was thus unable to read the file time. It's easiest to run your code in a full SciTE (for AutoIt) installation, especially while debugging, if you weren't already. The ConsoleWrite output will appear directly in the lower panel while the script is running. Roses are FF0000, violets are 0000FF... All my base are belong to you. Link to comment Share on other sites More sharing options...
water Posted December 6, 2016 Share Posted December 6, 2016 You need something like this: #include <File.au3> #include <Date.au3> #include <FileConstants.au3> $spath = ("C:\temp\") $aFiles = _FileListToArrayRec($spath, "*.txt", $FLTAR_FILES, $FLTAR_RECUR, $FLTAR_NOSORT, $FLTAR_FULLPATH) $iMaxAge = 7 If Not IsArray($aFiles) Then Exit For $i = 1 To $aFiles[0] $sFileTime = FileGetTime($aFiles[$i], 0, 1) $sFileTime = StringRegExpReplace($sFileTime, "(\d{4})(\d{2})(\d{2})(\d{2})(\d{2})(\d{2})", "$1/$2/$3 $4:$5:$6") If _DateDiff('D', $sFileTime, _NowCalc()) > $iMaxAge Then ConsoleWrite("File " & $aFiles[$i] & " is older then maxage!" & @CRLF) Else ConsoleWrite("File " & $aFiles[$i] & " is younger then maxage!" & @CRLF) EndIf Next My UDFs and Tutorials: Spoiler UDFs: Active Directory (NEW 2024-07-28 - Version 1.6.3.0) - Download - General Help & Support - Example Scripts - Wiki ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki Task Scheduler (2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki Standard UDFs: Excel - Example Scripts - Wiki Word - Wiki Tutorials: ADO - Wiki WebDriver - Wiki Link to comment Share on other sites More sharing options...
Hielper Posted December 6, 2016 Author Share Posted December 6, 2016 (edited) Currently im trying to make the script work with parameters, eg i want to add an parameter that the user can type a variable in cmd, so that the script automatically deletes files older than XX days Im not asking for an solution, i just need a push in the right way so i can figure out it myself since i didnt understand much of the helpfile This is currently my script #include <File.au3> #include <Date.au3> #include <FileConstants.au3> Global $map =("C:\school\") Global $test = _FileListToArrayRec($map, "*" ,$FLTAR_Files,$FLTAR_RECUR, $FLTAR_NOSORT, $FLTAR_FULLPATH) Global $test1= $Cmdline[2] ;filerecycle of file delete Global $quantity = $Cmdline[1] $Cmdline[0] > $Cmdline[1] = $quantity $Cmdline[2] = $test1 if IsArray($test) Then For $i = 1 To $test[0] consolewrite("locatie: " & $test[$i] & @CRLF) $tijd = FileGettime($test [$i], 1,1) $tijd = StringRegExpReplace($tijd,"(\d{4})(\d{2})(\d{2})(\d{2})(\d{2})(\d{2})", "$1/$2/$3 $4:$5:$6") If _DateDiff('D', $tijd, _NowCalc()) > $quantity & $cmdline[2] <> "d" Then msgbox( 0,"", "je hebt d ingevoerd") ElseIf _DateDiff ('D', $tijd, _NowCalc()) > $quantity & $cmdline[2] <> "r" Then msgbox(0, "", "je hebt r ingevoerd") EndIf Next EndIf Edited December 6, 2016 by Hielper Link to comment Share on other sites More sharing options...
water Posted December 6, 2016 Share Posted December 6, 2016 7 minutes ago, Hielper said: $Cmdline[1] = $quantity$Cmdline[2] = $test1 You can't modify the $Cmdline array. According to the help file this is a Constant. My UDFs and Tutorials: Spoiler UDFs: Active Directory (NEW 2024-07-28 - Version 1.6.3.0) - Download - General Help & Support - Example Scripts - Wiki ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki Task Scheduler (2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki Standard UDFs: Excel - Example Scripts - Wiki Word - Wiki Tutorials: ADO - Wiki WebDriver - Wiki Link to comment Share on other sites More sharing options...
Hielper Posted December 6, 2016 Author Share Posted December 6, 2016 11 minutes ago, water said: You can't modify the $Cmdline array. According to the help file this is a Constant. ah im started to understand it thx for the correction! you will see a better version soon Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now