Announcement

Collapse
No announcement yet.

How to pass a FileBrowse result to Command Line

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Karlos34
    replied
    Thanks, mutch appreciated for taking the time to help, splitting the filename code worked , will try to work out why it works when split but not when full path is given

    Again many thanks for the solution

    Leave a comment:


  • Old Fellow
    replied
    This is from one of my projects, to split the the file path down

    Code:
    image_split = String.SplitPath(Image_input); -- this breaks everypart of the filepath
    image_split_drive_letter = image_split.Drive;
    image_split_folder = image_split.Folder;
    image_split_image_name = image_split.Filename; -- this is the image file name
    image_split_file_extension = image_split.Extension; -- this the image file extension
    Image_fullName = image_split_image_name..image_split_file_extension
    WorkingFolder = image_split_drive_letter..image_split_folder
    change (Image_input) to (WordDocument[1]) and see if that works

    I called it "image_split" cause I was dealing with .iso images, you can name it to suit your needs.



    This gives the name of the .exe file

    Code:
    exeFileBrowse = Dialog.FileBrowse(true, "Locate File", _DesktopFolder, "Executable Files (*.exe)|*.exe|", "", "dat", false, false);
    --File.Run(exeFileBrowse[1], "", "", SW_SHOWNORMAL, false);
    
    image_split = String.SplitPath(exeFileBrowse[1]); -- this breaks everypart of the filepath
    image_split_drive_letter = image_split.Drive;
    image_split_folder = image_split.Folder;
    image_split_image_name = image_split.Filename; -- this is the image file name
    image_split_file_extension = image_split.Extension; -- this the image file extension
    Image_fullName = image_split_image_name..image_split_file_extension
    WorkingFolder = image_split_drive_letter..image_split_folder
    
    
    result = Dialog.Message("Notice", Image_fullName, MB_OK, MB_ICONINFORMATION, MB_DEFBUTTON1);

    Leave a comment:


  • colc
    replied
    to get filename use something like this :

    Code:
    tFiles = Dialog.FileBrowse(true, "Browse", "", "All Files (*.*)|*.*|", "", "", true, false);
    
    -- Ensure tFiles contains something, and the user didn't press cancel
    if tFiles and tFiles[1] ~= "CANCEL" then
    -- Traverse the table containing the selected file paths
    for nIndex, sFilePath in pairs(tFiles) do
    
    -- Set sText to the filename (without extension) using String.SplitPath
    sText = String.SplitPath(sFilePath).Filename;
    sExtn = String.SplitPath(sFilePath).Extension;
    sFile = sText..sExtn
    end
    end
    then use
    result = File.Run("AutoPlay\\Docs\\go.exe", "write "..sFile, "AutoPlay\\Docs", SW_SHOWNORMAL, false);

    Leave a comment:


  • Karlos34
    replied
    Thanks for the reply, I am sure its something simple I am missing but cant get the .exe to accept the string as a filename, works find when entered directly

    tried the script but not working no response from go.exe like it cant accept WordDocument[1] as a filename

    Leave a comment:


  • Karlos34
    replied
    it might be because its giving a full path is there a way to get rid of the path and just use the filename from FileBrowse ?

    file is in the same directory as go.exe, I am new to this not done any programming for years

    Leave a comment:


  • colc
    replied
    File Browse RETURNS
    A table containing the list of paths to the files that were selected. Each individual path can be accessed at it's table index.

    Your file test.doc is located in the same folder as go.exe?

    You need to concatenate your strings eg: "Write" and the string returned from File Browse

    try:
    Code:
    result = File.Run("AutoPlay\\Docs\\go.exe", "write ".. WordDocument[1], "AutoPlay\\Docs", SW_SHOWNORMAL, false);

    Leave a comment:


  • Old Fellow
    replied
    Does this help ?

    Code:
    exeFileBrowse = Dialog.FileBrowse(true, "Locate File", _DesktopFolder, "Executable Files (*.exe)|*.exe|", "", "dat", false, false);
    File.Run(exeFileBrowse[1], "", "", SW_SHOWNORMAL, false);
    Can you explain what your "go.exe" is. Is it just an example ?

    I tested my script and it allows me to search for a .exe and run it.

    Leave a comment:


  • Old Fellow
    replied
    what is it your are actually wanting to do ?

    Run a .exe within a AMS project by using file browse ? This "go.exe" ?

    Leave a comment:


  • Karlos34
    replied
    Thanks for the reply, I am using another filetype word doc was just an example

    my command line program does not seem to be accepting the filename string from Dialoge.FileBrowse as the file to use

    I select file test.doc with file browser dialogue

    result = File.Run("AutoPlay\\Docs\\go.exe", "write", WordDocument[1], "AutoPlay\\Docs", SW_SHOWNORMAL, false); - NOT Working

    If I add a filename manually it works ok
    result = File.Run("AutoPlay\\Docs\\go.exe", "write test.doc", "AutoPlay\\Docs", SW_SHOWNORMAL, false);

    Leave a comment:


  • Old Fellow
    replied
    You could use "File.Open"

    Code:
    WordDocument = Dialog.FileBrowse(true, "Load File", _DesktopFolder, "Microsoft Word Document (*.doc,*.docx)|*.doc;*.docx|All Files (*.*)|*.*|", "", "", false, true);
    File.Open(WordDocument[1], "", SW_SHOWNORMAL);
    I added .docx too into the mix. I believe newer Microsoft Office Word default saves files with the .docx extension.

    Hope this helps.

    Leave a comment:


  • Ulrich
    replied
    The value stored in result[1] is a string and no further conversion is required.

    Ulrich

    Leave a comment:


  • Karlos34
    started a topic How to pass a FileBrowse result to Command Line

    How to pass a FileBrowse result to Command Line

    Need to pass the filename from the file selected using "Dialog FileBrowse" to a command line .exe argument

    Anyone know this can be done

    Here is my current script

    result = Dialog.FileBrowse(true, "Load File", _DesktopFolder, "Microsoft Word Document (*.doc)|*.doc|All Files (*.*)|*.*|", "", "", false, true);


    I need the filename in result[1] to be added to a command line with File.Run but I think the table needs changing to a string for it to work?

Working...
X
😀
🥰
🤢
😎
😡
👍
👎