5

In the standard Windows open file dialog (the dialog that comes up with the "File > Open" menu entry in Notepad, for example), I would like to be able to type a path containing slashes /. But only backslashes are accepted (I tried in both Windows XP and Windows 7). I can open c:\autoexec.bat, but if I try opening /autoexec.bat or c:/autoexec.bat, I get the error message

c:/autoexec.bat
The file name is not valid.

Windows accepts slashes as a path separator in some contexts, but sadly not in the open file dialog, at least by default.

Is there a magic registry setting, add-on program or other reasonable¹ method that would let me use slashes in the Windows file opening dialog? I am especially interested in Office 2007 running under Windows 7, but would prefer a solution that applies to all applications that use the standard dialog under XP and 7.

“Don't use Windows” is not an option.

  • may I ask why you want the forward slashes? you're not typing in full paths, are you? and if you are, know that with backslashes also comes the dropdown box.. no way you can type faster than making use of the dropdown completion – stijn Jun 25 '12 at 10:38
  • the only thing I can think of is that the OP is copy/pasting paths from a source using forward slashes; in that case, I would fix that source to output paths the windows style – stijn Jun 25 '12 at 10:43
  • Actually, it is a valid path separator. It was added long ago so that Windows could claim a degree of POSIX compliance. It's just that not all Windows applications support it. You can use it at the command prompt for example. See my answer for a link to a fuller explanation. You would want to use it to have scripts and applications that are more closely aligned across OS's. – Julian Knight Jun 25 '12 at 10:43
  • @stijn Yes, copy-paste was my use case. Since the applications I tend to copy-paste from use backslash for other things, whereas Windows treats the slash as an invalid character in this context, the Windows side is the only one that could be adapted. – Gilles 'SO- stop being evil' Jun 25 '12 at 11:23
  • @JulianKnight: I think it's a bit more complicated than that. Unless I'm mistaken, forward slashes are (mostly) accepted by the Win32 API, but not by the underlying kernel. For example, they don't seem to work if you use the \?\ syntax so that you can handle paths longer than 260 characters. \?\c:\windows is a valid path but \?\c:/windows doesn't seem to work. – Harry Johnston Jun 26 '12 at 00:22
  • 2
    @JulianKnight - just a FYI, MS doesnt have a degree of POSIX compliance, it is 100% POSIX compliant with the apporpriate MS addons. See http://en.wikipedia.org/wiki/Interix – Keltari Feb 13 '13 at 03:41
  • @Keltari: Yea, sure, I even used that once! Actually, I was referring to history and why MS added support for the / as a path delimiter. – Julian Knight Feb 13 '13 at 21:36
  • @HarryJohnston: you may be right, not really my area. These days MS support all sorts of odd things tucked away in the OS. Try \\server.domain@SSH\... for example for some secure WebDAV magic. – Julian Knight Feb 13 '13 at 21:39

1 Answers1

5

I'm afraid the answer is no: the dialog you see is from the standard windows API, and most programs will use it. When programming it, there are a couple of options that can be turned on/off and the one casuing your problem is OFN_FILEMUSTEXIST in the OPENFILENAME structure. I could not find anything documenting how exactly it does the check, let alone a way to modify how it does it.

The only solution I see on the Windows side is patching the dll containing the function, and making it do another check allowing forward slashes, but that requires a sheer amount of skill.

On the other side things can be fixed though, if you are a programmer of some kind: the quickest I can think of (apart from modifying the source of the strings) is creating a small command line program that takes current clipboard input, converts forward to backslashes, and puts result on the clipboard again. Put it in a batch file, assign a shortcut to it and done. Your workflow would be: copy path, hit shortcut, hit Ctrl-V in dialog box, that's only one simple extra step. I think most scripting languages can get the clipboard content on windows, and they all can regex replace so it's only a few lines of code actually.

stijn
  • 2,047