Jump to content

file list and file search


Xand3r
 Share

Recommended Posts

:)

file list writes the results in files.txt

Edit: now writes file time and size :) aswell

search.au3

file_list.au3

Edited by alexmadman

Only two things are infinite, the universe and human stupidity, and i'm not sure about the former -Alber EinsteinPractice makes perfect! but nobody's perfect so why practice at all?http://forum.ambrozie.ro

Link to comment
Share on other sites

I would write this by dirs

Dim $folders=_FileListToArray($k,"*",2)

... :) works with and without the dot :)

Edited by alexmadman

Only two things are infinite, the universe and human stupidity, and i'm not sure about the former -Alber EinsteinPractice makes perfect! but nobody's perfect so why practice at all?http://forum.ambrozie.ro

Link to comment
Share on other sites

  • 1 month later...

Hi Alex,

I'm trying to learn the autoit script and currently working on a task which is pretty similar what you've posted earlier on. As I'm beginner of the autoit, I'm not quite familiar with some of the commands. Well, let me share with u my problems. My task is to monitor the "*.txt" file in a logfile directory.

Then need to write in an another text file to report file name,file size and file last modified date.

File Name File Size File Last Modified

Schedule1.txt 5K 10/10/2008 8:00pm (<<<< these file names, size and date are what I can see

in the "logfile" directory.)

Thank you very much in advance.

Link to comment
Share on other sites

Hi Alex,

I'm trying to learn the autoit script and currently working on a task which is pretty similar what you've posted earlier on. As I'm beginner of the autoit, I'm not quite familiar with some of the commands. Well, let me share with u my problems. My task is to monitor the "*.txt" file in a logfile directory.

Then need to write in an another text file to report file name,file size and file last modified date.

File Name File Size File Last Modified

Schedule1.txt 5K 10/10/2008 8:00pm (<<<< these file names, size and date are what I can see

in the "logfile" directory.)

Thank you very much in advance.

Why did you post twice at different times?:)

For this script, you might want to have a look at a loop (While 1...Wend), that checks the time it was modified (FileGetTime) then use the using If...Then...Else...EndIf to control whether the File... functions are adhered to then write the data to the file or if it just sleeps... Also, to get the size, use FileGetSize.

Link to comment
Share on other sites

dude i'm not gonna make you the code for that but i am going to point you in the right direction...

try the help file for:

_FileListToArray
FileGetTime
FileGetSize 
FileOpen
FileWrite

if you need to make that program try to code your self first and then ask for help!

Only two things are infinite, the universe and human stupidity, and i'm not sure about the former -Alber EinsteinPractice makes perfect! but nobody's perfect so why practice at all?http://forum.ambrozie.ro

Link to comment
Share on other sites

dude i'm not gonna make you the code for that but i am going to point you in the right direction...

try the help file for:

_FileListToArray
FileGetTime
FileGetSize 
FileOpen
FileWrite

if you need to make that program try to code your self first and then ask for help!

hi,

Thanks for your guidence. I've tried to write some codes but I've no idea how to get the file size and file time using with the array. Pls take a look my code and hope u 'll give me some more advice.

#Include <File.au3>

#Include <Array.au3>

$a = "C:\"

$b = "C:\Temp\Report.txt"

$FileList=_FileListToArray($a,"*.exe",1)

If @Error=1 Then

MsgBox (0,"","No Files\Folders Found.")

Exit

EndIf

_FileWriteFromArray($b,$FileList,1)

Thank you so much.

real4U

Link to comment
Share on other sites

#include <File.au3>
#Include <Array.au3>
$a = "C:\"
$b = "C:\Temp\Report.txt"
$FileList=_FileListToArray($a,"*.txt",1)
If @Error=1 Then
    MsgBox (0,"","No Files\Folders Found.")
    Exit
EndIf
Dim $size[UBound($FileList)+1]
Dim $time[UBound($FileList)+1]
For $i=1 To $FileList[0]
    $size[$i]=FileGetSize($a&$FileList[$i])
