Sign in to follow this  
Followers 0
Raffav

IF statement search value on arrays

10 posts in this topic

#1 ·  Posted (edited)

Hello

sorry for bad English

i need to chose some files to be excluded from $filearray or Filegetsize in this part of the script, i think that using FileOpenDialog funtion in some way can do that but dont have idea how to do

thanks for any help

#include <File.au3>
$fileArray = _FileListToArray(@ScriptDir, "*.pst", 1)
$fileSize = 0
_SmallPst($fileArray, $fileSize)
Func _SmallPst($fileArray, $fileSize)
    Local $array[2]
    ;$fileName = ""
;~  MsgBox(0,"",$fileArray[2])
    $size1 = 30e10 ; Set a big number to start with
    For $i = 1 To UBound($fileArray) - 1

        $fileSize = FileGetSize($fileArray[$i])
        If $fileSize < $size1 And $fileSize > 271360 And $fileArray[$i] <> "archive.pst" Then; Now see if this file is even smaller
            $size1 = $fileSize
            $urNomePst = $fileArray[$i]
        EndIf
    Next
;~  $uverifc = $uverifc + 2
    MsgBox(0, "Smallest file", "Smallest file is " & " " & $size1 & " " & $urNomePst) ;!!!!!!!!!!!!
    $array[0] = $urNomePst
    $array[1] = $size1
    Return $array


EndFunc   ;==>_SmallPst
Edited by Raffav

Share this post


Link to post
Share on other sites



Please post code people can run.

Chances are you'll learn your answer while creating a reproducer.

 

sorry for that

there is the part working

#include <File.au3>
$fileArray = _FileListToArray(@ScriptDir, "*.pst", 1)
$fileSize = 0
_SmallPst($fileArray, $fileSize)
Func _SmallPst($fileArray, $fileSize)
    Local $array[2]
    ;$fileName = ""
;~  MsgBox(0,"",$fileArray[2])
    $size1 = 30e10 ; Set a big number to start with
    For $i = 1 To UBound($fileArray) - 1

        $fileSize = FileGetSize($fileArray[$i])
        If $fileSize < $size1 And $fileSize > 271360 And $fileArray[$i] <> "archive.pst" Then; Now see if this file is even smaller
            $size1 = $fileSize
            $urNomePst = $fileArray[$i]
        EndIf
    Next
;~  $uverifc = $uverifc + 2
    MsgBox(0, "Smallest file", "Smallest file is " & " " & $size1 & " " & $urNomePst) ;!!!!!!!!!!!!
    $array[0] = $urNomePst
    $array[1] = $size1
    Return $array


EndFunc   ;==>_SmallPst 

Share this post


Link to post
Share on other sites

Raffav,

i need to chose some files to be excluded from Filegetsize

 

Choose them based on what criteria, size, name, location, etc.?


Forum Rules         Procedure for posting code

"I like pigs.  Dogs look up to us.  Cats look down on us.  Pigs treat us as equals."

- Sir Winston Churchill

Share this post


Link to post
Share on other sites

Raffav,

 

 

Choose them based on what criteria, size, name, location, etc.?

The name

Maybe using the open file dialog function can be done

And I will correct the first post

I think is more logical exclude from $filearray instead from filegetsize

Thanks for any help

Share this post


Link to post
Share on other sites

Raffav,

Then you can use the following from M23...

_FileListToArrayRec($path, "*|archive.pst", 1, 0, 1)

This is how I might write a function returning the smallest file size between a range and excluding files by pattern...

#include <File.au3>
#include <array.au3>

Local $path = 'K:\OE' ; change to your path

Local $aFiles = _SmallPst(_FileListToArrayRec($path, "*|archive.pst", 1, 0, 1, 2))
(@error = 0) ? _ArrayDisplay($aFiles) : ConsoleWrite('No Qualifying Files...@ERROR = ' & @error & @LF)

Func _SmallPst($fileArray, $iMaxSize = 10000000, $iMinSize = 0)

    ; $filearray = list of files
    ; $iMaxSize  = test files smaller than this
    ; $iMinSize  = test files larger than this

    If Not IsArray($fileArray) Then Return SetError(1)

    Local $iSavSize = $iMaxSize, $sSavName, $iTSze

    For $i = 1 To UBound($fileArray) - 1

        $iTSze = FileGetSize($filearray[$i])

        ;ConsoleWrite(stringformat('file = %-50s  $itsze = %08i  $imax = %08i  $imin = %08i',$filearray[$i],$iTSze,$iMaxSize,$iMinSize) & @LF)

        If ($iTSze < $iMaxSize And $iTSze > $iMinSize) And $iTSze < $iSavSize Then
            $iSavSize = $iTSze
            $sSavName = $fileArray[$i]
        EndIf

    Next

    If $sSavName = '' Then Return SetError(2)

    MsgBox(0, "Smallest file", "Smallest file is " & " " & $iSavSize & " " & $sSavName)

    Local $aRet[2]

    $aRet[0] = $sSavName
    $aRet[1] = $iSavSize

    Return $aRet

