Getting File I/O to Output a Lowercase File Name

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

  • Getting File I/O to Output a Lowercase File Name

    Problem Solved! (Sort of…)

    The problem I was facing is that there is no way to get PC DMIS to output a text file extension in lowercase. I was trying to automate an existing workflow of having to manually do a File>Export>Generic every time a program was run. We often use the program to measure batches of hundreds of parts, with each part run individually. As you can imagine, it takes a lot of time up trying to manually export a text file and name it every time you go to put another part on.

    It was easy enough to use the File I/O commands to automatically create the text files and autoincriment titles. However I did notice that it would always output the text files with all capitals, including the file extension (.TXT), but did not think it to be a problem.

    The next step the operator preforms is to use a master Excel sheet set up with macros to automatically import select text files for data review. This is where the problem with capitals kicked in; the Excel macro searches for files with a ".txt" file extension to import, that way it does not try to import programs or any other file type. Unfortunately it looks for exact matches, so in the program's mind a ".TXT" is not the same as ".txt" even though they are the exact same type of file. While it is easy enough to modify the macro with a simple "Or ".TXT"", I did not have access to every iteration of the Excel file in order to update them. This left me stuck trying to get PC DMIS to output ".txt"s.

    After experimenting with many different methods and commands, I soon discovered there was no possible way to get a lowercase ".txt" out of PC DMIS using File I/O commands. This is really a non-issue as a ".txt" and ".TXT" are the exact same file in everything but looks, but with our flawed Excel file it did become an issue.

    The next logical step was to find some way to rename the file extensions, and then figure out how to automate that method. After a brief search, I found the "ren" (rename) batch command. I created a batch file with the following line and threw it in a folder with some ".TXT" files:

    Code:
    ren *.TXT *.txt
    It simply uses a wildcard character (*) for whatever the file name may be, then looks for a following ".TXT" to replace with ".txt". Lo and behold it worked! Now to automate this...

    In order to get PC DMIS to automatically run this batch file all I had to do was use a execute external command line. This would execute the batch file, but it would run it in the PC DMIS program's directory while the files the program exported would be stored in whatever folder the operator input. Modifying the batch file allowed it to run on whatever folder the batch file itself was stored in:

    Code:
    cd /d %~dp0
    ren *.TXT *.txt
    Finally, since the batch file needed to be in the same directory as the exported file, a master batch file was created in the same folder as the PC DMIS program in order to keep track of it. The program was modified to export the text file as normal, then copy the master batch file to the text file's directory, execute the batch file, and then finally delete it. This is not a super-efficient method, but it does run near-instantaneously which is much faster than trying to manually export a generic text file every operation.

    In review, the PC DMIS program exports a text file using File I/O commands, copies a batch file to the file directory, executes the batch file which changes all ".TXT" to ".txt", then finally the batch file is deleted leaving only the text file with a lowercase extension.
    Last edited by Atokad; 05-12-2017, 04:19 PM.

  • #2
    I just tried this with success
    Code:
    ASSIGN/C_PATH="C:\PRODUCTION\PARTNUMBER\ROUTINE_Test.txt"
    C_FILE          =FILE/OPEN,C_PATH,APPEND
    FIle/WRITELINE...
    Text file was undercase. "...Test.txt"

    Comment


    • Atokad
      Atokad commented
      Editing a comment
      The problem I have is that when you edit a previously existing file, it preserves the file name's formatting. However, when creating a previously nonexistent file, it resorts to all capitals no matter what I do. For example, let's pretend there is a file on the desktop named "Test.txt".

      Code:
      ASSIGN/FILE_NAME="Test.txt"
      
      FILE          =FILE/OPEN,"C:\USERS\DESKTOP\" + FILE_NAME,WRITE
      FILE/WRITELINE...
      FILE/CLOSE...
      This ends up writing to the file, and the file on the desktop preserves its formatting and looks like "Test.txt". However, using the same code again but deleting the file on the desktop shows a different story. When forcing the program to create the file, it automatically capitalizes everything in the file name. With no file on the desktop originally, and then running the program, you end up with "TEST.TXT" on the desktop.
      Last edited by Atokad; 05-10-2017, 11:29 AM.

  • #3
    Untitled.jpg In the PC-DMIS program you should be able to control that with variables and the expression builder. If not, control it in excel with an if/else command that utilized both upper and lower case meathods.
    Last edited by R2ah1ze1l; 05-09-2017, 03:47 PM.

    Comment


    • Atokad
      Atokad commented
      Editing a comment
      I have gotten the LOWERCASE function to work just fine, such as the code you used above. The problem I am running into is using that in the creation of the text file itself. Let's use the code you have above:

      Code:
                ASSIGN/V2=".TXT"
                ASSIGN/V1=LOWERCASE("TeSt_"+V2)
      You have shown that V1 is now "test_.txt" in all lowercase, so the LOWERCASE function is working as intended. When I try to use this this in a FILE/OPEN script, I end up with outputting a capitalized file name still.

      Code:
                ASSIGN/V2=".TXT"
                ASSIGN/V1=LOWERCASE("TeSt_"+V2)
      
      FILE          =FILE/OPEN,"C:\USERS\DESKTOP\" + V1,WRITE
      FILE/WRITELINE...
      FILE/CLOSE...
      The expected outcome would to have a file named "test_.txt" on the desktop, but instead I end up with a file named "TEST_.TXT". However, I have noticed if I create a blank text file on the desktop named "test_.txt" and run the above code, it will preserve the formatting and leave the file name as "test_.txt" and still write to the file fine. Unfortunately I need the program to generate the file, so I cannot utilize this trick...

  • #4
    Yes my 2015 release has the same occur. New files are always uppercase. strange. I'm curious: why not output to csv or an excel-format, instead of all this text file output conversions?

    Comment


    • Atokad
      Atokad commented
      Editing a comment
      Unfortunately I'm just modifying an existing system, and I have no authority to change the work flow. The person who started doing testing on the project decided it would be a good idea to output each part into a text file, then have an excel document that imports all of the data from them. I have ended up taking their position, and now that we are in the middle of large amounts of testing the process can't be changed for consistency's sake. All of our data has to be comparable, so we have to use the same methods. The idea was to modify the CMM program to automatically save the text files in order to at least keep the user from having to manually export it every time. Unfortunately I can't modify the master excel sheet either, so if I can't figure out how to export the files with lowercase names, then the idea is canned.

  • #5
    ***Crummy idea alert***

    Could you make a vb script that could run through your save directory and rename anything "TXT" to "txt" ?

    Other than making a set of if/else sets in the pull file to check for both lower and uppercase variations, the above is the next thing I would look at.

    Comment


    • Atokad
      Atokad commented
      Editing a comment
      Modifying our excel file is super easy, all I have to do is add a OR condition. Unfortunately I don't think it's possible to hunt down every iteration of the excel file we have and update it. I also run into the problem if someone has a copy of the excel file that they just duplicate whenever they have another project they need to import data for and if I don't change that there will be a bunch of rouge files that won't be compatible.

      Using VB isn't too bad of an idea.... is there a way to embed it into the PC DMIS program so that whenever the program finishes running it will scan the directory and change the file names?

    • louisd
      louisd commented
      Editing a comment
      Your data integrity issue will be present regardless of what you do with VB script, *.txt, *.xls, or *.csv files. You know that, right?
      Unless your data is being controlled by a SPC system which has restricted data access, anyone can manipulate a *.txt, *.xls, or *.csv...

  • #6
    louisd,

    Data integrity is not so much a problem as compatibility. My comment was kind of oddly worded, but all I was worried about is using our current methods with the updated program. Basically modifying the Excel file is not an option, so I'm stuck with trying to get PC DMIS outputting lowercase *.txt files.

    Comment


    • #7
      Do note that technically, even though Windows stores file names exactly as written, they are matched case-insensitive, i.e. "TEST.TXT" is the same file as "Test.txt" - not recognizing that is a bug in the Excel macro, and should be corrected at the right place...
      AndersI
      SW support - Hexagon Metrology Nordic AB

      Comment

      Related Topics

      Collapse

      Working...
      X