Next
For $i=1 To $FileList[0]
    $time=FileGetTime($a&$FileList[$i])
    $time1=FileGetTime($a&$FileList[$i],1)
    $time2=FileGetTime($a&$FileList[$i],2)
    
    MsgBox(0 ,"File no:"&$i,"File name:"&$FileList[$i] &@CRLF & _
                            "File size:"&$size[$i]&" bytes" &@CRLF & _
                            "Created:"&$time1[2]&"/"&$time1[1]&"/"&$time1[0]&" - "& $time1[3]&":"&$time1[4]&":"&$time1[5] &@CRLF & _
                            "Last Modified:"&$time[2]&"/"&$time[1]&"/"&$time[0]&" - "& $time[3]&":"&$time[4]&":"&$time[5] &@CRLF & _
                            "Accessed:"&$time2[2]&"/"&$time2[1]&"/"&$time2[0]&" - "& $time2[3]&":"&$time2[4]&":"&$time2[5])
Next

Just put a file write instead of the msgbox

Only two things are infinite, the universe and human stupidity, and i'm not sure about the former -Alber EinsteinPractice makes perfect! but nobody's perfect so why practice at all?http://forum.ambrozie.ro

Link to comment
Share on other sites

Thank you very very much, Alex. Really do appreciate your kindness. <_<

#include <File.au3>
#Include <Array.au3>
$a = "C:\"
$b = "C:\Temp\Report.txt"
$FileList=_FileListToArray($a,"*.txt",1)
If @Error=1 Then
    MsgBox (0,"","No Files\Folders Found.")
    Exit
EndIf
Dim $size[UBound($FileList)+1]
Dim $time[UBound($FileList)+1]
For $i=1 To $FileList[0]
    $size[$i]=FileGetSize($a&$FileList[$i])
Next
For $i=1 To $FileList[0]
    $time=FileGetTime($a&$FileList[$i])
    $time1=FileGetTime($a&$FileList[$i],1)
    $time2=FileGetTime($a&$FileList[$i],2)
    
    MsgBox(0 ,"File no:"&$i,"File name:"&$FileList[$i] &@CRLF & _
                            "File size:"&$size[$i]&" bytes" &@CRLF & _
                            "Created:"&$time1[2]&"/"&$time1[1]&"/"&$time1[0]&" - "& $time1[3]&":"&$time1[4]&":"&$time1[5] &@CRLF & _
                            "Last Modified:"&$time[2]&"/"&$time[1]&"/"&$time[0]&" - "& $time[3]&":"&$time[4]&":"&$time[5] &@CRLF & _
                            "Accessed:"&$time2[2]&"/"&$time2[1]&"/"&$time2[0]&" - "& $time2[3]&":"&$time2[4]&":"&$time2[5])
Next

Just put a file write instead of the msgbox

Link to comment
Share on other sites

Hi Alex,

Thank you so much for your fast response. I've tried to modify the script to be more efficient display but somehow I got minor problem. I tried to put the heading but the heading is repeating after one txt has been entried. Please have a look the below modification if you have time.

#include <File.au3>

#Include <Array.au3>

$a = "C:\Temp\"

$b = "C:\Report.txt"

$report = FileOpen($b,2)

$FileList=_FileListToArray($a,"*.txt",1)

If @Error=1 Then

MsgBox (0,"","No Files\Folders Found.")

Exit

EndIf

Dim $size[uBound($FileList)+1]

Dim $time[uBound($FileList)+1]

$header = " File Name File Size Last Modified Contents"

For $i=1 To $FileList[0]

$size[$i]=FileGetSize($a&$FileList[$i])

Next

For $i=1 To $FileList[0]

$time=FileGetTime($a&$FileList[$i])

$time1=FileGetTime($a&$FileList[$i],1)

$time2=FileGetTime($a&$FileList[$i],2)

