5

I noticed that the semicolon ; is a valid character for Windows (NTFS) file and directory names.

The semicolon is, however, used as element delimiter for the PATH environment variable.

Say I have a folder called C:\"main() {printf('%d', 42);}" (heh, nice, also contains a percent sign) -- how could I add this folder to the system PATH?

6
  • Avoid using semicolons in folder names, then you won't have a problem!
    – Lee Taylor
    Apr 19, 2013 at 10:08
  • Well, you should be in control of folders that you're adding to PATH. It seems odd that you'd have folders with semicolons, etc. in them.
    – Lee Taylor
    Apr 19, 2013 at 10:22
  • 1
    As has been said, you really should avoid using such characters in paths--They will trip up many unsuspecting programs which you do not have to source code to rewrite to handle them. What I would suggest, if you must have this kind of path for a specific program, write a batch file that sets the path needed by this one program, executes that one program, then restores the path to normal when done. Then you can put that batch file on the path somewhere to call when you need to run that program, without clobbering the path for all other programs.
    – C. M.
    Jul 19, 2014 at 23:46
  • @C.M. While your advice is valid, I would also say that a piece of software written for a particular system that doesn't handle all paths the OS and file system allow is broken. Such a thing can even become a security threat. Linux software can also be guilty of this to a lesser extent mainly due to the newline character, but Windows, NTFS, and the software ecosystem around it is just a mess as it stands. Weird restrictions from the DOS era, different key parts of the OS not dealing with certain allowed characters, patchy unicode support with legacy code pages used in many core utilities…
    – Taederias
    Jan 17, 2022 at 1:43
  • I would not say such software is "broken", just--at worst--poorly written. The writers of the U.S. Constitution, for example, did not imagine or account for the invention of computers. But if you try to say it is "broken", or even "poorly written"... expect strong opposition. Another example of "bad characters" are the "/" and "\\" chars. Almost any OS actually allows them in file names (although you will likely need to use low-level system calls to do so); It is primarily the standard libraries that give them special meaning, not the filesystem itself.
    – C. M.
    Jan 18, 2022 at 7:50

2 Answers 2

7

Using double quotes works for me:

SET PATH=%PATH%;"C:\main() {printf('%d', 42);}"
2

Get the folder short name via DIR /X, then add that short name to the PATH. It seems that PATH is OK with % sign though

3
  • Bah. Short-Names. But, yes, indeed, this appears to be a possible solution iff one is able to determine the short name.
    – Martin
    Apr 19, 2013 at 10:06
  • 1
    So you mean how would you add if the user disabled the short name generation? support.microsoft.com/kb/121007
    – Martheen
    Apr 19, 2013 at 10:17
  • 1
    Either by creating a junction point or symbolic link with simple name and adding it to the PATH then.
    – Martheen
    Apr 19, 2013 at 10:22

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .