Jump to content

Search For Long File Name


Recommended Posts

Hello everyone. I need to find a way to do the following:

Example:

If I have a directory called C:\CustomerLogs where all the results log files are being stored after testing is complete. The resulta file is something like this:

0125798631447336_1_0005785606.log

5555579863166874_1_0005785606.log

7849563144734598_1_0005785606.log

The first 16 numbers from 0-6 are the system serial number, which is captured at the beginning of the test. The remaining of the numbers are generated by the application.

Goal:

I kinda have a script that will prompt for the serial number and create a log file on a different drive. But I need a script that will search C:\CustomerLogs and find the serial number log file that mathches the serial number that was entered.

for Example:

If I entered 0125798631447336, then to search and find 0125798631447336_1_0005785606.log, then take the results from this file and copy it to the log file created on the other drive.

Or once the serial number is matched, to copy that file and trim everything else but the serial number and create a log file with that serial number found.

I hope this makes sense.

Link to comment
Share on other sites

Here it is.

; Script in progress

; TBD

; TBD

; TBD

$var = ""

;Prompt For Serial Number

$var = InputBox("System Serial Number", "Scan Serial Number, then Click OK")

If $var = "" Then Exit

;if file exist to deleted or continue to over-write.

If FileExists("V:" & "\" & $var & ".log") Then

$answer = MsgBox(4, "File Already Exist", "Do you want to replace it?")

If $answer = 7 Then

;do if answer = no

MsgBox(48, "Stopped!", "You don't want to proceed, Click OK to exit")

Exit;ends script

EndIf

EndIf

;do if answer = yes

; Server to save Logs Files

;Create the file and Write results to it.

$file = FileOpen("V:" & "\" & ($var) & ".log", 2)

If $file = -1 Then

MsgBox(0, "Error", "Unable to open file.")

Exit

EndIf

; Show the File Name of input variable returned.

$CPath = ("C:" & "\" & "CustomerLogs" & "\")

$search = FileFindFirstFile($CPath & ($var) & ".log")

; 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, "C:\CustomerLogs Log File Found!, Log File:", $file)

WEnd

; Close the search handle

FileClose($search)

; Example of Serial Number Created by Application

; Need to search for input on Drive C: and trim the 13 right strings and copy results to another file

;$result = StringTrimRight("0123456789_1_123456.log", 13)

;MsgBox(0, "String without rightmost 13 characters is:", $result)

;$file = Fileopen(@DesktopDir & "\" & $result & ".log", 2)

Hello everyone. I need to find a way to do the following:

Example:

If I have a directory called C:\CustomerLogs where all the results log files are being stored after testing is complete. The resulta file is something like this:

0125798631447336_1_0005785606.log

5555579863166874_1_0005785606.log

7849563144734598_1_0005785606.log

The first 16 numbers from 0-6 are the system serial number, which is captured at the beginning of the test. The remaining of the numbers are generated by the application.

Goal:

I kinda have a script that will prompt for the serial number and create a log file on a different drive. But I need a script that will search C:\CustomerLogs and find the serial number log file that mathches the serial number that was entered.

for Example:

If I entered 0125798631447336, then to search and find 0125798631447336_1_0005785606.log, then take the results from this file and copy it to the log file created on the other drive.

Or once the serial number is matched, to copy that file and trim everything else but the serial number and create a log file with that serial number found.

I hope this makes sense.

Link to comment
Share on other sites

Quick and dirty example of how I would do it:

#include <file.au3>
#include <array.au3>

$s_path = "C:\CustomerLogs\"
$s_serial = InputBox("Serial Search", "Enter Serial # to search for.")
$a_filelist = _FileListToArray($s_path)
If (Not IsArray($a_filelist)) Then
    MsgBox (0,"","No Files\Folders Found.")
    Exit
EndIf
For $i = 0 to Ubound($a_filelist)-1
    $a_searchresult = StringRegExp($a_filelist[$i],'('&$s_serial&'_[0-9]{1}_[0-9]{10}.log)',1)
    If IsArray($a_searchresult) = 1 Then
        MsgBox(0,"File Found!","File: "&$a_filelist[$i]&" Matches: "&$s_serial&@CRLF&"Copying to"&$s_path&$s_serial&".log")
        FileCopy ( $s_path&$a_filelist[$i], $s_path&$s_serial&".log",1)
    EndIf
Next
Exit
AutoIt Scripts:Aimbot: Proof of Concept - PixelSearching Aimbot with several search/autoshoot/lock-on techniques.Sliding Toolbar - Add a nice Sliding Toolbar to your next script. Click the link to see an animation of it in action!FontInfo UDF - Get list of system fonts, or search to see if a particular font is installed.Get Extended Property UDF - Retrieve a files extended properties (e.g., video/image dimensions, file version, bitrate of song/video, etc)
Link to comment
Share on other sites

When I run the script I received the following message:

C:\test.au3(6,39) : ERROR: _FileListToArray(): undefined function.

$a_filelist = _FileListToArray($s_path)

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^

C:\test.au3 - 1 error(s), 0 warning(s)

Quick and dirty example of how I would do it:

#include <file.au3>
#include <array.au3>

$s_path = "C:\CustomerLogs\"
$s_serial = InputBox("Serial Search", "Enter Serial # to search for.")
$a_filelist = _FileListToArray($s_path)
If (Not IsArray($a_filelist)) Then
    MsgBox (0,"","No Files\Folders Found.")
    Exit
EndIf
For $i = 0 to Ubound($a_filelist)-1
    $a_searchresult = StringRegExp($a_filelist[$i],'('&$s_serial&'_[0-9]{1}_[0-9]{10}.log)',1)
    If IsArray($a_searchresult) = 1 Then
        MsgBox(0,"File Found!","File: "&$a_filelist[$i]&" Matches: "&$s_serial&@CRLF&"Copying to"&$s_path&$s_serial&".log")
        FileCopy ( $s_path&$a_filelist[$i], $s_path&$s_serial&".log",1)
    EndIf
Next
Exit
Link to comment
Share on other sites

Requires Beta, sorry.. forget to mention that.

AutoIt Scripts:Aimbot: Proof of Concept - PixelSearching Aimbot with several search/autoshoot/lock-on techniques.Sliding Toolbar - Add a nice Sliding Toolbar to your next script. Click the link to see an animation of it in action!FontInfo UDF - Get list of system fonts, or search to see if a particular font is installed.Get Extended Property UDF - Retrieve a files extended properties (e.g., video/image dimensions, file version, bitrate of song/video, etc)
Link to comment
Share on other sites

Download the latest beta version of AutoIT here:

http://www.autoitscript.com/autoit3/files/...-beta-Setup.exe

Also, I would suggest getting the SCITE editor if you have not already.

http://www.autoitscript.com/cgi-bin/getfil...iTe4AutoIt3.exe

So, Install BETA, Install Scite, open up the script I wrote for you in Scite, and click, Tools>Beta Run Or ALT+F5

AutoIt Scripts:Aimbot: Proof of Concept - PixelSearching Aimbot with several search/autoshoot/lock-on techniques.Sliding Toolbar - Add a nice Sliding Toolbar to your next script. Click the link to see an animation of it in action!FontInfo UDF - Get list of system fonts, or search to see if a particular font is installed.Get Extended Property UDF - Retrieve a files extended properties (e.g., video/image dimensions, file version, bitrate of song/video, etc)
Link to comment
Share on other sites

I install the Beta software and I had already installed the SCITE. I still get the same message:

:\test.au3(6,39) : ERROR: _FileListToArray(): undefined function.

?????????/

Download the latest beta version of AutoIT here:

http://www.autoitscript.com/autoit3/files/...-beta-Setup.exe

Also, I would suggest getting the SCITE editor if you have not already.

http://www.autoitscript.com/cgi-bin/getfil...iTe4AutoIt3.exe

So, Install BETA, Install Scite, open up the script I wrote for you in Scite, and click, Tools>Beta Run Or ALT+F5

Link to comment
Share on other sites

_FileListToArray is in the beta File.au3

Dont know what to tell you. Make sure you have it set to use the beta include folder, or copy the beta file.au3 to the normal version's include file as a workaround.

AutoIt Scripts:Aimbot: Proof of Concept - PixelSearching Aimbot with several search/autoshoot/lock-on techniques.Sliding Toolbar - Add a nice Sliding Toolbar to your next script. Click the link to see an animation of it in action!FontInfo UDF - Get list of system fonts, or search to see if a particular font is installed.Get Extended Property UDF - Retrieve a files extended properties (e.g., video/image dimensions, file version, bitrate of song/video, etc)
Link to comment
Share on other sites

I will try it. Thank you very much.

_FileListToArray is in the beta File.au3

Dont know what to tell you. Make sure you have it set to use the beta include folder, or copy the beta file.au3 to the normal version's include file as a workaround.

Link to comment
Share on other sites

Anyone else can help me this. I get error messages when running the script..

C:\Program Files\AutoIt3\beta\Examples\_FileListToArray.au3(6,43) : ERROR: _FileListToArray(): undefined function.

$FileList=_FileListToArray($sPath,$sFilter)

:)

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^

I will try it. Thank you very much.

Link to comment
Share on other sites

  • Moderators

Anyone else can help me this. I get error messages when running the script..

C:\Program Files\AutoIt3\beta\Examples\_FileListToArray.au3(6,43) : ERROR: _FileListToArray(): undefined function.

$FileList=_FileListToArray($sPath,$sFilter)

:)

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^

Use the Beta of AuotIt and you won't get the error if you use #include <File.au3>

Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.

Link to comment
Share on other sites

While this isnt a proper solution because you should be able to install and run the beta version fine, you could just tack this on the end of your script as a temporary workaround:

Func _FileListToArray($sPath, $sFilter = "*", $iFlag = 0)
    Local $hSearch, $sFile, $asFileList[1]
    If Not FileExists($sPath) Then
        SetError(1)
        Return ""
    EndIf
    If (StringInStr($sFilter, "\")) or (StringInStr($sFilter, "/")) or (StringInStr($sFilter, ":")) or (StringInStr($sFilter, ">")) or (StringInStr($sFilter, "<")) or (StringInStr($sFilter, "|")) or (StringStripWS($sFilter, 8) = "") Then
        SetError(2)
        Return 0
    EndIf
    If Not ($iFlag = 0 Or $iFlag = 1 Or $iFlag = 2) Then
        SetError(3)
        Return ""
    EndIf
    $asFileList[0] = 0
    $hSearch = FileFindFirstFile($sPath & "\" & $sFilter)
    If $hSearch = -1 Then 
        SetError(0)
        Return 0
    EndIf
    While 1
        $sFile = FileFindNextFile($hSearch)
        If @error Then ExitLoop
        If $iFlag = 1 Then
            If StringInStr(FileGetAttrib($sPath & "\" & $sFile), "D") <> 0 Then ContinueLoop
        EndIf
        If $iFlag = 2 Then
            If StringInStr(FileGetAttrib($sPath & "\" & $sFile), "D") = 0 Then ContinueLoop
        EndIf
        ReDim $asFileList[UBound($asFileList) + 1]
        $asFileList[0] = $asFileList[0] + 1
        $asFileList[UBound($asFileList) - 1] = $sFile
    WEnd
    FileClose($hSearch)
    SetError(0)
    If $asFileList[0] = 0 Then Return ""
    Return $asFileList
EndFunc  ;==>_FileListToArray
AutoIt Scripts:Aimbot: Proof of Concept - PixelSearching Aimbot with several search/autoshoot/lock-on techniques.Sliding Toolbar - Add a nice Sliding Toolbar to your next script. Click the link to see an animation of it in action!FontInfo UDF - Get list of system fonts, or search to see if a particular font is installed.Get Extended Property UDF - Retrieve a files extended properties (e.g., video/image dimensions, file version, bitrate of song/video, etc)
Link to comment
Share on other sites

Could not get it to work. I am very sad. What am I doing wrong HAAAAAAAAAAAAAAAAAAAAAAAAAA... :)

While this isnt a proper solution because you should be able to install and run the beta version fine, you could just tack this on the end of your script as a temporary workaround:

Func _FileListToArray($sPath, $sFilter = "*", $iFlag = 0)
    Local $hSearch, $sFile, $asFileList[1]
    If Not FileExists($sPath) Then
        SetError(1)
        Return ""
    EndIf
    If (StringInStr($sFilter, "\")) or (StringInStr($sFilter, "/")) or (StringInStr($sFilter, ":")) or (StringInStr($sFilter, ">")) or (StringInStr($sFilter, "<")) or (StringInStr($sFilter, "|")) or (StringStripWS($sFilter, 8) = "") Then
        SetError(2)
        Return 0
    EndIf
    If Not ($iFlag = 0 Or $iFlag = 1 Or $iFlag = 2) Then
        SetError(3)
        Return ""
    EndIf
    $asFileList[0] = 0
    $hSearch = FileFindFirstFile($sPath & "\" & $sFilter)
    If $hSearch = -1 Then 
        SetError(0)
        Return 0
    EndIf
    While 1
        $sFile = FileFindNextFile($hSearch)
        If @error Then ExitLoop
        If $iFlag = 1 Then
            If StringInStr(FileGetAttrib($sPath & "\" & $sFile), "D") <> 0 Then ContinueLoop
        EndIf
        If $iFlag = 2 Then
            If StringInStr(FileGetAttrib($sPath & "\" & $sFile), "D") = 0 Then ContinueLoop
        EndIf
        ReDim $asFileList[UBound($asFileList) + 1]
        $asFileList[0] = $asFileList[0] + 1
        $asFileList[UBound($asFileList) - 1] = $sFile
    WEnd
    FileClose($hSearch)
    SetError(0)
    If $asFileList[0] = 0 Then Return ""
    Return $asFileList
EndFunc ;==>_FileListToArray
Link to comment
Share on other sites

  • Moderators

Could not get it to work. I am very sad. What am I doing wrong HAAAAAAAAAAAAAAAAAAAAAAAAAA... :(

Are we supposed to guess what your doing at all? You didn't even show how you are using any of the functions in script :)

Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.

Link to comment
Share on other sites

I tried to test the script provided and it did not work for me. Perphaps you can shine a light on me and show me how it suppose to be done. In my initial request explains what I want to do and a simple script that it kinda works, but it's not perfect. I'm still learning, it will take some time for me to grasp the entire script language just you like you have. Let me know your thougths.

Are we supposed to guess what your doing at all? You didn't even show how you are using any of the functions in script :)

Link to comment
Share on other sites

Well, I tried a lot of things before compiling the script and it did not work for me. Can you help and tell me what I'm during wrong or perphaps have a script that will work with what I want to do. The idea is there of what I want to do, but I don't know exactly how to put it together. It seems that you have more experience in this field, so please show me the way...:)

what im guessing you did is just compile his script hahahhahaaa, to bad its just a UDF

Link to comment
Share on other sites

  • Moderators

Just show what you tried. I'm not going to guess what in the world you did to make it fail. Just show the code you used that failed, and we can help you figure it out.

Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.

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