Jump to content

Im looking for a string, can't find it


Recommended Posts

Ill remeber i once used a string something that could trim a variable or a text line from the right, until it reached a specific character..

I want to do this:

C:\Musik\Groove Coverage.mp3

I would have to get the file type if the current found file. To do that, ill have to trim it from the right, until it reache the "." character, and then tell me by a msgbox, witch filetype it is..

Or is there an easier way?.. i looked the varius command under String management, but couln't find somthing like that.

Thx for any help!

Edited by Wb-FreeKill
Link to comment
Share on other sites

Ill remeber i once used a string something that could trim a variable or a text line from the right, until it reached a specific character..

I want to do this:

C:\Musik\Groove Coverage.mp3

I would have to get the file type if the current found file. To do that, ill have to trim it from the right, until it reache the "." character, and then tell me by a msgbox, witch filetype it is..

Or is there an easier way?.. i looked the varius command under String management, but couln't find somthing like that.

Thx for any help!

<{POST_SNAPBACK}>

$sFileName = "C:\Musik\Groove Coverage.mp3"
$sExt = StringRight($sFileName, StringLen($sFileName)-StringInStr($sFileName, ".", 0, -1))
MsgBox(262144,'debug line ~2' , '$sExt:' & @lf & $sExt);### Debug MSGBOX

Or if you got your heart set on String trimming then:

$sFileName = "C:\Musik\Groove Coverage.mp3"
$sExt = StringTrimLeft($sFileName, StringInStr($sFileName, ".", 0, -1))
MsgBox(262144,'debug line ~2' , '$sExt:' & @lf & $sExt);### Debug MSGBOX
Edited by pacman
Link to comment
Share on other sites

$sFileName = "C:\Musik\Groove Coverage.mp3"
$sExt = StringRight($sFileName, StringLen($sFileName)-StringInStr($sFileName, ".", 0, -1))
MsgBox(262144,'debug line ~2' , '$sExt:' & @lf & $sExt);### Debug MSGBOX

Or if you got your heart set on String trimming then:

$sFileName = "C:\Musik\Groove Coverage.mp3"
$sExt = StringTrimLeft($sFileName, StringInStr($sFileName, ".", 0, -1))
MsgBox(262144,'debug line ~2' , '$sExt:' & @lf & $sExt);### Debug MSGBOX

<{POST_SNAPBACK}>

Thank you :lmao:
Link to comment
Share on other sites

Ill remeber i once used a string something that could trim a variable or a text line from the right, until it reached a specific character..

I want to do this:

C:\Musik\Groove Coverage.mp3

I would have to get the file type if the current found file. To do that, ill have to trim it from the right, until it reache the "." character, and then tell me by a msgbox, witch filetype it is..

Or is there an easier way?.. i looked the varius command under String management, but couln't find somthing like that.

Thx for any help!

<{POST_SNAPBACK}>

The below function is very useful:

$file = "C:\Musik\Groove Coverage.mp3"

$line = StringSplit ( $file, "." )

The left part ( before the ".") will be stored in $line[1]

and the part after the "." will be in $line[2]

Link to comment
Share on other sites

Almost finish :lmao:

But how can i make a new search, without closing the GUI and run again?

It have to delete all in the current list every time a new search starts!

#include <GUIConstants.au3>


$FileSearchGUI = GUICreate("File search",400,300, 100,200,-1,$WS_EX_ACCEPTFILES)
GUISetBkColor (0x00E0FFFF)

