Jump to content

Recommended Posts

how to read or run a file using its name with extension. it have to search with the folder  and sub folder

Run(@ComSpec & " /c " & Chr(34) & @ScriptDir & "\Multimedia.bat" & Chr(34), @ScriptDir) ; this line reads the Multimedia.bat file in the script directory. i need to read from the script directory and the consisting sub folders into that directory

Help plz
 

Link to post
Share on other sites
Posted (edited)

Basic example of getting all files in the current directory into an array and looping through the array.

#include <File.au3>

Local $aFiles = _FileListToArrayRec(@ScriptDir, "*.*", 1, 1, 0, 0)
    If @error Then Exit MsgBox(4096, "Error", "No files found.")

Local $sMessage = "File Name : "
SplashTextOn("Files", $sMessage, 500, 100, -1, -1, $DLG_TEXTLEFT, "")
For $i = 1 To $aFiles[0]
    ControlSetText("Files", "", "Static1", $i & " of " & $aFiles[0] & @CRLF & $sMessage & $aFiles[$i])
    Sleep(100)
Next
SplashOff()

 

Edited by Subz
Link to post
Share on other sites

@Subz i saw post or examples like that, but i don't need listing files into that directory.

Run(@ComSpec & " /c " & Chr(34) & @ScriptDir & "\Multimedia.bat" & Chr(34), @ScriptDir) ;

Here Program search Multimedia.bat the script directory (@ScriptDir) and run by this command, is there have anything for reading sub directory.

Link to post
Share on other sites

Maybe OP needs first a list of all sub folders (i.e. a 3rd parameter = 2 in _FileListToArrayRec)

His sentences "i need to read from the script directory and the consisting sub folders into that directory", then "i don't need listing files" seem to show this.

After getting a list of sub folders, it's up to him to know what to do if the file Multimedia.bat is found in several sub folders.

But I may be wrong in this explanation, let's wait and see...

Link to post
Share on other sites
Posted (edited)
1 hour ago, ashraful089 said:

I hope i am able to explain the question

I guess I understood your question.

If the file Multimedia.bat is located in the root directory, then @ScriptDir returns C:\ . If you now add \Multimedia.bat, the result is :

C:\\Multimedia.bat -> (double backslash).

If @ScriptDir is located in a subfolder e.g. C:\Testfolder, then the result is C:\Testfolder\Multimedia.bat

Is this your problem ?

Edited by Musashi
text interpreted as emoji

Musashi-C64.png

"In the beginning the Universe was created. This has made a lot of people very angry and been widely regarded as a bad move."

Link to post
Share on other sites
1 hour ago, ashraful089 said:

Only includes a trailing backslash when the script is located in the root of a drive.

To solve the problem with double backshlashes in the root directory, you could use e.g.

#include <WinAPIShPath.au3>
Run(@ComSpec & " /c " & Chr(34) & _WinAPI_PathAddBackslash (@Scriptdir) & "multimedia.bat" & Chr(34), @ScriptDir)

 

Musashi-C64.png

"In the beginning the Universe was created. This has made a lot of people very angry and been widely regarded as a bad move."

Link to post
Share on other sites
  • 2 weeks later...

  

image.png.a86ff7d7bccfdb32f4e9482367d1f1c5.png

Here, i want to run Anydesk.exe without declaring its full path in the script (Search in Directory with its sub-directory), like the full path is unknown . the declaration in script for search will be in directory (App Installer Folder) So it will search sub directories under it until gets the desired file

Link to post
Share on other sites

You can still use _FileListToArrayRec to search for an individual item, example:

1. Search for AnyDesk.exe below @ScriptDir & "\App Installer" and return the full path
2. Search for A*.exe below @ScriptDir & "\App Installer", will give you an option to select between multiple files and return the full path to the file.

#include <Array.au3>
#include <ComboConstants.au3>
#include <GUIConstantsEx.au3>
#include <File.au3>

Local $sAnyDesk = _SearchFolder(@ScriptDir & "\App Installer", "AnyDesk.exe")
MsgBox(4096, "Result for AnyDesk", (@error ? "Error : " & $sAnyDesk : "AnyDesk Path : " & $sAnyDesk))

Local $sSearch = _SearchFolder(@ScriptDir & "\App Installer", "A*.exe")
MsgBox(4096, "Result for A*", (@error ? "Error : " & $sSearch : "File Path : " & $sSearch))

Func _SearchFolder($_sSearchDir = @ScriptDir & "\App Installer", $_sSearchFile = "*.*")
    Local $aSearch = _FileListToArrayRec($_sSearchDir, $_sSearchFile, 1, 1, 0, 2)
    If @error Then Return SetError(1, 0, $_sSearchFile & " not found.")
    If $aSearch[0] = 1 Then
        ;~ One item found
        $sResult = $aSearch[1]
    Else
        ;~ Multiple items found
        $sResult = _SelectFile($aSearch)
        If @error Then Return SetError(1, 0, "No item selected.")
    EndIf
    Return SetError(0, 0, $sResult)
