Sign in to follow this  
Followers 0
MaCgyver

Read contents from several different files and email that info

8 posts in this topic

I'm trying to all files from a particular directory. I know how to read from one particular file, but how do I get it to read all files? I just need some pointers.

Share this post


Link to post
Share on other sites



I'm trying to all files from a particular directory. I know how to read from one particular file, but how do I get it to read all files? I just need some pointers.

FileRead()?

# MY LOVE FOR YOU... IS LIKE A TRUCK- #

Share this post


Link to post
Share on other sites

FileRead()?

fileread() everything in the directory? I'm trying to see how that can be done.

I think I need to filefindfirstfile & filefindnextfile to get the names of the files to read from.

Share this post


Link to post
Share on other sites

fileread() everything in the directory? I'm trying to see how that can be done.

I think I need to filefindfirstfile & filefindnextfile to get the names of the files to read from.

Maybe something like:

$File = _FileSearch("*", 0) ;* is a wildcard
MsgBox(0, "", $File[0]) ;Ammount of files
$Files = $File[0]
For $i = 1 To $Files
    FileRead($File & "[" & $i & "]")
Next

Func _FileSearch($sIstr, $bSF)
; $bSF = 1 means looking in subfolders
; $sSF = 0 means looking only in the current folder.
; An array is returned with the full path of all files found. The pos [0] keeps the number of elements.
  Local $sCriteria, $sBuffer, $iH, $iH2, $sCS, $sCF, $sCF2, $sCP, $sFP, $sOutPut = '', $aNull[1]
  $sCP = StringLeft($sIstr, StringInStr($sIstr, '\', 0, -1))
  If $sCP = '' Then $sCP = @WorkingDir & '\'
  $sCriteria = StringTrimLeft($sIstr, StringInStr($sIstr, '\', 0, -1))
  If $sCriteria = '' Then $sCriteria = '*.*'
  
;To begin we seek in the starting path.
  $sCS = FileFindFirstFile($sCP & $sCriteria)
  If $sCS <> - 1 Then
  While 1
     $sCF = FileFindNextFile($sCS)
     If @error Then
        FileClose($sCS)
        ExitLoop
     EndIf
     If $sCF = '.' Or $sCF = '..' Then ContinueLoop
     $sOutPut = $sOutPut & $sCP & $sCF & @LF
  Wend
  EndIf
  
;And after, if needed, in the rest of the folders.
  If $bSF = 1 Then
     $sBuffer = @CR & $sCP & '*' & @LF;The buffer is set for keeping the given path plus a *.
     Do
        $sCS = StringTrimLeft(StringLeft($sBuffer, StringInStr($sBuffer, @LF, 0, 1) - 1),1);current search.
        $sCP = StringLeft($sCS, StringInStr($sCS, '\', 0, -1));Current search path.
        $iH = FileFindFirstFile($sCS)
        If $iH <> - 1 Then
        While 1
           $sCF = FileFindNextFile($iH)
           If @error Then
              FileClose($iH)
              ExitLoop
           EndIf
           If $sCF = '.' Or $sCF = '..' Then ContinueLoop
           If StringInStr(FileGetAttrib($sCP & $sCF), 'd') Then
              $sBuffer = @CR & $sCP & $sCF & '\*' & @LF & $sBuffer;Every folder found is added in the begin of buffer
              $sFP = $sCP & $sCF & '\';                            for future searches
              $iH2 = FileFindFirstFile($sFP & $sCriteria);         and checked with the criteria.
              If $iH2 <> - 1 Then
              While 1
                 $sCF2 = FileFindNextFile($iH2)
                 If @error Then
                    FileClose($iH2)
                    ExitLoop
                 EndIf
                 If $sCF2 = '.' Or $sCF2 = '..' Then ContinueLoop
                 $sOutPut = $sOutPut & $sFP & $sCF2 & @LF;Found items are put in the Output.
              Wend
              EndIf
           EndIf
        Wend
        EndIf
        $sBuffer = StringReplace($sBuffer, @CR & $sCS & @LF, '')
     Until $sBuffer = ''
  EndIf
  
  If $sOutPut = '' Then
     $aNull[0] = 0
     Return $aNull
  Else
     Return StringSplit(StringTrimRight($sOutPut, 1), @LF)
  EndIf
EndFunc ;==>_FileSearch

Something like that, Though, theres probly another way, I cant seem to find out how to set each different FileRead to a different variable, Unless you manually go in and put each one down.


# MY LOVE FOR YOU... IS LIKE A TRUCK- #

Share this post


Link to post
Share on other sites

#5 ·  Posted (edited)

I am working with this. I just can't get the fileread part to work. Nothing shows up.

#include <Inet.au3>

; Shows the filenames of all files in the current directory

$search = FileFindFirstFile("\\sv000bktrade\apps\Transend\Transend_Scrubs\*.*")

$f2r = FileOpen($search,0)

; Check if the search was successful

If $search = -1 Then

MsgBox(0, "Error", "No files/directories matched the search pattern")

Exit

EndIf

While 1

$file = FileFindNextFile($search)

If @error Then ExitLoop

$chars = FileRead($f2r)

MsgBox(4096, "File:", $file)

MsgBox(0, "Char read:", $chars)

FileClose($f2r)

WEnd

Edited by MaCgyver

Share this post


Link to post
Share on other sites

I am working with this. I just can't get the fileread part to work. Nothing shows up.

I Have no idea. Ive had this problem with fileread before.

# MY LOVE FOR YOU... IS LIKE A TRUCK- #

Share this post


Link to post
Share on other sites

I Have no idea. Ive had this problem with fileread before.

Gonna need to use clipget() and clipput().

I will post up if it works.

Share this post


Link to post
Share on other sites

This seems to be working.

#include <Inet.au3>

; Shows the filenames of all files in the current directory

$search = FileFindFirstFile("\\sv000bktrade\apps\Transend\Transend_Scrubs\*.*")

;$f2r = FileOpen($search,0)

; Check if the search was successful

If $search = -1 Then

MsgBox(0, "Error", "No files/directories matched the search pattern")

Exit

EndIf

While 1

$file = FileFindNextFile($search)

If @error Then ExitLoop

MsgBox(4096, "File:", $file,2)

clipput($file)

$f2g = clipget()

$f2o = fileopen("\\sv000bktrade\apps\transend\transend_scrubs\"&$f2g,0)

$f2r = fileread($f2o)

msgbox(0,"FileRead",$f2r,2)

FileClose($f2r)

WEnd

; Close the search handle

FileClose($search)

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
Sign in to follow this  
Followers 0