User Tools

Site Tools


Filenames containing spaces

by Richard Russell, May 2006

You don't need to take any special precautions when using OPENIN, OPENOUT or OPENUP to access files whose names (or paths) contain one or more spaces:

        filename$ = "Filename containing spaces"
        file% = OPENIN(filename$)
        file% = OPENUP(filename$)
        file% = OPENOUT(filename$)

However if you need to access such a file with a star command (or with OSCLI) then you should enclose the filename in quotes:

        *DISPLAY "Filename containing spaces"
        *COPY "Source file" "Destination file"

When using OSCLI (typically because the filename is a variable rather than a constant) then you must add quotes around the filename(s) in the command string. There are two main ways of doing this, firstly by using the CHR$34 character:

        filename$ = "Filename containing spaces"
        OSCLI "DISPLAY "+CHR$34+filename$+CHR$34
        srcfile$ = "Source file"
        dstfile$ = "Destination file"
        OSCLI "COPY "+CHR$34+srcfile$+CHR$34+" "+CHR$34+dstfile$+CHR$34

and secondly by using the ““ sequence:

        filename$ = "Filename containing spaces"
        OSCLI "DISPLAY """+filename$+""""
        srcfile$ = "Source file"
        dstfile$ = "Destination file"
        OSCLI "COPY """+srcfile$+""" """+dstfile$+""""

Forgetting to include the quotes can result in confusing (at first sight) symptoms. Some people find that the method using CHR$34 tends to produce clearer code and is easier to debug. Others prefer the compactness of the ”” method. Use whichever you feel happier with.

This website uses cookies for visitor traffic analysis. By using the website, you agree with storing the cookies on your computer.More information
filenames_20containing_20spaces.txt · Last modified: 2018/04/17 16:07 by tbest3112