EndFunc   ;==>_SmallPst

 If you are not running 3.3.10 then change the error test after the function call.

kylomas


Forum Rules         Procedure for posting code

"I like pigs.  Dogs look up to us.  Cats look down on us.  Pigs treat us as equals."

- Sir Winston Churchill

Share this post


Link to post
Share on other sites

Raffav,

Then you can use the following from M23...

_FileListToArrayRec($path, "*|archive.pst", 1, 0, 1)

This is how I might write a function returning the smallest file size between a range and excluding files by pattern...

#include <File.au3>
#include <array.au3>

Local $path = 'K:\OE' ; change to your path

Local $aFiles = _SmallPst(_FileListToArrayRec($path, "*|archive.pst", 1, 0, 1, 2))
(@error = 0) ? _ArrayDisplay($aFiles) : ConsoleWrite('No Qualifying Files...@ERROR = ' & @error & @LF)

Func _SmallPst($fileArray, $iMaxSize = 10000000, $iMinSize = 0)

    ; $filearray = list of files
    ; $iMaxSize  = test files smaller than this
    ; $iMinSize  = test files larger than this

    If Not IsArray($fileArray) Then Return SetError(1)

    Local $iSavSize = $iMaxSize, $sSavName, $iTSze

    For $i = 1 To UBound($fileArray) - 1

        $iTSze = FileGetSize($filearray[$i])

        ;ConsoleWrite(stringformat('file = %-50s  $itsze = %08i  $imax = %08i  $imin = %08i',$filearray[$i],$iTSze,$iMaxSize,$iMinSize) & @LF)

        If ($iTSze < $iMaxSize And $iTSze > $iMinSize) And $iTSze < $iSavSize Then
            $iSavSize = $iTSze
            $sSavName = $fileArray[$i]
        EndIf

    Next

    If $sSavName = '' Then Return SetError(2)

    MsgBox(0, "Smallest file", "Smallest file is " & " " & $iSavSize & " " & $sSavName)

    Local $aRet[2]

    $aRet[0] = $sSavName
    $aRet[1] = $iSavSize

    Return $aRet

EndFunc   ;==>_SmallPst

 If you are not running 3.3.10 then change the error test after the function call.

kylomas

Thanks

