Search code examples
delphiassociationsfilenamesparamstr

How Can I Handle Parameters With Spaces in Delphi?


My program accepts input file names either as command line parameters or in a drag and drop operation or in Explorer by clicking on filenames with an extension that is associated with my program.

The command line and drag and drop work fine, but it is clicking on the filenames in Explorer that causes problems when the filepaths of the files clicked on have spaces in them, e.g.:

c:\temp\file one.txt
c:\my directory\filetwo.txt
c:\my directory\file three.txt

then, the ParamStr function gives me back:

ParamStr(1):  c:\temp\file
ParamStr(2):  one.txt
ParamStr(3):  c:\my
ParamStr(4):  directory\filetwo.txt
ParamStr(5):  c:\my
ParamStr(6):  directory\file
ParamStr(7):  three.txt

How can I best reconstitute these back into the three filenames that I need?


Solution

  • It might be your shell file association that does not include the pair of "".

    Like these ones for opening:

    "C:\Program Files\WinRAR\WinRAR.exe" "%1"  
    

    or with DDE message:

    [open("%1")]