$listview = GUICtrlCreateListView ("Filename  |Filetype|Size   |Location  ",10,60,380,150)
$button = GUICtrlCreateButton ("Value?",75,240,70,20)
$input = GUICtrlcreateInput("C:\Musik\",20,10,150,20)
$Filetype = GUICtrlCreateCombo("*.*",190,10,60,20)
GUICtrlsetdata(-1,"*.mp3|*.avi|*.mpg|")
$StartSearch = GUICtrlcreateButton("Start",300,10,70,22)
$label = GUICtrlcreatelabel("",20,40,300,20)
;============================================================
Func _FileSearch($szMask,$nOption)
    $szRoot = ""
    $hFile = 0
    $szBuffer = ""
    $szReturn = ""
    $szPathList = "*"
    Dim $aNULL[1]

    If Not StringInStr($szMask,"\") Then
         $szRoot = GUICtrlread($input)
    Else
         While StringInStr($szMask,"\")
              $szRoot = $szRoot & StringLeft($szMask,StringInStr($szMask,"\"))
              $szMask = StringTrimLeft($szMask,StringInStr($szMask,"\"))
         Wend
    EndIf
    If $nOption = 0 Then
         _FileSearchUtil($szRoot, $szMask, $szReturn)
    Else
         While 1
         sleep(10)           
             $hFile = FileFindFirstFile($szRoot & "*.*")
              If $hFile >= 0 Then
                   $szBuffer = FileFindNextFile($hFile)
                   While Not @ERROR
                        If $szBuffer <> "." And $szBuffer <> ".." And _
                             StringInStr(FileGetAttrib($szRoot & $szBuffer),"D") Then _
                             $szPathList = $szPathList & $szRoot & $szBuffer & "*"
                        $szBuffer = FileFindNextFile($hFile)
                   Wend
                   FileClose($hFile)
              EndIf
              _FileSearchUtil($szRoot, $szMask, $szReturn)
              If $szPathList == "*" Then ExitLoop
              $szPathList = StringTrimLeft($szPathList,1)
              $szRoot = StringLeft($szPathList,StringInStr($szPathList,"*")-1) & "\"
              $szPathList = StringTrimLeft($szPathList,StringInStr($szPathList,"*")-1)
         Wend
    EndIf
    If $szReturn = "" Then
         $aNULL[0] = 0
         Return $aNULL
    Else
         Return StringSplit(StringTrimRight($szReturn,1),"*")
    EndIf
EndFunc

Func _FileSearchUtil(ByRef $ROOT, ByRef $MASK, ByRef $RETURN)
    $hFile = FileFindFirstFile($ROOT & $MASK)
    If $hFile >= 0 Then
         $szBuffer = FileFindNextFile($hFile)
         While Not @ERROR
              If $szBuffer <> "." And $szBuffer <> ".." Then _
                   $RETURN = $RETURN & $ROOT & $szBuffer & "*"
              $szBuffer = FileFindNextFile($hFile)
         Wend
         FileClose($hFile)
    EndIf
EndFunc
;============================================================
Func Startsearch()
WinSetTitle($FileSearchGUI,"","File search - Searching...")

$a = _FileSearch(GUICtrlread($Filetype),1)
GUICtrlsetdata($label,$a[0] & " Files was found in " & GUICtrlread($input))
If $a[0] > 0 Then
    For $i = 1 to $a[0]
    ;============================================================
    ;                  Get File Size = kb
    ;============================================================
        $Getsize = FileGetSize($a[$i])
        $SizeCalc = $GetSize /1024
        $Size = Round($SizeCalc,0)
    ;============================================================
    ;                    Get File Type
    ;============================================================
        $sExt = StringTrimLeft($a[$i], StringInStr($a[$i], ".", 0, -1))
        $sExtlen = StringLen($sExt)
        If $sExtlen > 3 Then
        $sExt = "Directory"
        Else
        $sExt = $sExt
        EndIf   
    ;============================================================
    ;               Sort Out Path In Filename
    ;============================================================
        $Length = StringLen(GUICtrlread($input))
        $RealFileName = StringTrimLeft($a[$i], $Length)
        $type = FileGetAttrib ($a[$i]) 
    ;============================================================
    ;                  Sort Out Filetypes
    ;============================================================
        If $type = "ASH" Then
        ElseIf $type = "D" Then
        Elseif $type = "AD" Then
        Else
        GUICtrlCreateListViewItem($RealFileName & "|" & $sExt & "|" & $Size & " kb" & "|" & GUICtrlRead($input), $listview)
        EndIf
    Next
WinSetTitle($FileSearchGUI,"","File search - Search complete")
EndIf
Endfunc
;============================================================
GUISetstate()
While 1
    $msg = GUIGetMsg()
    If $msg = $GUI_EVENT_CLOSE Then ExitLoop
    
    If $msg = $StartSearch Then
       Startsearch()
    Endif   
    
    If $msg = $Button Then
       MsgBox(0,"listview item",GUICtrlRead(GUICtrlRead($listview)))
    EndIf   

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