gh0stid

Newb Question, wanna check fileexist, rename if so, and check ownership before copying

8 posts in this topic

#1 ·  Posted (edited)

Hello, again ...

 

Ive been working a lot on a script lately .. unfortunately I just.. cannot figure to get it to work ( im no coder.. )
I start a new thread , cause the old one isoutdated, the code, have changed a lot since its creation

 

so far..

1 - I need to search for every files with specific extensions on C:\ G:\ H:\ drive and get their filesize. ---- Solved Using UDF _DirGetSizeEx

2- Output everything to log --- Solved too

3- Proceed to copy IF for drive G: ( another function ) @username match file ownership --- Not yet figured out.. 

Local $aFilesG = _DirGetSizeEx("\\fs1\groupes\DSTH\C - SGPI-SEFI\SGPI\PROJETS\T1200-T1299\T1206\4.0 Documents administratifs\Correspondance\", "*.nsf", 1)

If IsArray($aFilesG) Then
    ;FileWriteLine($hLogFile, "[" & _Now() & "] -> C:\ " & $aFiles[0][0] & " fichiers trouves pour une taille de " & _ReadableSize($aFiles[0][1]))
    _ProcessNSFCopyG($aFilesG)
EndIf


Func _ProcessNSFCopyG($aNSFFilesG)
    Local Static $x = 0
    Local $suffixe
$path = $aNSFFilesG[$i][0]

    For $i = 1 To $aNSFFilesG[0][0]
GetOwner($path)

Next
EndFunc


Func GetOwner()
    Local $computer = "."
    Local $wmi = ObjGet("winmgmts:{impersonationLevel=impersonate}!\\" & $computer & "\root\cimv2")

    Dim $res
    $res = $wmi.ExecQuery("ASSOCIATORS OF {Win32_LogicalFileSecuritySetting='" & $path & "'} WHERE AssocClass=Win32_LogicalFileOwner ResultRole=Owner")

    For $val In $res
        Return $val.AccountName
    Next
EndFunc

Tried that.. no succes so far... and im sure its pretty obvious why but once again, cant figure it out . . ( it is only a TEST' not the actual code.. ) 

4- If ownership match, proceed to copy, to $storage, If upon copy FileExist, rename to $sFilename_1."extension of the file" --- having trouble here too ...

heres the code.. 

#include <Date.au3>
#include <Array.au3>
#include <File.au3>

Local $logfile = "c:\bulk\NSF.log"
Local $storage = "C:\bulk\backup_test\" & @UserName & "\"

Local $hLogFile = FileOpen($logfile, 1) ;1 = append au fichier, utiliser 2 si on veut overwrite


; ##### Pour le traitement sur c:\ g:\ h:\ ################################################################################
;creation des variables de recherche a l'aide de la fonction homemade _DirGetSizeEx
FileWriteLine($hLogFile, "[" & _Now() & "] Recherche des fichiers NSF NDK et INI sur C:\ G:\ et H:\ pour l'utilisateur " & @USERNAME)
Local $aFiles = _DirGetSizeEx("c:\", "*.nsf", 1)
Local $aFilesNDK = _DirGetSizeEx("c:\", "*.ndk", 1)
Local $aFilesINI = _DirGetSizeEx("c:\", "notes.ini", 1)
Local $aFilesG = _DirGetSizeEx("\\fs1\groupes\DSTH\C - SGPI-SEFI\SGPI\PROJETS\T1200-T1299\T1206\4.0 Documents administratifs\Correspondance\", "*.nsf", 1)
Local $aFilesH = _DirGetSizeEx("\\fs2\home\SAVA0002\notes\", "*.nsf", 1)

If IsArray($aFiles) Then
    FileWriteLine($hLogFile, "[" & _Now() & "] -> C:\ " & $aFiles[0][0] & " fichiers trouves pour une taille de " & _ReadableSize($aFiles[0][1]))
    _ProcessNSFCopy($aFiles)
EndIf
If IsArray($aFilesINI) Then
    FileWriteLine($hLogFile, "[" & _Now() & "] -> C:\ " & $aFilesINI[0][0] & " fichiers trouves pour une taille de " & _ReadableSize($aFilesINI[0][1]))
    _ProcessNSFCopy($aFilesINI)
EndIf
If IsArray($aFilesNDK) Then
    FileWriteLine($hLogFile, "[" & _Now() & "] -> C:\ " & $aFilesNDK[0][0] & " fichiers trouves pour une taille de " & _ReadableSize($aFilesNDK[0][1]))
    _ProcessNSFCopy($aFilesNDK)
EndIf
If IsArray($aFilesG) Then
    FileWriteLine($hLogFile, "[" & _Now() & "] -> G:\ " & $aFilesG[0][0] & " fichiers trouves pour une taille de " & _ReadableSize($aFilesG[0][1]))
    _ProcessNSFCopyG($aFilesG)
EndIf
If IsArray($aFilesH) Then
    FileWriteLine($hLogFile, "[" & _Now() & "] -> H:\ " & $aFilesH[0][0] & " fichiers trouves pour une taille de " & _ReadableSize($aFilesH[0][1]))
    _ProcessNSFCopyH($aFilesH)
EndIf
; #################################################################################################################

FileWriteLine($hLogFile, "[" & _Now() & "] Fin")


Func _ProcessNSFCopy($aNSFFiles)

For $i = 1 To $aNSFFiles[0][0]
local Static $x = 0
local $Suffixe

    $SBPath = $aNSFFiles[$i][0]
    $SBType = 3


    If FileExists($SBPath) Then
    $Suffixe = "_" & $x
    $sFileName = _SBfpsplit($SBPath, $SBType)
    $sFileName = $sFileName & $Suffixe
Else
    $sFileName = _SBfpsplit($SBPath, $SBType)
    EndIf



        FileWriteLine($hLogFile, "[" & _Now() & "] Copie de " & $aNSFFiles[$i][0] & " (" & _ReadableSize($aNSFFiles[$i][1]) & ") => " & $storage & $sFileName&@CRLF)

        If FileCopy($aNSFFiles[$i][0], $storage & $sFileName, 9) Then
            $sText = "Copie effectuee avec success"
        Else
            $sText = "ERREUR lors de la copie du fichier"
        EndIf
        FileWriteLine($hLogFile, "[" & _Now() & "] " & $sText)
        $x += 1
Next

EndFunc

Func _ProcessNSFCopyINI($aNSFFilesINI)
For $i = 1 To $aNSFFilesINI[0][0]
    $SBPath = $aNSFFilesINI[$i][0]
    $SBType = 3
    $sFileName = _SBfpsplit($SBPath, $SBType)


        FileWriteLine($hLogFile, "[" & _Now() & "] Copie de " & $aNSFFilesINI[$i][0] & " (" & _ReadableSize($aNSFFilesINI[$i][1]) & ") => " & $storage & $sFileName&@CRLF)

        If FileCopy($aNSFFilesINI[$i][0], $storage & $sFileName, 9) Then
            $sText = "Copie effectuee avec success"
        Else
            $sText = "ERREUR lors de la copie du fichier"
        EndIf
        FileWriteLine($hLogFile, "[" & _Now() & "] " & $sText)
    Next

EndFunc

Func _ProcessNSFCopyNDK($aNSFFilesNDK)
For $i = 1 To $aNSFFilesNDK[0][0]
    $SBPath = $aNSFFilesNDK[$i][0]
    $SBType = 3
    $sFileName = _SBfpsplit($SBPath, $SBType)


        FileWriteLine($hLogFile, "[" & _Now() & "] Copie de " & $aNSFFilesNDK[$i][0] & " (" & _ReadableSize($aNSFFilesNDK[$i][1]) & ") => " & $storage & $sFileName&@CRLF)

        If FileCopy($aNSFFilesNDK[$i][0], $storage & $sFileName, 9) Then
            $sText = "Copie effectuee avec success"
        Else
            $sText = "ERREUR lors de la copie du fichier"
        EndIf
        FileWriteLine($hLogFile, "[" & _Now() & "] " & $sText)
    Next

EndFunc

Func _ProcessNSFCopyG($aNSFFilesG)
For $i = 1 To $aNSFFilesG[0][0]
    $SBPath = $aNSFFilesG[$i][0]
    $SBType = 3
    $sFileName = _SBfpsplit($SBPath, $SBType)

        FileWriteLine($hLogFile, "[" & _Now() & "] Copie de " & $aNSFFilesG[$i][0] & " (" & _ReadableSize($aNSFFilesG[$i][1]) & ") => " & $storage & $sFileName&@CRLF)

        If FileCopy($aNSFFilesG[$i][0], $storage & $sFileName, 9) Then
            $sText = "Copie effectuee avec success"
        Else
            $sText = "ERREUR lors de la copie du fichier"
        EndIf
        FileWriteLine($hLogFile, "[" & _Now() & "] " & $sText)
    Next

EndFunc

Func _ProcessNSFCopyH($aNSFFilesH)
For $i = 1 To $aNSFFilesH[0][0]
    $SBPath = $aNSFFilesH[$i][0]
    $SBType = 3
    $sFileName = _SBfpsplit($SBPath, $SBType)

        FileWriteLine($hLogFile, "[" & _Now() & "] Copie de " & $aNSFFilesH[$i][0] & " (" & _ReadableSize($aNSFFilesH[$i][1]) & ") => " & $storage & $sFileName&@CRLF)

        If FileCopy($aNSFFilesH[$i][0], $storage & $sFileName, 9) Then
            $sText = "Copie effectuee avec success"
        Else
            $sText = "ERREUR lors de la copie du fichier"
        EndIf
        FileWriteLine($hLogFile, "[" & _Now() & "] " & $sText)
    Next

EndFunc
FileClose($hLogFile)


; #FUNCTION#====================================================================================================================
; Name ..........: _DirGetSizeEx ; Description ...: Returns the size in bytes of a file list by extension.
; Syntax ........: _DirGetSizeEx($sDir[, $sMask = "*"[, $iFlag = 0]])
; Parameters ....: $sDir                - The directory to search in.
;                  $sMask               - [optional] Filter for results. Default is "*" (all).
;                                         Filter for result. Multiple filters must be separated by ";"
;                                         Use "|" to separate 3 possible sets of filters: "Include|Exclude|Exclude_Folders"
;                                             Include = Files/Folders to include (default = "*" [all])
;                                             Exclude = Files/Folders to exclude (default = "" [none])
;                                             Exclude_Folders = only used if $iRecur = 1 AND $iReturn <> 2 to exclude defined folders (default = "" [none])
;                  $iFlag               - [optional] 0 (default) = Returns the size
;                                                    1 = Extended mode is On -> returns an array that contains the file of each file (see Remarks).
;                                                    2 = Don't get the size of files in subdirectories (recursive mode is Off)
; Return values .: Success = The size in bytes, or a single dimension array
;                  Failure = -1 and sets the @error flag to 1 if the path doesn't exist.
; Author ........: jguinch
; Remarks .......: If you use the extended mode then the array returned from this function is a single dimension array containing the followingelements:
;                    $aArray[0][0] = Files count
;                    $aArray[0][1] = Total files size
;                    $aArray[1][0] = Full name of 1st file
;                    $aArray[1][1] = Size of 1st file
;                    $aArray[2][0] = Full name of 2nd file
;                    $aArray[2][1] = Size of 2nd file
;                    $aArray[n][1] = Size of nth file
;                    $aArray[n][1] = Size of nth file
;===============================================================================================================================
Func _DirGetSizeEx($sDir, $sMask = "*", $iFlag = 0); OK
    If NOT FileExists($sDir) Then Return SetError(1, 0, -1)
    If NOT StringInStr(FileGetAttrib($sDir), "D") Then Return SetError(1, 0, -1)

    Local $iExtMode = BitAND($iFlag, 1) > 0
    Local $iRecMode = NOT BitAND($iFlag, 2) > 0
    Local $aDirs[1] = [ StringRegExpReplace($sDir, "\\$", "") ]
    Local $iCountDir = 0, $iCountFile = 0, $n = 0, $iSize = 0, $iFullSize = 0
    Local $aFiles[1][2] = [[0]]
    Local $hSearch, $sFileName, $sRegexFilesInclude, $sRegexFilesExclude = "^$", $sRegexFoldersExclude = "^$"

    Local $sRegexMask = StringReplace( StringReplace( StringReplace($sMask, "|", "\|") , "?", "\E(?:.|.?$)\Q"), "*", "\E.*?\Q")
    Local $aFilters = StringSplit($sRegexMask, "\|", 3)

    $sRegexFilesInclude = "(?i)^(?:" & StringRegExpReplace(StringReplace($aFilters[0], ";", "|") , "([^|]+)", "\\Q$1\\E") & ")$"
    If UBound($aFilters) > 1 Then $sRegexFilesExclude = "(?i)^(?:" & StringRegExpReplace(StringReplace($aFilters[1], ";", "|") , "([^|]+)", "\\Q$1\\E") & ")$"
    If UBound($aFilters) > 2 Then $sRegexFoldersExclude = "(?i)^(?:" & StringRegExpReplace(StringReplace($aFilters[2], ";", "|") , "([^|]+)", "\\Q$1\\E") & ")$"

    While 1
        $hSearch = FileFindFirstFile( $aDirs[$n]  & "\*.*"  )
        If $hSearch <> -1 Then

            While 1
                $sFileName = FileFindNextFile($hSearch)
                If @error Then ExitLoop

                If @Extended Then
                    If NOT StringRegExp($sFileName, $sRegexFoldersExclude) Then
                        $iCountDir += 1
                        If $iCountDir >= UBound($aDirs) Then Redim $aDirs[UBound($aDirs) * 2]
                        $aDirs[$iCountDir] = $aDirs[$n] & "\" & $sFileName
                    EndIf
                Else
                    If StringRegExp($sFileName, $sRegexFilesInclude) AND NOT StringRegExp($sFileName, $sRegexFilesExclude) Then
                        $iSize = FileGetSize($aDirs[$n] &  "\" &$sFileName)
                        $iFullSize += $iSize
                        If $iExtMode Then
                            $iCountFile += 1
                            If $iCountFile >= UBound($aFiles) Then Redim $aFiles[UBound($aFiles) * 2][2]
                            $aFiles[$iCountFile][0] = $aDirs[$n] &  "\" &$sFileName
                            $aFiles[$iCountFile][1] = $iSize
                        EndIf
                    EndIf
                EndIf
            WEnd

            If NOT $iRecMode Then ExitLoop
        EndIf

        FileClose($hSearch)

        If $n = $iCountDir Then ExitLoop
        $n += 1
    WEnd

    If NOT $iExtMode Then Return $iFullSize

    Redim $aFiles[$iCountFile + 1][2]
    $aFiles[0][0] = $iCountFile
    $aFiles[0][1] = $iFullSize
    Return $aFiles
EndFunc

Func _ReadableSize($iSize, $decimalplaces = 2)
    Local $aUnites = [1024, "octets", "Ko", "Mo", "Go", "To"]
    For $i = 2 To UBound($aUnites) - 1
        If $iSize < $aUnites[0] Then ExitLoop
        $iSize /= $aUnites[0]
    Next
    Return Round($iSize, $decimalplaces) & " " & $aUnites[$i - 1]
EndFunc

;#FUNCTION# ====================================================================================================
; Name...........: _SBfpsplit
; Description ...: Splits a file path into Drive, path, filename, or extension.
; Syntax.........: _SBfpsplit($SBPath, $SBType);$SBpath (file path to evaluate) , $SBType (option)
; Parameters ....:
;|1 = Drive                 ex. D:
;|2 = Path                   ex. D:\1111\dir\file.txt
;|3 = File name          ex. file.txt
;|4 = Extension           ex. txt
;|5 = Drive letter only ex. D
; Author ........: Scott E. Brown ripandreplace@eset.com
; Modified.......:04/03/2009
; Remarks .......:
; Related .......:
; Link ..........;
; Example .......; _SBfpsplit("D:\1111\dir\file.txt, 1)
;
;$path = "D:\1111\dir\test.txt"
;ConsoleWrite(_SBfpsplit($path, 1) & @CRLF)
;ConsoleWrite(_SBfpsplit($path, 2) & @CRLF)
;ConsoleWrite(_SBfpsplit($path, 3) & @CRLF)
;ConsoleWrite(_SBfpsplit($path, 5) & @CRLF)
; ====================================================================================================
Func _SBfpsplit($SBPath, $SBType);$SBpath = file path to evaluate , $SBType = 1 for Drive, 2 for Path, 3 for File name, 4 for extension, 5 for drive letter only
    Local $SBfile, $SBSplit, $SBdrive, $SBfilepath, $SBnumber
    $SBSplit = StringSplit($SBPath, "\"); split into array
    $SBnumber = $SBSplit[0]; the number of strings returned
    $SBfilepath = ""
    for $1 = 1 to $SBnumber -1
        $SBfilepath = $SBfilepath & $SBSplit[$1] & "\"; path
    Next
    $SBfile = $SBSplit[($SBsplit[0])]; file
    $SBdrive = $SBSplit[1]; drive
    $SBfs = StringSplit($SBPath, "."); split into array
;MsgBox(4096, "Path", $SBSfs[0])
    if $SBfs[0] = 1 then
        $SBExt = ""; no extension found
    Else
        $SBExt = $SBfs[($SBfs[0])]; last . extentsion
    EndIf

    If $SBType = 1 then Return $SBdrive
    If $SBType = 2 then Return $SBfilepath
    If $SBType = 3 then Return $SBfile
    If $SBType = 4 then Return $SBExt
    If $SBType = 5 then Return StringLeft($SBdrive, 1)
EndFunc

 

Thank you ... 
btw. its really important for me, it for a Notes Migration of 1740 users... I dont want to do it by hand.. not, at all!

Edited by gh0stid

Share this post


Link to post
Share on other sites



This is an example of what I use for determining ownership through WMI. Works on file or folder:

#include <MsgBoxConstants.au3>

$sFile = @DesktopDir & "\PDF Javascript.txt"
$oWMI = ObjGet("winmgmts:{impersonationLevel=impersonate}!\\" & @ComputerName & "\root\cimv2")
    If Not IsObj($oWMI) Then Exit(MsgBox($MB_OK, "Returned error: " & @error, "Could not attach to WMI"))

$aItems = $oWMI.ExecQuery("ASSOCIATORS OF {Win32_LogicalFileSecuritySetting='" & $sFile & "'} WHERE AssocClass=Win32_LogicalFileOwner ResultRole=Owner")
    For $sResult In $aItems
        ConsoleWrite($sResult.ReferencedDomainName & ", " & $sResult.AccountName & @CRLF)
    Next

 


√-1 2^3 ∑ π, and it was delicious!

Share this post


Link to post
Share on other sites

This is an example of what I use for determining ownership through WMI. Works on file or folder:

#include <MsgBoxConstants.au3>

$sFile = @DesktopDir & "\PDF Javascript.txt"
$oWMI = ObjGet("winmgmts:{impersonationLevel=impersonate}!\\" & @ComputerName & "\root\cimv2")
    If Not IsObj($oWMI) Then Exit(MsgBox($MB_OK, "Returned error: " & @error, "Could not attach to WMI"))

$aItems = $oWMI.ExecQuery("ASSOCIATORS OF {Win32_LogicalFileSecuritySetting='" & $sFile & "'} WHERE AssocClass=Win32_LogicalFileOwner ResultRole=Owner")
    For $sResult In $aItems
        ConsoleWrite($sResult.ReferencedDomainName & ", " & $sResult.AccountName & @CRLF)
    Next

 

Unfortunately it wont work for my needs, I use Network Path in some case.. 

MsgBox('', '', _fileOwner(@AppDataDir))
MsgBox('', '', @UserName)
MsgBox('', '', @ScriptFullPath)

Func _fileOwner($varname)


    Dim $objSD
    Local $oWMIService = ObjGet("winmgmts:")
    Local $oFolderSecuritySettings = $oWMIService.Get("Win32_LogicalFileSecuritySetting='" & $varname & "'")
    Local $intRetVal = $oFolderSecuritySettings.GetSecurityDescriptor($objSD)

    If $intRetVal = 0 Then
        ;Local $objStr = $objSD.Owner.Domain & "\" & $objSD.Owner.Name;
        Local $objStr = $objSD.Owner.Name;
        Return($objStr)
    Else
        Return("Couldn't retrieve security descriptor.")
    EndIf
EndFunc

That. return the correct value. unfortunately, cannot get it to work on something else than @blablabla, Please take the time to see my code.
thank you !

Share this post


Link to post
Share on other sites

In either case, your code or mine, you need to pull the information from WMI on the machine the file resides on. If this is a network share, you need to connect to that file server (which means you're going to need rights to it). This works just fine for me pulling from a network share using an account that has rights:

#include <MsgBoxConstants.au3>
$sServer = "<Server FQDN>"
$sFile = "C:\Share\File.txt"

$oWMI = ObjGet("winmgmts:{impersonationLevel=impersonate}!\\" & $sServer & "\root\cimv2")
    If Not IsObj($oWMI) Then Exit(MsgBox($MB_OK, "Returned error: " & @error, "Could not attach to WMI"))

$aItems = $oWMI.ExecQuery("ASSOCIATORS OF {Win32_LogicalFileSecuritySetting='" & $sFile & "'} WHERE AssocClass=Win32_LogicalFileOwner ResultRole=Owner")
    For $sResult In $aItems
        ConsoleWrite($sResult.ReferencedDomainName & ", " & $sResult.AccountName & @CRLF)
    Next

 


√-1 2^3 ∑ π, and it was delicious!

Share this post


Link to post
Share on other sites

#5 ·  Posted (edited)

The goal of that "part of the script" is to prevent duplicate files from being copying since multiple user will run it.

thank you for the help, but I might simply be ... too inexperienced or stupid to understand.

 

ive been struggling for a few day now.. figured how to get a list with _DirGetSizeEx, log everything, still need to manage possible filename duplicate. and ownership..

in fact ill be scanning network drive for file matching x/y criteria of my choice, put em in an array, if @username and ownership match proceed to copy to according $storage if not, proceed to the next file in array till end.

 

If i am needed to populate server FQDN .. apparentely I just wont be able to do it.. correct me if im wrong.

autoit program will be run by simple users. to figure what FILES do they own on drive G:  and then proceed to copy those files, only. it will not be ran by a superadmin or whatever similar.

Edited by gh0stid

Share this post


Link to post
Share on other sites

#6 ·  Posted (edited)

Can you share what led you down the path of _DirGetSizeEX? It is a great script for its time, but Kafu wrote it back in 2009 and it hasn't been updated since. AutoIt has changed a lot since then. Can you detail what it is giving you that the built in DirGetSize (with some massaging) does not?

Looking at the code in your OP, you're pointing it at a share (\\fs1\groupes\DSTH\...). You are correct that you would need to connect to WMI on the file server and then do full path (C:\fs1\groupes\DSTH\...) As I mentioned, the big question is going to be whether you will be running the script under credentials that can access the location.

Edited by JLogan3o13

√-1 2^3 ∑ π, and it was delicious!

Share this post


Link to post
Share on other sites

#7 ·  Posted (edited)

Sure: 

 

Ive been pointed to _DirGetSizeEX by jquinch on another french autoit forum. in fact, he provided me with his udf. then out of charity wrote most of the code and i just had to "adapt" my need.

I needed to be able to SEARCH for specific mask and return result in a array for future treament + get size of each file it returned matching the mask I choosen. ( for my knownledge, wich is limited. I didnt suceed at first with the basic function of AutoIt, plus im a bit in a hurry so unfortunately , i didnt have the "whole week" to try to figure it out .. i have zero experience in coding, i just.. try my best )

and for the answer of your question, That is exactely the point. we NEED users that run the autoit program to ONLY copy files on \\fs1\ ( no matter how deep it is in the directory tree ) wich OWNER of the file, MATCHES their @username retunred in AutoIT

Also need to be sure they do not overwrite duplicate files, but rename em instead 

 

#include <Date.au3>
#include <Array.au3>
#include <File.au3>


Local $logfile = "c:\bulk\NSF.log"
Local $storage = "C:\bulk\backup_test\" & @UserName & "\"

Local $hLogFile = FileOpen($logfile, 1) ;1 = append au fichier, utiliser 2 si on veut overwrite


; ##### Pour le traitement sur c:\ g:\ h:\ ################################################################################
;creation des variables de recherche a l'aide de la fonction homemade _DirGetSizeEx
FileWriteLine($hLogFile, "[" & _Now() & "] Recherche des fichiers NSF NDK et INI sur C:\ G:\ et H:\ pour l'utilisateur " & @USERNAME)
Local $aFiles = _DirGetSizeEx("c:\", "*.nsf", 1)
Local $aFilesNDK = _DirGetSizeEx("c:\", "*.ndk", 1)
Local $aFilesINI = _DirGetSizeEx("c:\", "notes.ini", 1)
Local $aFilesG = _DirGetSizeEx("\\fs1\groupes\DSTH\C - SGPI-SEFI\SGPI\PROJETS\T1200-T1299\T1206\4.0 Documents administratifs\Correspondance\", "*.nsf", 1)
Local $aFilesH = _DirGetSizeEx("\\fs2\home\SAVA0002\notes\", "*.nsf", 1)

;########################################################################
;#  SI un ARRAY CRÉER ON ECRIT LE LOG ET PROCEDE A LA FONCTION DE COPIE #
;####################################################################################################################
;# VALIDE POUR TOUS LES TYPE DE ARRAY, ICI ON AJOUTE OU RETIRE CE QUI EST SUPERFLUX POUR LES AUTRES ETABLISSEMENTS  #
;####################################################################################################################

If IsArray($aFiles) Then
    FileWriteLine($hLogFile, "[" & _Now() & "] -> C:\ " & $aFiles[0][0] & " fichiers trouves pour une taille de " & _ReadableSize($aFiles[0][1]))
    _ProcessNSFCopy($aFiles)
EndIf

If IsArray($aFilesINI) Then
    FileWriteLine($hLogFile, "[" & _Now() & "] -> C:\ " & $aFilesINI[0][0] & " fichiers trouves pour une taille de " & _ReadableSize($aFilesINI[0][1]))
    _ProcessNSFCopy($aFilesINI)
EndIf

If IsArray($aFilesNDK) Then
    FileWriteLine($hLogFile, "[" & _Now() & "] -> C:\ " & $aFilesNDK[0][0] & " fichiers trouves pour une taille de " & _ReadableSize($aFilesNDK[0][1]))
    _ProcessNSFCopy($aFilesNDK)
EndIf

If IsArray($aFilesG) Then
    FileWriteLine($hLogFile, "[" & _Now() & "] -> G:\ " & $aFilesG[0][0] & " fichiers trouves pour une taille de " & _ReadableSize($aFilesG[0][1]))
    _ProcessNSFCopyG($aFilesG)
EndIf

If IsArray($aFilesH) Then
    FileWriteLine($hLogFile, "[" & _Now() & "] -> H:\ " & $aFilesH[0][0] & " fichiers trouves pour une taille de " & _ReadableSize($aFilesH[0][1]))
    _ProcessNSFCopyH($aFilesH)
EndIf


FileWriteLine($hLogFile, "[" & _Now() & "] Fin")

;#################################################################################################################
;#  POUR TOUS CE QUI EST _PROCESSNFSCOPY * ON NE TOUCHE A RIEN, JE DOCUMENTE CELUI-CI, LES AUTRES SONT IDENTIQUES#
;#################################################################################################################

Func _ProcessNSFCopy($aNSFFiles)

;tentative de gestion de doublons, echec pour l'instant
For $i = 1 To $aNSFFiles[0][0]
local Static $x = 0
local $Suffixe

; on s'en sert pour isoler le FILENAME avec extension du PATH dans le array NSFFILES - ne pas toucher...
    $SBPath = $aNSFFiles[$i][0]
    $SBType = 3

;tentative de gestion de doublons, echec pour l'instant
    If FileExists($SBPath) Then
    $Suffixe = "_" & $x
    $sFileName = _SBfpsplit($SBPath, $SBType)
    $sFileName = $sFileName & $Suffixe
Else
    $sFileName = _SBfpsplit($SBPath, $SBType)
    EndIf


; écriture du log avec date et heure pour la grosseur des fichiers et leur noms. -- a fin de statistique et deboguage
        FileWriteLine($hLogFile, "[" & _Now() & "] Copie de " & $aNSFFiles[$i][0] & " (" & _ReadableSize($aNSFFiles[$i][1]) & ") => " & $storage & $sFileName&@CRLF)

        If FileCopy($aNSFFiles[$i][0], $storage & $sFileName, 9) Then
            $sText = "Copie effectuee avec success"
        Else
            $sText = "ERREUR lors de la copie du fichier"
        EndIf
        FileWriteLine($hLogFile, "[" & _Now() & "] " & $sText)
        $x += 1
Next

EndFunc

Func _ProcessNSFCopyINI($aNSFFilesINI)
For $i = 1 To $aNSFFilesINI[0][0]
    $SBPath = $aNSFFilesINI[$i][0]
    $SBType = 3
    $sFileName = _SBfpsplit($SBPath, $SBType)


        FileWriteLine($hLogFile, "[" & _Now() & "] Copie de " & $aNSFFilesINI[$i][0] & " (" & _ReadableSize($aNSFFilesINI[$i][1]) & ") => " & $storage & $sFileName&@CRLF)

        If FileCopy($aNSFFilesINI[$i][0], $storage & $sFileName, 9) Then
            $sText = "Copie effectuee avec success"
        Else
            $sText = "ERREUR lors de la copie du fichier"
        EndIf
        FileWriteLine($hLogFile, "[" & _Now() & "] " & $sText)
    Next

EndFunc

Func _ProcessNSFCopyNDK($aNSFFilesNDK)
For $i = 1 To $aNSFFilesNDK[0][0]
    $SBPath = $aNSFFilesNDK[$i][0]
    $SBType = 3
    $sFileName = _SBfpsplit($SBPath, $SBType)


        FileWriteLine($hLogFile, "[" & _Now() & "] Copie de " & $aNSFFilesNDK[$i][0] & " (" & _ReadableSize($aNSFFilesNDK[$i][1]) & ") => " & $storage & $sFileName&@CRLF)

        If FileCopy($aNSFFilesNDK[$i][0], $storage & $sFileName, 9) Then
            $sText = "Copie effectuee avec success"
        Else
            $sText = "ERREUR lors de la copie du fichier"
        EndIf
        FileWriteLine($hLogFile, "[" & _Now() & "] " & $sText)
    Next

EndFunc

Func _ProcessNSFCopyG($aNSFFilesG)
For $i = 1 To $aNSFFilesG[0][0]
    $SBPath = $aNSFFilesG[$i][0]
    $SBType = 3
    $sFileName = _SBfpsplit($SBPath, $SBType)

        FileWriteLine($hLogFile, "[" & _Now() & "] Copie de " & $aNSFFilesG[$i][0] & " (" & _ReadableSize($aNSFFilesG[$i][1]) & ") => " & $storage & $sFileName&@CRLF)

        If FileCopy($aNSFFilesG[$i][0], $storage & $sFileName, 9) Then
            $sText = "Copie effectuee avec success"
        Else
            $sText = "ERREUR lors de la copie du fichier"
        EndIf
        FileWriteLine($hLogFile, "[" & _Now() & "] " & $sText)
    Next

EndFunc

Func _ProcessNSFCopyH($aNSFFilesH)
For $i = 1 To $aNSFFilesH[0][0]
    $SBPath = $aNSFFilesH[$i][0]
    $SBType = 3
    $sFileName = _SBfpsplit($SBPath, $SBType)

        FileWriteLine($hLogFile, "[" & _Now() & "] Copie de " & $aNSFFilesH[$i][0] & " (" & _ReadableSize($aNSFFilesH[$i][1]) & ") => " & $storage & $sFileName&@CRLF)

        If FileCopy($aNSFFilesH[$i][0], $storage & $sFileName, 9) Then
            $sText = "Copie effectuee avec success"
        Else
            $sText = "ERREUR lors de la copie du fichier"
        EndIf
        FileWriteLine($hLogFile, "[" & _Now() & "] " & $sText)
    Next

EndFunc
FileClose($hLogFile)


; #FUNCTION#====================================================================================================================
; Name ..........: _DirGetSizeEx ; Description ...: Returns the size in bytes of a file list by extension.
; Syntax ........: _DirGetSizeEx($sDir[, $sMask = "*"[, $iFlag = 0]])
; Parameters ....: $sDir                - The directory to search in.
;                  $sMask               - [optional] Filter for results. Default is "*" (all).
;                                         Filter for result. Multiple filters must be separated by ";"
;                                         Use "|" to separate 3 possible sets of filters: "Include|Exclude|Exclude_Folders"
;                                             Include = Files/Folders to include (default = "*" [all])
;                                             Exclude = Files/Folders to exclude (default = "" [none])
;                                             Exclude_Folders = only used if $iRecur = 1 AND $iReturn <> 2 to exclude defined folders (default = "" [none])
;                  $iFlag               - [optional] 0 (default) = Returns the size
;                                                    1 = Extended mode is On -> returns an array that contains the file of each file (see Remarks).
;                                                    2 = Don't get the size of files in subdirectories (recursive mode is Off)
; Return values .: Success = The size in bytes, or a single dimension array
;                  Failure = -1 and sets the @error flag to 1 if the path doesn't exist.
; Author ........: jguinch
; Remarks .......: If you use the extended mode then the array returned from this function is a single dimension array containing the followingelements:
;                    $aArray[0][0] = Files count
;                    $aArray[0][1] = Total files size
;                    $aArray[1][0] = Full name of 1st file
;                    $aArray[1][1] = Size of 1st file
;                    $aArray[2][0] = Full name of 2nd file
;                    $aArray[2][1] = Size of 2nd file
;                    $aArray[n][1] = Size of nth file
;                    $aArray[n][1] = Size of nth file
;===============================================================================================================================
Func _DirGetSizeEx($sDir, $sMask = "*", $iFlag = 0); OK
    If NOT FileExists($sDir) Then Return SetError(1, 0, -1)
    If NOT StringInStr(FileGetAttrib($sDir), "D") Then Return SetError(1, 0, -1)

    Local $iExtMode = BitAND($iFlag, 1) > 0
    Local $iRecMode = NOT BitAND($iFlag, 2) > 0
    Local $aDirs[1] = [ StringRegExpReplace($sDir, "\\$", "") ]
    Local $iCountDir = 0, $iCountFile = 0, $n = 0, $iSize = 0, $iFullSize = 0
    Local $aFiles[1][2] = [[0]]
    Local $hSearch, $sFileName, $sRegexFilesInclude, $sRegexFilesExclude = "^$", $sRegexFoldersExclude = "^$"

    Local $sRegexMask = StringReplace( StringReplace( StringReplace($sMask, "|", "\|") , "?", "\E(?:.|.?$)\Q"), "*", "\E.*?\Q")
    Local $aFilters = StringSplit($sRegexMask, "\|", 3)

    $sRegexFilesInclude = "(?i)^(?:" & StringRegExpReplace(StringReplace($aFilters[0], ";", "|") , "([^|]+)", "\\Q$1\\E") & ")$"
    If UBound($aFilters) > 1 Then $sRegexFilesExclude = "(?i)^(?:" & StringRegExpReplace(StringReplace($aFilters[1], ";", "|") , "([^|]+)", "\\Q$1\\E") & ")$"
    If UBound($aFilters) > 2 Then $sRegexFoldersExclude = "(?i)^(?:" & StringRegExpReplace(StringReplace($aFilters[2], ";", "|") , "([^|]+)", "\\Q$1\\E") & ")$"

    While 1
        $hSearch = FileFindFirstFile( $aDirs[$n]  & "\*.*"  )
        If $hSearch <> -1 Then

            While 1
                $sFileName = FileFindNextFile($hSearch)
                If @error Then ExitLoop

                If @Extended Then
                    If NOT StringRegExp($sFileName, $sRegexFoldersExclude) Then
                        $iCountDir += 1
                        If $iCountDir >= UBound($aDirs) Then Redim $aDirs[UBound($aDirs) * 2]
                        $aDirs[$iCountDir] = $aDirs[$n] & "\" & $sFileName
                    EndIf
                Else
                    If StringRegExp($sFileName, $sRegexFilesInclude) AND NOT StringRegExp($sFileName, $sRegexFilesExclude) Then
                        $iSize = FileGetSize($aDirs[$n] &  "\" &$sFileName)
                        $iFullSize += $iSize
                        If $iExtMode Then
                            $iCountFile += 1
                            If $iCountFile >= UBound($aFiles) Then Redim $aFiles[UBound($aFiles) * 2][2]
                            $aFiles[$iCountFile][0] = $aDirs[$n] &  "\" &$sFileName
                            $aFiles[$iCountFile][1] = $iSize
                        EndIf
                    EndIf
                EndIf
            WEnd

            If NOT $iRecMode Then ExitLoop
        EndIf

        FileClose($hSearch)

        If $n = $iCountDir Then ExitLoop
        $n += 1
    WEnd

    If NOT $iExtMode Then Return $iFullSize

    Redim $aFiles[$iCountFile + 1][2]
    $aFiles[0][0] = $iCountFile
    $aFiles[0][1] = $iFullSize
    Return $aFiles
EndFunc

;################################################################
;# CONVERSION DES BYTES EN KO MO GO TO, PLUS CONVIVIABLE .......#
;################################################################

Func _ReadableSize($iSize, $decimalplaces = 2)
    Local $aUnites = [1024, "octets", "Ko", "Mo", "Go", "To"]
    For $i = 2 To UBound($aUnites) - 1
        If $iSize < $aUnites[0] Then ExitLoop
        $iSize /= $aUnites[0]
    Next
    Return Round($iSize, $decimalplaces) & " " & $aUnites[$i - 1]
EndFunc

;#FUNCTION# ====================================================================================================
; Name...........: _SBfpsplit
; Description ...: Splits a file path into Drive, path, filename, or extension.
; Syntax.........: _SBfpsplit($SBPath, $SBType);$SBpath (file path to evaluate) , $SBType (option)
; Parameters ....:
;|1 = Drive                 ex. D:
;|2 = Path                   ex. D:\1111\dir\file.txt
;|3 = File name          ex. file.txt
;|4 = Extension           ex. txt
;|5 = Drive letter only ex. D
; Author ........: Scott E. Brown ripandreplace@eset.com
; Modified.......:04/03/2009
; Remarks .......:
; Related .......:
; Link ..........;
; Example .......; _SBfpsplit("D:\1111\dir\file.txt, 1)
;
;$path = "D:\1111\dir\test.txt"
;ConsoleWrite(_SBfpsplit($path, 1) & @CRLF)
;ConsoleWrite(_SBfpsplit($path, 2) & @CRLF)
;ConsoleWrite(_SBfpsplit($path, 3) & @CRLF)
;ConsoleWrite(_SBfpsplit($path, 5) & @CRLF)
; ====================================================================================================
Func _SBfpsplit($SBPath, $SBType);$SBpath = file path to evaluate , $SBType = 1 for Drive, 2 for Path, 3 for File name, 4 for extension, 5 for drive letter only
    Local $SBfile, $SBSplit, $SBdrive, $SBfilepath, $SBnumber
    $SBSplit = StringSplit($SBPath, "\"); split into array
    $SBnumber = $SBSplit[0]; the number of strings returned
    $SBfilepath = ""
    for $1 = 1 to $SBnumber -1
        $SBfilepath = $SBfilepath & $SBSplit[$1] & "\"; path
    Next
    $SBfile = $SBSplit[($SBsplit[0])]; file
    $SBdrive = $SBSplit[1]; drive
    $SBfs = StringSplit($SBPath, "."); split into array
;MsgBox(4096, "Path", $SBSfs[0])
    if $SBfs[0] = 1 then
        $SBExt = ""; no extension found
    Else
        $SBExt = $SBfs[($SBfs[0])]; last . extentsion
    EndIf

    If $SBType = 1 then Return $SBdrive
    If $SBType = 2 then Return $SBfilepath
    If $SBType = 3 then Return $SBfile
    If $SBType = 4 then Return $SBExt
    If $SBType = 5 then Return StringLeft($SBdrive, 1)
EndFunc

 

Edited by gh0stid

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

  • Similar Content

    • LoneWolf_2106
      By LoneWolf_2106
      Hi everybody,
      i have a question related to strings items in an Array and sorting. Maybe someone can advice me how to solve the issue.
      I have an Array of strings, every item of the Array is as following:
      INFO [13.06.2017 11:48:01] [Thread-13] [ConGenImpUsb -> waitForConnection]  INFO [07.06.2017 08:55:44] [main] MDU5 - Ver 5.1x I want to sort the item in the array by date and time, is there any function which allows me to sort by date/time?
      Thanks in advance
    • Rimoun
      By Rimoun
      Hello everyone
      I would like to have some help regarding my issue.
      I am trying to extract some information from excel sheet, I use _Excel_RangeFind then I get the array for the value then I check the array. In case the array is true the next will be to get some information based on the extracted array if no array because the value is not found it gives a messages box that the value is not found.
      My problem that the button works for one time only if i tried any value which exist in the sheet it gives me that value not found.
      I suspect that there is a problem regarding While loop.
      here is my code
      #include <GUIConstantsEx.au3> #include <WinAPI.au3> #Include <GuiListBox.au3> #include <WindowsConstants.au3> #include <Array.au3> #include <Excel.au3> #include <MsgBoxConstants.au3> #include <ExcelConstants.au3> if FileExists ("result.txt") Then Sleep (100) Else readxl() EndIf Global $oExcel = _Excel_Open(False,False) If @error Then Exit MsgBox($MB_SYSTEMMODAL, "Excel UDF: _Excel_RangeFind Example", "Error creating the Excel application object." & @CRLF & "@error = " & @error & ", @extended = " & @extended) Global $oWorkbook = _Excel_BookOpen($oExcel, "D:\info.xlsx",False,False) If @error Then MsgBox($MB_SYSTEMMODAL, "Excel Error", "Error opening workbook '" & $oWorkbook & @CRLF & "@error = " & @error & ", @extended = " & @extended) _Excel_Close($oExcel) Exit EndIf Local $lab1 = _Excel_RangeRead($oWorkbook, Default,"B1") Local $lab2 = _Excel_RangeRead($oWorkbook, Default,"C1") Local $lab3 = _Excel_RangeRead($oWorkbook, Default,"D1") Local $lab4 = _Excel_RangeRead($oWorkbook, Default,"E1") Global $sResult1,$sResult2,$sResult3,$sResult4,$sResult5,$sResult6 Global $asKeyWords = stringsplit (FileRead (@ScriptDir & "\result.txt"),@CRLF) Global Const $xlUp = -4162 ;~ _Main() Local $hGUI, $hList, $hInput, $aSelected, $sChosen, $hUP, $hDOWN, $hENTER, $hESC Local $sCurrInput = "", $aCurrSelected[2] = [-1, -1], $iCurrIndex = -1, $hListGUI = -1 $hGUI = GUICreate("Rimo System", 253, 270, 192, 124) Global $hInput = GUICtrlCreateInput("", 24, 48, 169, 21) Global $Label1 = GUICtrlCreateLabel("Rimo System", 80, 16, 150, 25) GUICtrlSetFont(-1, 14, 800, 0, "MS Serif") Global $Input2 = GUICtrlCreateInput("", 72, 144, 161, 21) Global $Input3 = GUICtrlCreateInput("", 72, 176, 161, 21) Global $Input4 = GUICtrlCreateInput("", 72, 208, 161, 21) Global $Input5 = GUICtrlCreateInput("", 72, 240, 161, 21) $Input6 = GUICtrlCreateInput("", 72, 272, 161, 21) $Input7 = GUICtrlCreateInput("", 72, 304, 161, 21) $Button1 = GUICtrlCreateButton("Get Info", 72, 88, 89, 33) $Label2 = GUICtrlCreateLabel("Label2", 16, 144, 36, 17) GUICtrlSetData( -1,$lab1) $Label3 = GUICtrlCreateLabel("Label3", 16, 176, 36, 17) GUICtrlSetData( -1,$lab2) $Label4 = GUICtrlCreateLabel("Label4", 16, 208, 36, 17) GUICtrlSetData( -1,$lab3) $Label5 = GUICtrlCreateLabel("Label5", 16, 240, 36, 17) GUICtrlSetData( -1,$lab4) $Label6 = GUICtrlCreateLabel("", 16, 272, 36, 17) $Label7 = GUICtrlCreateLabel("", 16, 304, 36, 17) $Button2 = GUICtrlCreateButton("Cancel", 112, 416, 121, 25) GUISetState(@SW_SHOW, $hGUI) Global $sSearch = guictrlread ($hInput) $hUP = GUICtrlCreateDummy() $hDOWN = GUICtrlCreateDummy() $hENTER = GUICtrlCreateDummy() $hESC = GUICtrlCreateDummy() Dim $AccelKeys[4][2] = [["{UP}", $hUP], ["{DOWN}", $hDOWN], ["{ENTER}", $hENTER], ["{ESC}", $hESC]] GUISetAccelerators($AccelKeys) While 1 Switch GUIGetMsg() Case $GUI_EVENT_CLOSE ExitLoop Case $Button2 Exit Case $Button1 Global $aResult = _Excel_RangeFind($oWorkbook, guictrlread($hInput) ,"A2:A2000") Global $aExtract = _ArrayExtract($aResult, 0, 0, 2, 2) if _elementExists($aExtract,0) Then getdata() Else MsgBox(0,"","Value Does Not Exist") EndIf Case $hESC If $hListGUI <> -1 Then ; List is visible. GUIDelete($hListGUI) $hListGUI = -1 Else ExitLoop EndIf Case $hUP If $hListGUI <> -1 Then ; List is visible. $iCurrIndex -= 1 If $iCurrIndex < 0 Then $iCurrIndex = 0 EndIf _GUICtrlListBox_SetCurSel($hList, $iCurrIndex) EndIf Case $hDOWN If $hListGUI <> -1 Then ; List is visible. $iCurrIndex += 1 If $iCurrIndex > _GUICtrlListBox_GetCount($hList) - 1 Then $iCurrIndex = _GUICtrlListBox_GetCount($hList) - 1 EndIf _GUICtrlListBox_SetCurSel($hList, $iCurrIndex) EndIf Case $hENTER If $hListGUI <> -1 And $iCurrIndex <> -1 Then ; List is visible and a item is selected. $sChosen = _GUICtrlListBox_GetText($hList, $iCurrIndex) EndIf Case $hList $sChosen = GUICtrlRead($hList) EndSwitch Sleep(10) $aSelected = _GetSelectionPointers($hInput) If GUICtrlRead($hInput) <> $sCurrInput Or $aSelected[1] <> $aCurrSelected[1] Then ; Input content or pointer are changed. $sCurrInput = GUICtrlRead($hInput) $aCurrSelected = $aSelected ; Get pointers of the string to replace. $iCurrIndex = -1 If $hListGUI <> -1 Then ; List is visible. GUIDelete($hListGUI) $hListGUI = -1 EndIf $hList = _PopupSelector($hGUI, $hListGUI, _CheckInputText($sCurrInput, $aCurrSelected)) ; ByRef $hListGUI, $aCurrSelected. EndIf If $sChosen <> "" Then GUICtrlSendMsg($hInput, 0x00B1, $aCurrSelected[0], $aCurrSelected[1]) ; $EM_SETSEL. _InsertText($hInput, $sChosen) $sCurrInput = GUICtrlRead($hInput) GUIDelete($hListGUI) $hListGUI = -1 $sChosen = "" EndIf WEnd GUIDelete($hGUI) Func _CheckInputText($sCurrInput, ByRef $aSelected) Local $sPartialData = "" If (IsArray($aSelected)) And ($aSelected[0] <= $aSelected[1]) Then Local $aSplit = StringSplit(StringLeft($sCurrInput, $aSelected[0]), " ") $aSelected[0] -= StringLen($aSplit[$aSplit[0]]) If $aSplit[$aSplit[0]] <> "" Then For $A = 1 To $asKeyWords[0] If StringLeft($asKeyWords[$A], StringLen($aSplit[$aSplit[0]])) = $aSplit[$aSplit[0]] And $asKeyWords[$A] <> $aSplit[$aSplit[0]] Then $sPartialData &= $asKeyWords[$A] & "|" EndIf Next EndIf EndIf Return $sPartialData EndFunc ;==>_CheckInputText Func _PopupSelector($hMainGUI, ByRef $hListGUI, $sCurr_List) Local $hList = -1 If $sCurr_List = "" Then Return $hList EndIf $hListGUI = GUICreate("", 280, 160, 23, 62, $WS_POPUP, BitOR($WS_EX_TOOLWINDOW, $WS_EX_TOPMOST, $WS_EX_MDICHILD), $hMainGUI) $hList = GUICtrlCreateList("", 0, 0, 170, 150, BitOR(0x00100000, 0x00200000)) GUICtrlSetData($hList, $sCurr_List) GUISetControlsVisible($hListGUI) ; To Make Control Visible And Window Invisible. GUISetState(@SW_SHOWNOACTIVATE, $hListGUI) Return $hList EndFunc ;==>_PopupSelector Func _InsertText(ByRef $hEdit, $sString) #cs Description: Insert A Text In A Control. Returns: Nothing #ce Local $aSelected = _GetSelectionPointers($hEdit) GUICtrlSetData($hEdit, StringLeft(GUICtrlRead($hEdit), $aSelected[0]) & $sString & StringTrimLeft(GUICtrlRead($hEdit), $aSelected[1])) Local $iCursorPlace = StringLen(StringLeft(GUICtrlRead($hEdit), $aSelected[0]) & $sString) GUICtrlSendMsg($hEdit, 0x00B1, $iCursorPlace, $iCursorPlace) ; $EM_SETSEL. EndFunc ;==>_InsertText Func _GetSelectionPointers($hEdit) Local $aReturn[2] = [0, 0] Local $aSelected = GUICtrlRecvMsg($hEdit, 0x00B0) ; $EM_GETSEL. If IsArray($aSelected) Then $aReturn[0] = $aSelected[0] $aReturn[1] = $aSelected[1] EndIf Return $aReturn EndFunc ;==>_GetSelectionPointers Func GUISetControlsVisible($hWnd) ; By Melba23. Local $aControlGetPos = 0, $hCreateRect = 0, $hRectRgn = _WinAPI_CreateRectRgn(0, 0, 0, 0) Local $iLastControlID = _WinAPI_GetDlgCtrlID(GUICtrlGetHandle(-1)) For $i = 3 To $iLastControlID $aControlGetPos = ControlGetPos($hWnd, '', $i) If IsArray($aControlGetPos) = 0 Then ContinueLoop $hCreateRect = _WinAPI_CreateRectRgn($aControlGetPos[0], $aControlGetPos[1], $aControlGetPos[0] + $aControlGetPos[2], $aControlGetPos[1] + $aControlGetPos[3]) _WinAPI_CombineRgn($hRectRgn, $hCreateRect, $hRectRgn, 2) _WinAPI_DeleteObject($hCreateRect) Next _WinAPI_SetWindowRgn($hWnd, $hRectRgn, True) _WinAPI_DeleteObject($hRectRgn) EndFunc Func _elementExists($array, $element) If $element > UBound($array)-1 Then Return False ; element is out of the array bounds Return True ; element is in array bounds EndFunc Func getdata() ;~ Local $sResult1 = _Excel_RangeRead($oWorkbook, Default,StringReplace(StringReplace ($aExtract[0],"$",""),"A","B")) ;~ Local $sResult2 = _Excel_RangeRead($oWorkbook, Default,StringReplace(StringReplace ($aExtract[0],"$",""),"A","C")) ;~ Local $sResult3 = _Excel_RangeRead($oWorkbook, Default,StringReplace(StringReplace ($aExtract[0],"$",""),"A","D")) ;~ Local $sResult4 = _Excel_RangeRead($oWorkbook, Default,StringReplace(StringReplace ($aExtract[0],"$",""),"A","E")) ;~ Local $sResult5 = _Excel_RangeRead($oWorkbook, Default,StringReplace(StringReplace ($aExtract[0],"$",""),"A","F")) ;~ Local $sResult6 = _Excel_RangeRead($oWorkbook, Default,StringReplace(StringReplace ($aExtract[0],"$",""),"A","G")) guictrlsetdata($Input2,$sResult1) guictrlsetdata($Input3,$sResult2) guictrlsetdata($Input4,$sResult3) guictrlsetdata($Input5,$sResult4) guictrlsetdata($Input6,$sResult5) guictrlsetdata($Input7,$sResult6) _Excel_Close($oExcel,Default,True) EndFunc Func readxl() Global $oExcel = _Excel_Open(False,False) If @error Then Exit MsgBox($MB_SYSTEMMODAL, "Excel UDF: _Excel_RangeFind Example", "Error creating the Excel application object." & @CRLF & "@error = " & @error & ", @extended = " & @extended) Global $oWorkbook = _Excel_BookOpen($oExcel, "D:\info.xlsx",False,False) LOcal Const $xlUp = -4162 With $oWorkbook.ActiveSheet ; process active sheet $oRangeLast = .UsedRange.SpecialCells($xlCellTypeLastCell) ; get a Range that contains the last used cells $iRowCount = .Range(.Cells(1, 1), .Cells($oRangeLast.Row, $oRangeLast.Column)).Rows.Count ; get the the row count for the range starting in row/column 1 and ending at the last used row/column $iLastCell = .Cells($iRowCount + 1, "B").End($xlUp).Row ProgressOn("Copying Cells", "Copying Cells progress", "0%") For $i = 2 to $iLastCell Local $total = Int(($i/$iLastCell)*100) Local $sResult3 = _Excel_RangeRead($oWorkbook, Default, "A" & $i) FileWriteLine("result.txt",$sResult3) ProgressSet(($i/$iLastCell)*100, $total & "%") Next ;~ FileWrite("result.txt",$sResult3) ProgressSet(100, "Done", "Complete") Sleep (1500) ProgressOff() _Excel_Close($oExcel,Default,True) EndWith EndFunc  
    • fosil
      By fosil
      Hi everyone.

      I'm currently working a program that constantly prints out log files through "consolewrite" and the "#AutoIt3Wrapper_Change2CUI=y" wrapper.

      Part of this program requires me to run a batch script.

      My issue is the batch script launches from the same window as consolewrite. I need the batch file to be launched through a different window as currently this causes an issue with the logs (which need to be very precise) but also causes the batch file to produce some funny behavior...

      Does anyone know how I can force the file to run on a second DOS window?

      Thanks in advance!!!
       
      Edit: Im using the "run" command if that helps. I tried "shellexecute" but that seemed to not launch the batch scripts at all.
    • nacerbaaziz
      By nacerbaaziz
      Hello guys
      I have an inquiry regarding bass.dll
      I wanted to record an audio file and did not know the way
      As well as I want to save the file after applying the effects
      can you help me?
      am sorry for my english
      With my greetings and best wishes
    • hcI
      By hcI
      Hello, i'm making a little script that lets users enter a question and if the script can't answer to, it ask what would be the answer (a bit like siri on IPhones). And I try to display the "supposed array" I still have an error.. I searched on Google and got nothing looked in the help file too.. I'm here to know if someone have a solution to my error please.
      Here is where $a and $b should become arrays :
      Dim $dossier = @AppDataDir & "\Siri2" Dim $chemin = $dossier & "\data.ini" Global $a = _InfoRead($chemin, 0) Global $b = _InfoRead($chemin, 1) with this function :
      Func _InfoRead($path, $mode = 0) If DirGetSize($dossier) = -1 Then Return SetError(-4) If Not FileExists($chemin) Then Return SetError(-5) Local $readed = IniReadSection($path, "data") If @error Then Return SetError(-3) $size = $readed[0][0] Local $return[$size] For $i = 1 To $size Step 1 $return[$i - 1] = $readed[$i][$mode] Next Return $return EndFunc and the thing that i don't understand is that, after _InfoRead return affected to $a, I can't use _ArrayDisplay because of  error 1 "$aArray is not an array" (and same fpr the variable $b)..
      Can please someone help me to understand why is it doing this ?

      -hcI