now iam getting stuck how to make the FileOpenDialog to work (Didn't find another way)  when i select more than 1 works, but if i select only one the fileoepndialog var get the diretoryfile1 instead of the diretory file1 so i cant split it 

#include <File.au3>
#include <array.au3>
#include <FileConstants.au3>
#include <MsgBoxConstants.au3>
Local  $Message = "Hold down Ctrl or Shift to choose multiple files."

$var = FileOpenDialog($message, @ScriptDir & "\", "Outlook (*.pst)",1+4)
MsgBox(0, "1", $var)
;~ _ArrayDisplay($var, "$FileList")
If @error Then
    MsgBox(4096, "", "No File(s) chosen")
Else
;~  ;$var = StringReplace($var, "|", @CRLF)
;~  ;MsgBox(4096, "", "You chose " & $var)
EndIf


;~ $var = FileOpenDialog("", @DesktopDir, "Images (*.jpg;*.bmp;*.png)", 1+4)
$files = StringSplit($var, "|",2)
MsgBox(0, "2", $files[0])
MsgBox(0, "2b", UBound($files) - 1)
Global $file[(UBound($files) - 1) + 1]
For $i = 1 To UBound($files) - 1
    $file[$i] = $files[$i]
;~     ConsoleWrite("File "&$i&" "&$file&@CRLF) ; Do somethi5ng with file
Next
;~ _ArrayDisplay($file, "$FileList")
;~     ConsoleWrite("File "& _ArrayToString($files,";",1)& @CR)
MsgBox(0, "3", _ArrayToString($files, ";", 1))

Local $aFiles = _SmallPst(_FileListToArrayRec(@ScriptDir, "*.pst|" & _ArrayToString($file, ";", 1), 1, 0, 0, 0))
(@error = 0) ? _ArrayDisplay($aFiles) : ConsoleWrite('No Qualifying Files...@ERROR = ' & @error & @LF)

Func _SmallPst($fileArray, $iMaxSize = 30e10, $iMinSize = 0)

    ; $filearray = list of files
    ; $iMaxSize  = test files smaller than this
    ; $iMinSize  = test files larger than this

    If Not IsArray($fileArray) Then Return SetError(1)

    Local $iSavSize = $iMaxSize, $sSavName, $iTSze

    For $i = 1 To UBound($fileArray) - 1

        $iTSze = FileGetSize($filearray[$i])

        ;ConsoleWrite(stringformat('file = %-50s  $itsze = %08i  $imax = %08i  $imin = %08i',$filearray[$i],$iTSze,$iMaxSize,$iMinSize) & @LF)

        If ($iTSze < $iMaxSize And $iTSze > $iMinSize) And $iTSze < $iSavSize Then
            $iSavSize = $iTSze
            $sSavName = $fileArray[$i]
        EndIf

    Next

    If $sSavName = '' Then Return SetError(2)

    MsgBox(0, "Smallest file", "Smallest file is " & " " & $iSavSize & " " & $sSavName)

    Local $aRet[2]

    $aRet[0] = $sSavName
    $aRet[1] = $iSavSize

    Return $aRet

EndFunc   ;==>_SmallPst

Share this post


Link to post
Share on other sites

Raffav,

You have to detect whether the user selected one or more than one file and process the list accordingly.  Something like this...

#include <File.au3>
#include <array.au3>
#include <FileConstants.au3>
#include <MsgBoxConstants.au3>
Local  $Message = "Hold down Ctrl or Shift to choose multiple files."

$var = FileOpenDialog($message, @ScriptDir & "\", "Outlook (*.dbx)",1+4)
If @error Then
    MsgBox(4096, "", "No File(s) chosen")
Else
    if stringinstr($var,'|') = 0 then                       ; if not more than 1 file selected
        $var = stringregexpreplace($var,'.*\\(.*)','$1')    ;    get filename only
    Else                                                    ; else
        $var = stringtrimleft($var,stringinstr($var,'|'))   ;    strip off path
        $var = stringreplace($var,'|',';')                  ;    change sep char to semi-colon
    endif
EndIf

ConsoleWrite($var & @LF)

Local $aFiles = _SmallPst(_FileListToArrayRec(@ScriptDir, "*.pst|" & $var, 1, 0, 0, 0))
(@error = 0) ? _ArrayDisplay($aFiles) : ConsoleWrite('No Qualifying Files...@ERROR = ' & @error & @LF)

Func _SmallPst($fileArray, $iMaxSize = 30e10, $iMinSize = 0)

    ; $filearray = list of files
    ; $iMaxSize  = test files smaller than this
    ; $iMinSize  = test files larger than this

    If Not IsArray($fileArray) Then Return SetError(1)

    Local $iSavSize = $iMaxSize, $sSavName, $iTSze

    For $i = 1 To UBound($fileArray) - 1

        $iTSze = FileGetSize($filearray[$i])

        ;ConsoleWrite(stringformat('file = %-50s  $itsze = %08i  $imax = %08i  $imin = %08i',$filearray[$i],$iTSze,$iMaxSize,$iMinSize) & @LF)

        If ($iTSze < $iMaxSize And $iTSze > $iMinSize) And $iTSze < $iSavSize Then
            $iSavSize = $iTSze
            $sSavName = $fileArray[$i]
        EndIf

    Next

    If $sSavName = '' Then Return SetError(2)

    MsgBox(0, "Smallest file", "Smallest file is " & " " & $iSavSize & " " & $sSavName)

    Local $aRet[2]

    $aRet[0] = $sSavName
    $aRet[1] = $iSavSize

    Return $aRet

EndFunc   ;==>_SmallPst

Forum Rules         Procedure for posting code

"I like pigs.  Dogs look up to us.  Cats look down on us.  Pigs treat us as equals."

- Sir Winston Churchill

Share this post


Link to post
Share on other sites

#9 ·  Posted (edited)

 

Raffav,

You have to detect whether the user selected one or more than one file and process the list accordingly.  Something like this...

#include <File.au3>
#include <array.au3>
#include <FileConstants.au3>
#include <MsgBoxConstants.au3>
Local  $Message = "Hold down Ctrl or Shift to choose multiple files."

$var = FileOpenDialog($message, @ScriptDir & "\", "Outlook (*.dbx)",1+4)
If @error Then
    MsgBox(4096, "", "No File(s) chosen")
Else
    if stringinstr($var,'|') = 0 then                       ; if not more than 1 file selected
        $var = stringregexpreplace($var,'.*\\(.*)','$1')    ;    get filename only
    Else                                                    ; else
        $var = stringtrimleft($var,stringinstr($var,'|'))   ;    strip off path
        $var = stringreplace($var,'|',';')                  ;    change sep char to semi-colon
    endif
EndIf

ConsoleWrite($var & @LF)

Local $aFiles = _SmallPst(_FileListToArrayRec(@ScriptDir, "*.pst|" & $var, 1, 0, 0, 0))
(@error = 0) ? _ArrayDisplay($aFiles) : ConsoleWrite('No Qualifying Files...@ERROR = ' & @error & @LF)

Func _SmallPst($fileArray, $iMaxSize = 30e10, $iMinSize = 0)

    ; $filearray = list of files
    ; $iMaxSize  = test files smaller than this
    ; $iMinSize  = test files larger than this

    If Not IsArray($fileArray) Then Return SetError(1)

    Local $iSavSize = $iMaxSize, $sSavName, $iTSze

    For $i = 1 To UBound($fileArray) - 1

        $iTSze = FileGetSize($filearray[$i])

        ;ConsoleWrite(stringformat('file = %-50s  $itsze = %08i  $imax = %08i  $imin = %08i',$filearray[$i],$iTSze,$iMaxSize,$iMinSize) & @LF)

        If ($iTSze < $iMaxSize And $iTSze > $iMinSize) And $iTSze < $iSavSize Then
            $iSavSize = $iTSze
            $sSavName = $fileArray[$i]
        EndIf

    Next

    If $sSavName = '' Then Return SetError(2)

    MsgBox(0, "Smallest file", "Smallest file is " & " " & $iSavSize & " " & $sSavName)

    Local $aRet[2]

    $aRet[0] = $sSavName
    $aRet[1] = $iSavSize

    Return $aRet

EndFunc   ;==>_SmallPst

Once again thanks i will dive a try on your way

but

i have done it in another way,  ;)

maybe is  nasty or not perfect  but for now is workings

and happy new year

#include <File.au3>
#include <array.au3>
#include <FileConstants.au3>
#include <MsgBoxConstants.au3>
Local $Message = "Hold down Ctrl or Shift to choose multiple files."
$var = FileOpenDialog($Message, @ScriptDir & "\", "Outlook (*.pst)", 1 + 4)
MsgBox(0, "1", $var)
;~ _ArrayDisplay($var, "$FileList")
If @error Then
    MsgBox(4096, "", "No File(s) chosen")
EndIf


;~ $var = FileOpenDialog("", @DesktopDir, "Images (*.jpg;*.bmp;*.png)", 1+4)
$files = StringSplit($var, "|", 2)
Global $file[(UBound($files))]
If UBound($files) = 1 Then
    MsgBox(0, "111", "UNICO ARQUIVO SELECIONADO")
    MsgBox(0, "2", $files[0])
    MsgBox(0, "2b", UBound($files))

;~  Global $file[(UBound($files))]
    For $i = 0 To UBound($files) - 1
        $file[$i] = $files[$i]
        ConsoleWrite("File 111 " & $i & " " & $file[$i] & @CRLF) ; Do somethi5ng with file
    Next

    ConsoleWrite("File33 111 " & _ArrayToString($file, ";", 0) & @CR)


    Local $sDrive = "", $sDir = "", $sFilename = "", $sExtension = ""
    Local $aPathSplit = _PathSplit(_ArrayToString($file, ";", 0), $sDrive, $sDir, $sFilename, $sExtension)

    MsgBox(0, "4", $aPathSplit[3] & $aPathSplit[4])
    MsgBox(0, "5", $aPathSplit[0])



ElseIf UBound($files) > 1 Then
    MsgBox(0, "222", "MAIS DE UM ARQUIVO SELECIONADO")
    MsgBox(0, "2", $files[0])
    MsgBox(0, "2b", UBound($files))

;~  Global $file[(UBound($files))]
    For $i = 1 To UBound($files) - 1
        $file[$i] = $files[$i]
        ConsoleWrite("File 222 " & $i & " " & $file[$i] & @CRLF) ; Do somethi5ng with file
    Next

    ConsoleWrite("File33 222 " & _ArrayToString($file, ";", 1) & @CR)


    Local $sDrive = "", $sDir = "", $sFilename = "", $sExtension = ""
    Local $aPathSplit = _PathSplit(_ArrayToString($file, ";", 1), $sDrive, $sDir, $sFilename, $sExtension)

    MsgBox(0, "4", $aPathSplit[3] & $aPathSplit[4])
    MsgBox(0, "5", $aPathSplit[0])


EndIf
Edited by Raffav

Share this post


Link to post
Share on other sites

Great, good luck and Happy New Year to you too!


Forum Rules         Procedure for posting code

"I like pigs.  Dogs look up to us.  Cats look down on us.  Pigs treat us as equals."

- Sir Winston Churchill

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