EndFunc

Func _SelectFile($_aSelectFiles)
    If Not IsArray($_aSelectFiles) Then Return SetError(1, 0, "")
    Local $sSelect = "", $iError = 1
    GUICreate("Select", 500, 70)
    GUISetFont(12, 400, -1, "MS San Serif")
    Local $idSelection = GUICtrlCreateCombo("", 10, 10, 480, 25, $CBS_DROPDOWNLIST)
    Local $idSelect = GUICtrlCreateButton("Select", 490-100, 40, 100, 25)
    GUICtrlSetData($idSelection, _ArrayToString($_aSelectFiles, "|", 1), $_aSelectFiles[1])
    GUISetState()
    While 1
        Switch GUIGetMsg()
            Case $GUI_EVENT_CLOSE
                ExitLoop
            Case $idSelect
                $sSelect = GUICtrlRead($idSelection)
                $iError = 0
                ExitLoop
        EndSwitch
    WEnd
    Return SetError($iError, 0, $sSelect)
EndFunc

 

Link to post
Share on other sites

Did you change the search path from @ScriptDir & "\App Installer"?  Actually tested this before posting so I know it works, please post the code you used.

Link to post
Share on other sites
#include <Array.au3>
#include <ComboConstants.au3>
#include <GUIConstantsEx.au3>
#include <File.au3>

Local $sAnyDesk = _SearchFolder(@ScriptDir & "\AppInstaller", "AnyDesk.exe")
MsgBox(4096, "Result for AnyDesk", (@error ? "Error : " & $sAnyDesk : "AnyDesk Path : " & $sAnyDesk))

Local $sSearch = _SearchFolder(@ScriptDir & "\AppInstaller", "A*.exe")
MsgBox(4096, "Result for A*", (@error ? "Error : " & $sSearch : "File Path : " & $sSearch))

Func _SearchFolder($_sSearchDir = @ScriptDir & "\AppInstaller", $_sSearchFile = "*.*")
    Local $aSearch = _FileListToArrayRec($_sSearchDir, $_sSearchFile, 1, 1, 0, 2)
    If @error Then Return SetError(1, 0, $_sSearchFile & " not found.")
    If $aSearch[0] = 1 Then
        ;~ One item found
        $sResult = $aSearch[1]
    Else
        ;~ Multiple items found
        $sResult = _SelectFile($aSearch)
        If @error Then Return SetError(1, 0, "No item selected.")
    EndIf
    Return SetError(0, 0, $sResult)
EndFunc

Func _SelectFile($_aSelectFiles)
    If Not IsArray($_aSelectFiles) Then Return SetError(1, 0, "")
    Local $sSelect = "", $iError = 1
    GUICreate("Select", 500, 70)
    GUISetFont(12, 400, -1, "MS San Serif")
    Local $idSelection = GUICtrlCreateCombo("", 10, 10, 480, 25, $CBS_DROPDOWNLIST)
    Local $idSelect = GUICtrlCreateButton("Select", 490-100, 40, 100, 25)
    GUICtrlSetData($idSelection, _ArrayToString($_aSelectFiles, "|", 1), $_aSelectFiles[1])
    GUISetState()
    While 1
        Switch GUIGetMsg()
            Case $GUI_EVENT_CLOSE
                ExitLoop
            Case $idSelect
                $sSelect = GUICtrlRead($idSelection)
                $iError = 0
                ExitLoop
        EndSwitch
    WEnd
    Return SetError($iError, 0, $sSelect)
EndFunc

 

@Subzi used this code. i just deleted space from AppInstaller cause my folder is named like that.
But i was asked about is there have any small form one or two line code  which will lookup its directory and its sub directories too
 

Run(@ComSpec & " /c " & Chr(34) & @ScriptDir & "\AnyDesk.exe" & Chr(34), @ScriptDir)


 

Link to post
Share on other sites

Is your @ScriptDir your C:\Users\<Profile Name>?  Based on your screenshot above it's under %UserProfile%\Downloads\AppInstaller, so you should be able to use:

Run(_SearchFolder(@UserProfileDir & "\Downloads\AppInstaller", "AnyDesk.exe"))

 

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
  • Recently Browsing   0 members

    No registered users viewing this page.

  • Similar Content

    • By xiantez
      Hello Everyone, 
      I am having a bit of trouble getting my FileReadLine function to read all the characters in a specific text file. Here is my code. 
      Func PastePassword() ;Paste Password $file = ('C:\Text\Logins\MacroPWList.txt') FileOpen($file, 0) For $i = 2 to _FileCountLines($file) $line = FileReadLine($File, 2) GUISetState(@SW_HIDE, $wsi_form) Sleep(350) Send($line) Sleep(150) Send("{Enter}") ExitLoop Next EndFunc $line should return the following string "EY@RdJ5S}#<r8rh"
      However, instead $line is returning "EY@RdJ5S}<r8rh"
      For some reason it is leaving out the # sign in the string. Does anyone know why that is?
       
      Thanks for all your help!
×
×
  • Create New...