Jump to content

Little help


leveex
 Share

Recommended Posts

i found this:

; AutoIt Version: 3.0
; Language:    English
; Platform:    Win9x/NT/XP
; Author:        jos van der Zande
;
; Find files in directory and subdirectories and return it in an Array, all coded in Autoit3
; 
Dim $FILES
Dim $DIR="c:\" ; specify the directory to search
Dim $FILEMASK="*.txt"                      ; specify the filemask

$FILES = _GetFileList($DIR, $FILEMASK)
For $X = 0 To UBound($FILES)-1
   MsgBox(0,'test:' & $X,$FILES[$X])
Next 
Exit
;********************************************************************************
;Recursive search for filemask
;********************************************************************************

Func _GetFileList($T_DIR,$T_MASK)
   Dim $N_DIRNAMES[200000]; max number of directories that can be scanned
   Local $N_DIRCOUNT = 0
   Local $N_FILE
   Local $N_SEARCH
   Local $N_TFILE
   Local $N_OFILE
   Local $T_FILENAMES
   Local $T_FILECOUNT
   Local $T_DIRCOUNT = 1
  ; remove the end \ If specified
   If StringRight($T_DIR,1) = "\" Then $T_DIR = StringTrimRight($T_DIR,1)
   $N_DIRNAMES[$T_DIRCOUNT] = $T_DIR
  ; Exit if base dir doesn't exists
   If Not FileExists($T_DIR) Then Return 0
  ; keep on looping until all directories are scanned
   While $T_DIRCOUNT > $N_DIRCOUNT
      $N_DIRCOUNT = $N_DIRCOUNT + 1
     ; find all subdirs in this directory and save them in a array
      $N_SEARCH = FileFindFirstFile($N_DIRNAMES[$N_DIRCOUNT] & "\*.*")  
      While 1
         $N_FILE = FileFindNextFile($N_SEARCH) 
         If @error Then ExitLoop
        ; skip these references
         If $N_FILE = "." Or $N_FILE = ".." Then ContinueLoop
         $N_TFILE = $N_DIRNAMES[$N_DIRCOUNT] & "\" & $N_FILE
        ; if Directory than add to the list of directories to be processed 
         If StringInStr(FileGetAttrib( $N_TFILE ),"D") > 0 Then
            $T_DIRCOUNT = $T_DIRCOUNT + 1
            $N_DIRNAMES[$T_DIRCOUNT] = $N_TFILE
         EndIf
      Wend
      FileClose($N_SEARCH)
     ; find all Files that mtach the MASK
      $N_SEARCH = FileFindFirstFile($N_DIRNAMES[$N_DIRCOUNT] & "\" & $T_MASK )  
      If $N_SEARCH = -1 Then ContinueLoop
      While 1
         $N_FILE = FileFindNextFile($N_SEARCH) 
         If @error Then ExitLoop
        ; skip these references
         If $N_FILE = "." Or $N_FILE = ".." Then ContinueLoop
         $N_TFILE = $N_DIRNAMES[$N_DIRCOUNT] & "\" & $N_FILE
        ; if Directory than add to the list of directories to be processed 
         If StringInStr(FileGetAttrib( $N_TFILE ),"D") = 0 Then
            $T_FILENAMES  = $T_FILENAMES & $N_TFILE & @CR
            $T_FILECOUNT = $T_FILECOUNT + 1
           ;MsgBox(0,'filecount ' & $T_FILECOUNT ,$N_TFILE)
         EndIf
      Wend
      FileClose($N_SEARCH)
   Wend
   $T_FILENAMES  = StringTrimRight($T_FILENAMES,1)
   $N_OFILE = StringSplit($T_FILENAMES,@CR)
   Return( $N_OFILE )
EndFunc  ;==>_GetFileList
Link to comment
Share on other sites

Yes this is helpful, but this only search for for files that are in file mask. Or?

I have playing a little bit and found some thing like this:

$file = FileOpen("D:\example.txt", 0)
; Check if file opened for reading OK
If $file = -1 Then
    MsgBox(0, "Error", "Unable to open file.")
    Exit
EndIf
$amount = 0
; Read in lines of text until the EOF is reached
While 1


    $line = FileReadLine($file)
    If @error = -1 Then ExitLoop
    $len = StringLen($line)
    While 1

        $result1= StringTrimLeft($line, $amount)
        $result2= StringTrimRight($result1, $len-12-$amount)

    FileChangeDir("C:\")
    If FileExists($result2) Then 
    Else
        MsgBox(4096,"DOES NOT EXISTS!!!", $result2)
    EndIf

    $amount = $amount + 13
        If $amount>= $len Then ExitLoop

    WEnd
Wend

FileClose($file)
MsgBox(4096,"COMPLETE", "STATUS OK")

But problem is because this don't look in subfolders (that isn't so big problem)

Problem that badgering me is how to tell script that it needs to delete those files?

Link to comment
Share on other sites

I thought that it' will be easier, but can't get it to search in subfolders.

I try it to combine both script into one but it wasnt successful.

Don't understand which command exactly is from first script to look in subfolders?

Link to comment
Share on other sites

won't work, even won't close window

maybe I am done something wrong.

Here is what have I done.

;Find text script;
$file = 'test.txt'
RunWait(@ComSpec & ' /c del /s/q "' & $file & '"', 'C:\', @SW_HIDE)
; Check if file opened for reading OK
If $file = -1 Then
    MsgBox(0, "Error", "Unable to open file.")
    Exit
EndIf

$amount = 0
; Read in lines of text until the EOF is reached
While 1


    $line = FileReadLine($file)
    If @error = -1 Then ExitLoop
    $len = StringLen($line)
    While 1

        $result1= StringTrimLeft($line, $amount)
        $result2= StringTrimRight($result1, $len-13-$amount)

    FileChangeDir("C:\Input")
    If FileExists($result2) Then 
        FileDelete($result2)
    Else
        MsgBox(4096,"DOES NOT EXISTS!!!", $result2)
    EndIf

    $amount = $amount + 13
        If $amount>= $len Then ExitLoop

    WEnd
Wend

FileClose($file)
MsgBox(4096,"COMPLETE", "STATUS OK")
Link to comment
Share on other sites

;Find text script;
$file = 'test.txt'
RunWait(@ComSpec & ' /c del /s/q "' & $file & '"', 'C:\', @SW_HIDE)
; Check if file opened for reading OK
If $file = -1 Then
    MsgBox(0, "Error", "Unable to open file.")
    Exit
EndIf

$amount = 0
; Read in lines of text until the EOF is reached
While 1


    $line = FileReadLine($file)
    If @error = -1 Then ExitLoop
    $len = StringLen($line)
    While 1

        $result1= StringTrimLeft($line, $amount)
        $result2= StringTrimRight($result1, $len-13-$amount)

    FileChangeDir("C:\Input")
    If FileExists($result2) Then
        FileDelete($result2)
    Else
        MsgBox(4096,"DOES NOT EXISTS!!!", $result2)
    EndIf

    $amount = $amount + 13
        If $amount>= $len Then ExitLoop

    WEnd
Wend

FileClose($file)
MsgBox(4096,"COMPLETE", "STATUS OK")

where is the problem....

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