FileWrite($report,$header &@CRLF &$i &")" &$FileList[$i] & @TAB & @TAB & @TAB & $size[$i]&" bytes" & @TAB & @TAB &$time[2]&"/"&$time[1]&"/"&$time[0]&" - "& $time[3]&":"&$time[4]&":"&$time[5]&@CRLF)

Next

Thank you very much.

yours friendly,

REAL4U

Link to comment
Share on other sites

dude i can't understand what you say :)

anywayz......

i got bored so i made somethin for you <_<

#include <File.au3>
#include <Array.au3>
#include <Date.au3>
$a = "C:\" 
$b = "C:\Report.html" 
If Not FileExists(@MyDocumentsDir & "\file_report_txt.ini") Then
    IniWrite(@MyDocumentsDir & "\file_report_txt.ini", "Info", "count", 1)
    $nr = 1
Else
    $nr = IniRead(@MyDocumentsDir & "\file_report_txt.ini", "Info", "count", 1)
    IniWrite(@MyDocumentsDir & "\file_report_txt.ini", "Info", "count", $nr + 1)
EndIf
;MsgBox(0 ,"" , _NowCalc() )
$FileList = _FileListToArray($a, "*", 1)
$report = FileOpen($b, 1)
Switch @error
    Case 1
        MsgBox(0 + 16, "", "No files/folders found")
    Case 2
        MsgBox(0 + 16, "", "Invalid filter")
    Case 3
        MsgBox(0 + 16, "", "Invalid flag")
    Case 4
        MsgBox(0 + 16, "", "No files found!")
EndSwitch
Dim $size[UBound($FileList) + 1]
Dim $time[UBound($FileList) + 1]
$header = StringSplit("No,File Name,File Size,Last Modified", ",")
;~ For $i=1 To $FileList[0]
;~  $size[$i]=FileGetSize($a&$FileList[$i])
;~ Next
FileWriteLine($report, "<HTML><HEAD></HEAD><BODY><BR><B>Scan no:" & $nr & " at:" & _NowDate() & "-" & _NowTime() & "</B><BR><TABLE border=1>")
FileWriteLine($report, "<TR>")
For $i = 1 To $header[0]
    FileWriteLine($report, "<TD><B>" & $header[$i] & "</B></TD>")
Next
FileWriteLine($report, "</TR>")


For $i = 1 To $FileList[0]
    $time = FileGetTime($a & $FileList[$i])
    $sz_size = calcsize(FileGetSize($a & $FileList[$i]))
    $calcdate = $time[0] & "/" & $time[1] & "/" & $time[2] & " " & $time[3] & ":" & $time[4] & ":" & $time[5]
    $szfile = parsefile($FileList[$i], $calcdate)
    FileWriteLine($report, "<TR><TD><B>" & $i & "</B><TD>" & $szfile & "<TD>" & $sz_size & "<TD>" & $time[2] & "/" & $time[1] & "/" & $time[0] & " - " & $time[3] & ":" & $time[4] & ":" & $time[5] & "</TR>")
Next
FileWriteLine($report, "</TABLE></BODY></HTML>");


Func calcsize($bytes)
    If $bytes < 1024 Then Return $bytes & " B" 
    
    $tb = did($bytes, pow(1024, 4))
    $gb = did($bytes, pow(1024, 3))
    $mb = did($bytes, pow(1024, 2))
    $kb = did($bytes, pow(1024, 1))
    $size = ""
    If $tb <> 0 Then
        $size = $size & $tb & " TB " 
    EndIf
    If $gb <> 0 Then
        $size = $size & $gb & " GB " 
    EndIf
    If $mb <> 0 Then
        $size = $size & $mb & " MB " 
    EndIf
    If $kb <> 0 Then
        $size = $size & $kb & " KB " 
    EndIf
    Return $size
EndFunc   ;==>calcsize

Func pow($num, $power)
    $pow = $num
    For $i = 1 To $power - 1
        $pow *= $num
    Next
    Return $pow
