Jump to content
Sign in to follow this  
Gringo

FileOpenDialog and FileSelectFolder

Recommended Posts

Hi,

I'm trying to:

-Select a file in a folder (to store it to an ini file)

-Write the file on an ini

-Copy files to the folder selected by the user

instead of using FileOpenDialog then FileSelectFolder, I was wondering if it was possible to do the whole thing only with FileOpenDialog spliting the value returned in 2 variables. I got something like that for the first part (select a file and store it to an ini file)

Local $message = "Select your executable"
                        Local $pathk = FileOpenDialog($message, "C:" & "", "Select the executable you want to terminate (*.exe)", 1 + 4)

                        Local $path = "None"
;ici je dois copier les fichiers

                        $split = StringSplit($pathk, "\")
                        $tokill = $split[$split[0]]



                        If @error Then
                        MsgBox(4096, "", "No Executable chosen")
                        Else



                        MsgBox(4096, "", $pathk & " Will be terminated " & @LF & @LF & "Press OK to EXIT ")
                        IniWrite(@ScriptDir & "\path.ini", "Torun", "path", $path)
                        IniWrite(@ScriptDir & "\path.ini", "Tokill", "pathk", $tokill)
                        EndIf

As you can see I manage to split the value returned by FileOpenDialog to have only the exe but as a noob I can't manage to get the path to copy the files I need to the same path.

Any idea? ^^

Share this post


Link to post
Share on other sites

Have a look at _PathSplit it will split a full path and file name out into an array of useful parts.


Problem solving step 1: Write a simple, self-contained, running, replicator of your problem.

Share this post


Link to post
Share on other sites

There are bunch of path API functions here: "C:\Program Files (x86)\AutoIt3\Include\WinAPIShPath.au3" 

Simple code:

Func GetPath($sFullPath)
    Local $i = StringInStr($sFullPath,'\',1,-1) ; first backslah from end
    If $i = 0 Then Return $sFullPath
    Return StringLeft($sFullPath, $i)
EndFunc

 

Share this post


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
Sign in to follow this  

  • Recently Browsing   0 members

    No registered users viewing this page.

  • Similar Content

    • By c.haslam
      _
      _cFileSelectFolder() is intended as a replacement for native FileSelectFolder() for selecting folders: It implements the left pane of FileSelectFolder(), and goes beyond FileSelectFolder() in several ways.
      Features:
      •    It is user friendly and designed to be easy to use;
      •    New folder, Delete folder and Rename folder controls are optional;
      •    Its GUI can be placed anywhere, including centred on another window;
      •    Neither needs nor uses CLSIDs;
      •    Checks calling parameters rigorously, with the user choosing either to show error messages in a dialog or to set @error and return them to the caller;
      •    For local and mapped drives, accepts file specifications with drives that can be drive letters, drive labels, or both,
      •    For local and mapped drives, always returns drive letter:\ ...\ so its output is compatible with native AutoIt functions.
      •    For UNC paths, returns \\computer\share\...\
      •    For unmapped drives on computers on the network,  offers a shortcut to shares.
      •    Selecting a treeview item to be highlighted initially is specified in a user-friendly way, including a diagnostic for when the user gets it wrong
      •    Because it can be called with many arguments, a user can show a list of the arguments / parameters and their values
      The root of the treeview can be:
      •    The Desktop hierarchy with Desktop at the top
      •     Partial Desktop hierarchy with any other Desktop item at the top, with or without local/mapped drives and file folders, or remote shares and file folders (as appropriate),
      •     Local/mapped drives and file folders, or
      •    Remote shares and folders.
      The script and example scripts are in the zip file. Documentation beyond what is in the UDF header is  in the PDF file,   cFileSelectFolder 1_6_1.pdf
      Comments and suggestions are most welcome.
       
       
       
      cFileSelectFolder 1_6_1.pdf
    • By YawStar
      Hi there. I want to add my FileSelectFolder function with "include subdirectories Checkbox". The example image is shown in below.

    • By Tippex
      I have a problem with FileOpenDialog using long default filenames ... they always get truncated. 
      For example: 
      "A Long FileName.mpg" as a default would prompt as just "FileName.mpg" (but scrolling left will show it named correctly).
      Does anyone know of a fix for this please (I didn't spot it in a Forum search), or is it one for the bug tracker?
      #include <FileConstants.au3> #include <MsgBoxConstants.au3> Local Const $sMessage = "Hold down Ctrl or Shift to choose multiple files." Local $sFileOpenDialog = FileOpenDialog($sMessage, @WindowsDir & "\", "Images (*.jpg;*.bmp)|Videos (*.avi;*.mpg)", BitOR($FD_FILEMUSTEXIST, $FD_MULTISELECT), "A Long FileName.mpg") Thanks,
    • By XinYoung
      Hello all!   I'm stuck at a seemingly simple part of my script. Using IE, I'm filling out a web form that involves clicking a "Browse" button and selecting a file. Once the file explorer dialog opens, however, I am unable to control it.
      I have a string, which is the name of the file I want, and I'm trying to insert it into the 'File name:' text box in the dialog (which already has focus), but it doesn't get inserted. I've tried ClipPut and Send. 

      What's even more concerning is, when I close the dialog, the string is then pasted into the very next window that has focus, which is often SciTE. It's like that Browse's file open dialog halts all processes. Once it's closed, the script continues.
      ;~ Open a IE window and navigate to the login page. Global $oIE = _IECreate($urlBBLogin) _IELoadWait($oIE) ;~ Recognize the form on this page (login input boxes). Local $oForm = _IEFormGetObjByName($oIE, "login") Local $oTextLogin = _IEFormElementGetObjByName($oForm, "user_id") Local $oTextPass = _IEFormElementGetObjByName($oForm, "password") ;~ Enter the Automation user credentials into the form. _IEFormElementSetValue($oTextLogin, $bbUsername) _IEFormElementSetValue($oTextPass, $bbPassword) ;~ Click the Login button. _IEFormSubmit($oForm) _IELoadWait($oIE) ;~ Navigate to the feedfile upload page. _IENavigate($oIE, $urlUpload) _IELoadWait($oIE) ;~ Click the Browse button Local $Browse = _IEGetObjById($oIE, "feedFile_chooseLocalFile") _IEAction($Browse, "Click") Local $Browse = WinWait("Choose File to Upload") ;~ Open the file we created. WinActivate($Browse) Send($finalFile) Has anyone else experienced this problem? Any ideas to get around it? Am I approaching this the wrong way?
      Any support is greatly appreciated.
      Thank you.
    • By PINTO1927
      Hello guys,
      I'm working on this script:
      Case $BTN Global $URL = FileOpenDialog("IMPORT FILE", $DESKTOP, "ALL FORMAT (*)", 4) $DIR_DEST = "C:\DIR-WORK\list\IMPORT_DOC\" DirCreate($DIR_DEST) Local $LINE For $t = 1 To $URL[0] _FileReadToArray($URL[$t], $LINE) For $u = 1 To $LINE[0] FileCopy($URL[$u], $DIR_DEST) Next Next the selected files via OpenFileDialog must be copied to the folder $DIR_DEST.
       
×
×
  • Create New...