Jump to content

How to check a a folder his subfolders?


Hielper
 Share

Recommended Posts

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

_FileListToArrayRec?

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2022-02-19 - Version 1.6.1.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 (NEW 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

Could you tell me what is wrong here $test = _FileListToArrayRec($map, "", "", $FLTAR_RECUR, $FLTAR_fullpath)

$test = _FileListToArrayRec($map, "", "", $FLTAR_RECUR, $FLTAR_fullpath)

 

Edited by Hielper
Link to comment
Share on other sites

Define "wrong".
Error message, unexpected result ...?

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2022-02-19 - Version 1.6.1.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 (NEW 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

#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 by Hielper
Link to comment
Share on other sites

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 2022-02-19 - Version 1.6.1.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 (NEW 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

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 by Hielper
Link to comment
Share on other sites

FileGetType returns an array. So StringRegExpReplace does not work in this case.

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2022-02-19 - Version 1.6.1.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 (NEW 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

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 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

  • Moderators

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

 

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png 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 columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
Share on other sites

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

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 2022-02-19 - Version 1.6.1.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 (NEW 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

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 by Hielper
Link to comment
Share on other sites

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 2022-02-19 - Version 1.6.1.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 (NEW 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

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...