EndFunc   ;==>pow
Func did(ByRef $bytes, $size)
    $count = 0
    While $bytes >= $size
        $count += 1
        $bytes -= $size
    WEnd
    Return $count
EndFunc   ;==>did
Func parsefile($file, $calcdate)
    $color = "BLUE" 
    Switch getdate($calcdate)
        Case 1
            $color = "RED" 
        Case 2
            $color = "BROWN" 
        Case 3
            $color = "ORANGE" 
        Case 4
            $color = "GREEN" 
    EndSwitch
    If getext($file) = "txt"  Or $color <> "BLUE"  Then Return "<FONT color=" & $color & ">" & $file & "</FONT>" 
    Return $file
EndFunc   ;==>parsefile

Func getext($name)
    If StringInStr($name, ".") Then
        $string = StringSplit($name, ".")
        Return $string[2]
    EndIf
    Return ""
EndFunc   ;==>getext
Func getdate($date)
    If _DateDiff("D", $date, _NowCalc()) <= 1 Then Return 1
    If _DateDiff("D", $date, _NowCalc()) <= 2 Then Return 2
    If _DateDiff("D", $date, _NowCalc()) <= 3 Then Return 3
    If _DateDiff("D", $date, _NowCalc()) <= 4 Then Return 4
    Return 0
EndFunc   ;==>getdate

Btw try to explain better exactly what u want

Only two things are infinite, the universe and human stupidity, and i'm not sure about the former -Alber EinsteinPractice makes perfect! but nobody's perfect so why practice at all?http://forum.ambrozie.ro

Link to comment
Share on other sites

Hi Dude,,

That's absolutely awesome. I'm just speechless when I'm trying to run your code. Millions Thanks, dude.

In fact, I am trying to write a script which is reading the ".txt" files in a directory and report in a txt file (which you've kinldy made for me in "html" format). Big thanks for that, dude. That's exactly what I am trying to achieve.

In my old script, I was trying to add some extra checking like reading the individual txt file in the directory and if there's first error detected while reading the file, the script excit from the reading loop and report in the "html" under the contents column with the exact place where the error found.

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

#include <File.au3>

#Include <Array.au3>

$Loc_logf = "C:\Temp\"

$Loc_report = "C:\Report.txt"

$report = FileOpen($Loc_report,2)

$FileList=_FileListToArray($Loc_logf,"*.txt",1)

If @Error=1 Then

MsgBox (0,"","No Files\Folders Found.")

Exit

EndIf

Dim $size[uBound($FileList)+1]

Dim $time[uBound($FileList)+1]

$contents = ""

$header = " File Name File Size Last Modified Contents"&@CRLF

For $i=1 To $FileList[0]

$size[$i]=FileGetSize($Loc_logf&$FileList[$i])

$time=FileGetTime($Loc_logf&$FileList[$i])

$time1=FileGetTime($Loc_logf&$FileList[$i],1)

$time2=FileGetTime($Loc_logf&$FileList[$i],2)

$contents = $contents &"("& $i &")" &$FileList[$i] & @TAB & @TAB & @TAB & $size[$i]&" bytes" & @TAB & @TAB &$time[2]&"/"&$time[1]&"/"&$time[0]&" - "& $time[3]&":"&$time[4]&":"&$time[5]

$file_log = fileopen($Loc_logf &""&$FileList[$i],0)

while 1

$line_log = filereadline($file_log)

If @error = -1 then exitloop

If StringInstr($line_log,"error") > 0 then

$contents = $contents & @tab & $line_log & @CRLF

exitloop

Endif

If StringInstr($line_log,"error") <> 0 then

$contents = ""&@CRLF

exitloop

Endif

wend

fileclose($file_log)

Next

$contents = $header & @CRLF & $contents & @CRLF

FileWrite($report,$contents)

FileClose($report)

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

I attached with 3 test sample files to try out the error checking script line. You save them in your C:\Temp. <_<

I'll try to add in your html script. :)

Once again, thanks dude.

yours friendly,

REAL4U

test.zip

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