Announcement

Collapse
No announcement yet.

Why do I have to use double backslashes in code?

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

  • Why do I have to use double backslashes in code?

    Question
    Why do I have to use double backslashes in code?

    Answer
    In windows, specifically when working with files, backslashes ("\\") are used repeatedly. Whether separating folders, filenames, or drives, there is no way to reference files without making use of backslashes, in one form or another.

    Backslashes are equally important in Setup Factory. But in order to use backslashes correctly, the difference between the single backslash ("\") and double backslash ("\\") must be understood. In Windows paths, the various parts are separated by a single backslash. This is true 100% of the time when dealing with local paths. In setup factory, paths are treated the exact same way.

    However, in setup factory, whenever a path is referenced WITHIN A STRING, a double backslash must be used. This is because in setup factory, the backslash has two purposes. The first is the same as windows, to separate the various parts of a path. The second purpose is to act as an 'escape character' from within strings, to perform various functions that cannot be accomplished within a string using regular letters and numbers, such as a line break.

    With that in mind, the following string within setup factory:
    "C:\New_Files"
    In reality translates into the following:
    c:ew_files

    This is because "\n" translates into a 'new line' command within a string. To insert the path 'c:\New_Files' into a string, the format is as follows:
    "C:\\New_Files"

    The double backslash within a string translates into a single backslash outside of a string.

    It is important to keep in mind, however, that when you are not using a backslash in script, you only need to use a single backslash. This applies to, for example, using backslashes in screen controls and session variables. You only have to use a double backslash when entering backslashes INTO SCRIPT, where the backslashes are stored in STRINGS.

    For more information please see the following topics in the Setup Factory help file:

    Windows Basics | Files, Folders and Paths | Paths
    Last edited by Adam; 04-29-2008, 12:15 PM.
Working...
X