Space in file var string

Discussion in 'AutoCAD' started by BillZ, Apr 30, 2004.

  1. BillZ

    BillZ Guest

    R2005 Vlisp:

    After stringent training and discipline practices, I still run into filenames with spaces in them.
    Command: (setq file_name (getfiled "OPEN FILE IN Excel " "G:" "xls" 8))
    "G:\\2003\\Lists\\Floor Plates 03.XLS"

    When I try to feed this string to startapp:
    (Startapp "C:\\Program Files\\Microsoft Office\\Office10\\excel.exe" file_name)

    It opens Excel but errors out on the file name.

    Is there a simple way to get value of file_name so Excel will understand it?

    TIA

    Bill
     
    BillZ, Apr 30, 2004
    #1
  2. BillZ

    BillZ Guest

    Sorry,
    It was too simple for me.

    (strcat "\"" file_name "\"")

    Bill
     
    BillZ, Apr 30, 2004
    #2
  3. BillZ

    zeha Guest

    (Startapp "C:\\Program Files\\Microsoft Office\\Office10\\excel.exe" (strcat "\"" file_name "\""))
     
    zeha, Apr 30, 2004
    #3
  4. BillZ

    Devin Guest

    You could use dos_lib...

    (dos_shellexe "notepad.exe" "c:\\dev folder\\dev.txt")

    The above worked for me.

    Devin
     
    Devin, Apr 30, 2004
    #4
  5. BillZ

    BillZ Guest

    It worked good in notepad but when I tried this in excel it croaked.

    (dos_shellexe "excel.exe" "g:\\temp\\area clear test.txt")

    Bill
     
    BillZ, Apr 30, 2004
    #5
  6. BillZ

    wkiernan Guest

    Have a look at DOSLIB's dos_shortpath function. Though you would probably think it only applies to directory names, it also works (almost correctly) on files. Here's an example using a long file name on my PC:

    (dos_shortpath "C:\\Program Files\\Autodesk\\ObjectARX Wizards for AutoCAD 2004\\ArxWizardHelp.chm")

    returns

    "C:\\PROGRA~1\\Autodesk\\OBJECT~1\\ARXWIZ~1.CHM\\"

    Note, however, the backslash at the end of the return value;if you're trying to get the short file name for a file, not a directory, your program would have to strip that off before sending the string to something like startapp. I think this ought to work; give it a try:

    (setq long_file_name (getfiled "Select Excel file" "" "xls" 0))
    (setq short_file_name (dos_shortpath long_file_name))
    (setq short_file_name (substr short_file_name 1 (1- (strlen short_file_name))))
    (startapp "C:\\Program Files\\Microsoft Office\\Office10\\excel.exe" short_file_name)
     
    wkiernan, Apr 30, 2004
    #6
  7. BillZ

    Josh Guest

    Just to make things interesting, here's what I use based on the fact that
    workstations have Office installed inconsistently:

    (startapp
    (vl-registry-read
    "HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\App
    Paths\\Excel.exe\\" "@")
    (strcat "\"" filename"\"")
    )
     
    Josh, Apr 30, 2004
    #7
  8. BillZ

    Devin Guest

    I see your point :(
     
    Devin, Apr 30, 2004
    #8
  9. BillZ

    RichardG Guest

    (setq 1path (strcat "\042G:\\2003\\Lists\\"))

    (setq 2name "Floor Plates 03.xls\042")



    (defun c:eek:pen-floor ()

    (startapp "C:/Program Files/Microsoft Office/Office/EXCEL"(strcat 1path
    2name))

    (princ)

    )

    Bill someone from here about a month ago sent me the solution. See example
    above and note the location of "042". I split it up this way for our own
    reasons. HTH
    Richard
     
    RichardG, May 3, 2004
    #9
  10. BillZ

    BillZ Guest

    Thanks.
    I'll have to try that.

    Bill
     
    BillZ, May 4, 2004
    #10
Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.