Search code examples
command-promptfilemakergetfiles

Open the first file in a folder using command prompt


I am trying to get the name of the first file of a folder using command prompt command. The first files' names in these folders do not follow any rules unfortunately. They are also different types so there isn't an extension rule. My final goal is to pass this name into FileMaker so that I can get all the files that are inside these folders.

In addition, if there is a way to take the name by just using a script step or a function in Filemaker, that would also be perfect!

Thank you so much!

P/s: I'm sorry for not being clear before, I'm trying to perform this on a Windows machine


Solution

  • To run cmd from FileMaker use "Send Event" script step in your FileMaker script, "Send the" dropdown should be set to "open document/application" and select "Text" option. In text box enter

    cmd.exe /c "your cmd command"
    

    e.g.

    cmd.exe /c MKDIR "C:\Users\Nicolai\Desktop\ImportantStuff"
    

    You have a few options to get the output back.

    1. Save the output of CMD to a text file and import it into FileMaker as text file
    2. Save the output as XML and import it as XML
    3. Save the output as HTML, load it in FileMaker webviewer and scrap the context of webviewer
    4. Copy the output of cmd command and paste it into a FileMaker field with "Go to Field" / "Paste" script steps

    The last one is the easiest to implement, but has a disadvantage of overwriting user clipboard. I am using clip command on Windows 10. I am not sure if it was available on the earlier Windows systems.

    My "Send Event" looks like this:

    cmd.exe /c DIR "C:\Users\Nicolai\Desktop\MyFolder" /o:d /b | clip
    

    I pasted the result into a myField field:

    GetValue ( myTestDb::myField; 1)
    

    Gives me the first file name sorted by date and time