Jump to content

Recommended Posts

Posted

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
 

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
Posted

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

Posted

 

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

Here " @ScriptDir "     Directory containing the running script. Only includes a trailing backslash when the script is located in the root of a drive.
Question is is there have any way for run a file from Script Sub directories?
I hope i am able to explain the question

Posted

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

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

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

  • 2 weeks later...
Posted

  

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

Posted

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

 

Posted

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.

Posted
#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)


 

Posted

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"))

 

  • 2 months later...
Posted

@Subz You always give such clear examples when replying to users.

I was looking for a way to search through a number of .txt files (in a folder) to find a certain set of characters and display them.

Sort of like a simple "Agent Ransack".

You're provided the perfect starting point for me to develop.

I'm feeling a little under the weather today, so this will have to wait for another day.

Thank you for being who you are.

taurus905

"Never mistake kindness for weakness."-- Author Unknown --"The highest point to which a weak but experienced mind can rise is detecting the weakness of better men."-- Georg Lichtenberg --Simple Obfuscator (Beta not needed.), Random names for Vars and Funcs

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
×
×
  • Create New...