Hielper

How to check a a folder his subfolders?

17 posts in this topic

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

Share this post


Link to post
Share on other sites



_FileListToArrayRec?


My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2017-04-18 - Version 1.4.8.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2017-02-27 - Version 1.3.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
ADO - Wiki

 

Share this post


Link to post
Share on other sites

#3 ·  Posted (edited)

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

Share this post


Link to post
Share on other sites

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


My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2017-04-18 - Version 1.4.8.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2017-02-27 - Version 1.3.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
ADO - Wiki

 

Share this post


Link to post
Share on other sites

#5 ·  Posted (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 by Hielper

Share this post


Link to post
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 2017-04-18 - Version 1.4.8.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2017-02-27 - Version 1.3.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
ADO - Wiki

 

Share this post


Link to post
Share on other sites

#7 ·  Posted (edited)

thx will try!

Edited by Hielper

Share this post


Link to post
Share on other sites

#8 ·  Posted (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 by Hielper

Share this post


Link to post
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 2017-04-18 - Version 1.4.8.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2017-02-27 - Version 1.3.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
ADO - Wiki

 

Share this post


Link to post
Share on other sites

#10 ·  Posted (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 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.

Share this post


Link to post
Share on other sites

#11 ·  Posted (edited)

haha thank you very much for your example

Could i ask what the point is of using the three consolewrite lines?

Edited by Hielper

Share this post


Link to post
Share on other sites

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

 

Share this post


Link to post
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.

Share this post


Link to post
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 2017-04-18 - Version 1.4.8.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2017-02-27 - Version 1.3.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
ADO - Wiki

 

Share this post


Link to post
Share on other sites

#15 ·  Posted (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 by Hielper

Share this post


Link to post
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 2017-04-18 - Version 1.4.8.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2017-02-27 - Version 1.3.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
ADO - Wiki

 

Share this post


Link to post
Share on other sites
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 :D

Share this post


Link to post
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