Jump to content

GetFileName


Recommended Posts

I have searched and I can't find anything that will help. Obviously I am new. But here goes I have a script that does recursive file searching, that works great. I need to be able to pass the filename from that search to a send(). Here is my script. I am completely lost, I have tried wingettitle, wingettext, and pathsplit. HELP.

; _FileSearch( <Path and Mask>, <Option (0 - normal, 1- recursive)>)
; Returns array. Either Array of files (full path) where...
; Array[0] is number of files.
; Array[0] = 0 if nothing found.
;
; EXAMPLE USAGE
;--------------------------------------------
#include <File.au3>


$a = _FileSearch("*.dwg",1)
;ShellExecute("C:\Program Files\Acadm 6\acad.exe")
If $a[0] > 0 Then
    For $i = 1 to $a[0]
         ;MsgBox(4096,"",$a[$i])
         ShellExecute($a[$i])
         Dim $szDrive, $szDir, $szFName, $szExt
         $TestPath = _PathSplit(@ScriptDir & "..\..\" & $a, $szDrive, $szDir, $szFName, $szExt)
         WinWait("AutoCAD Mechanical Power Pack")
         If Not WinActive("AutoCAD Mechanical Power Pack") Then WinActivate("AutoCAD Mechanical Power Pack")
         WinWaitActive("AutoCAD Mechanical Power Pack")
         Send("{ALTDOWN}{ALTUP}n{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{RIGHT}{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{ENTER}")
         WinWait("BOM","&Properties")
         If Not WinActive("BOM","&Properties") Then WinActivate("BOM","&Properties")
         WinWaitActive("BOM","&Properties")
         MouseMove(782,286)
         MouseDown("left")
         MouseUp("left")
         WinWait("Export","Save as &type:")
         If Not WinActive("Export","Save as &type:") Then WinActivate("Export","Save as &type:")
         WinWaitActive("Export","Save as &type:")
         MouseMove(731,595)
         MouseDown("left")
         MouseMove(701,639)
         MouseUp("left")
         ;MouseMove(284,290)
         ;MouseDown("left")
         ;MouseUp("left")
         MouseMove(702,565)
         MouseDown("left")
         MouseUp("left")
         Send($szFName)
         MouseMove(812,565)
         MouseDown("left")
         MouseUp("left")
         WinWait("BOM","&Properties")
         If Not WinActive("BOM","&Properties") Then WinActivate("BOM","&Properties")
         WinWaitActive("BOM","&Properties")
         MouseMove(654,727)
         MouseDown("left")
         MouseUp("left")


         ProcessClose("acad.exe")
         WinWait("AutoCAD","Save changes to ")
         If Not WinActive("AutoCAD","Save changes to ") Then WinActivate("AutoCAD","Save changes to \\et")
         WinWaitActive("AutoCAD","Save changes to ")
         MouseMove(160,96)
         MouseDown("left")
         MouseUp("left")


    Next
EndIf
;--------------------------------------------

Func _FileSearch($szMask,$nOption)
    $szRoot = ""
    $hFile = 0
    $szBuffer = ""
    $szReturn = ""
    $szPathList = "*"
    Dim $aNULL[1]

    If Not StringInStr($szMask,"\") Then
         $szRoot = @SCRIPTDIR & "\" ;put gates directory here
    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
              $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 _FileGetPath($sFile)
    Local $sDir, $sPath, $NULL
    _PathSplit($sFile, $sDir, $sPath, $NULL, $NULL)
    Return _PathMake($sDir, $sPath, "", "")
EndFunc

Link to comment
Share on other sites

different from your 1st post? ( http://www.autoitscript.com/forum/index.ph...mp;#entry333607 )

I thought the filse name where given from the return value of _FileSearch()?

Not really different just didn't match the title of the other post wasn't sure if I should add different questions to same post, (sorry, I am new at this) ! The filename is returned from the _filesearch, but every time I put Send($a) nothing gets entered into the field receiving the send.
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...