Adding Important sentence to FileCreateDir documentation Topic is solved

Share your ideas as to how the documentation can be improved.
User avatar
Avtem
Posts: 43
Joined: 01 Jun 2021, 02:20

Adding Important sentence to FileCreateDir documentation

24 Aug 2022, 13:14

Hello. So today i spent about 3 hours trying to understand why AHK doesn't create directories with FileCreateDir command. Only by accident i found out why AHK FileCreateDir command didn't work. Turns out it only partially supports forward slashes (by accident you can assume that they work). But the problem - AHK doesn't support them.
i think there are a lot of people that prefer forward slashes over back slashes (especially when you have to type them 2 times in regEx, source code, etc.) and my note could really help them out.

So, i really would like to add this sentence to the FileCreateDir command in description of the 1st parameter:
Name of the directory to create, which is assumed to be in %A_WorkingDir% if an absolute path isn't specified.
Note: path must contain only backslashes (\)
Last edited by Avtem on 24 Aug 2022, 23:55, edited 1 time in total.
gregster
Posts: 9103
Joined: 30 Sep 2013, 06:48

Re: Adding Important sentence to FileCreateDir documentation

24 Aug 2022, 14:13

Avtem wrote:Note: path must contain only forward slashes (/)
Isn't that suggested sentence the opposite of what you have discovered?!
Avtem wrote:
24 Aug 2022, 13:20
So, the lesson is: when working with paths, use backslashes only

Code: Select all

FileCreateDir c:/111/222/333     ; FAILS - won't create anything
FileCreateDir c:\111\222\333     ; SUCCEEDS - works as expected. All folders are created
User avatar
Ragnar
Posts: 630
Joined: 30 Sep 2013, 15:25

Re: Adding Important sentence to FileCreateDir documentation

24 Aug 2022, 14:25

Wow, I didn't realize until today that FileCreateDir only supports backslash.

@lexikos this might be worth considering to support forward slash for FileCreateDir (and DirCreate). All other path-related commands, functions etc. seem to support both slash types.
iseahound
Posts: 1467
Joined: 13 Aug 2016, 21:04
Contact:

Re: Adding Important sentence to FileCreateDir documentation

24 Aug 2022, 19:53

I feel like I ran into this bug in the past... But generally with very few exceptions, such as the Open File dialog, a forward slash is a backslash.

UNC paths are another exception: Run in cmd with and without \\?\

Code: Select all

start "" "//?/C:/Windows/notepad.exe"
User avatar
Avtem
Posts: 43
Joined: 01 Jun 2021, 02:20

Re: Adding Important sentence to FileCreateDir documentation

24 Aug 2022, 23:55

@gregster
Oh, jeez! You are right, how did i mess that up?) Fixing it now!
User avatar
Avtem
Posts: 43
Joined: 01 Jun 2021, 02:20

Re: Adding Important sentence to FileCreateDir documentation

27 Aug 2022, 23:20

@Ragnar
Thank you as well)
teadrinker
Posts: 4399
Joined: 29 Mar 2015, 09:41
Contact:

Re: Adding Important sentence to FileCreateDir documentation

28 Aug 2022, 08:39

Actually forward slashes work in this command if all parent directories already exist:

Code: Select all

FileCreateDir %A_Desktop%/NewDir
FileCreateDir %A_Desktop%/NewDir/NewDir
lexikos
Posts: 9688
Joined: 30 Sep 2013, 04:07
Contact:

Re: Adding Important sentence to FileCreateDir documentation

01 Sep 2022, 21:13

Ragnar wrote:
24 Aug 2022, 14:25
All other path-related commands, functions etc. seem to support both slash types.
As far as I can tell, this is all of the code in AutoHotkey which explicitly supports '/' as a path separator:

Code: Select all

if (*cp == '\\' || *cp == '/')
:lol:

That's in the file loop code, and was probably added when I added long path support.

None of the other functions explicitly support forward-slash. If it works, it is only because the system handles it. Some functions use GetFullPathName to normalize the path, and that takes care of slashes. Most functions just pass the path to whatever system function.

SplitPath explicitly supports URLs like file://whatever, so supports '/' for those; but still doesn't support it for other file paths.

I don't currently care about this enough to do a code review and fix these issues myself. Not even the shell (in Windows 11) supports forward slash.
User avatar
Ragnar
Posts: 630
Joined: 30 Sep 2013, 15:25

Re: Adding Important sentence to FileCreateDir documentation

02 Sep 2022, 11:33

I have created PR #300 which supports the use of forward slashes in FileCreateDir. Strictly speaking, it is a breaking change for coders who rely on the current behavior, however, their number should be very small. Moreover, I strongly doubt that this command is used very often.
User avatar
Avtem
Posts: 43
Joined: 01 Jun 2021, 02:20

Re: Adding Important sentence to FileCreateDir documentation

02 Sep 2022, 11:36

@Ragnar Since the topic is about slashes, i could also add that some WinAPI functions support only backslashes as well. For example
keyExists := !DllCall("RegOpenKeyExW", "PTR", 0x80000001, "wstr", keyPathWithoutRoot, "UINT", 0, "UINT", 131097, "PTR*", hKey)
User avatar
Ragnar
Posts: 630
Joined: 30 Sep 2013, 15:25

Re: Adding Important sentence to FileCreateDir documentation

02 Sep 2022, 13:29

I have added some notes in SplitPath and DllCall regarding slash usage via PR #570.
lexikos
Posts: 9688
Joined: 30 Sep 2013, 04:07
Contact:

Re: Adding Important sentence to FileCreateDir documentation

02 Sep 2022, 17:59

Ragnar wrote:
02 Sep 2022, 11:33
Strictly speaking, it is a breaking change for coders who rely on the current behavior,
I'm not sure that fixing broken, undocumented behaviour - that couldn't be construed as useful - would be counted as a breaking change. To rely on it, one would have to:
  • have some requirement that if the parent directory does not exist, the command must abort;
  • observe that using '/' prevents the preceding directory from being created; and
  • decide to use '/' for that purpose, relying on the command to avoid creating parent directories despite that behaviour directly contradicting the documentation:
This command will also create all parent directories given in DirName if they do not already exist.
User avatar
joedf
Posts: 8994
Joined: 29 Sep 2013, 17:08
Location: Canada
Contact:

Re: Adding Important sentence to FileCreateDir documentation

03 Sep 2022, 10:51

Forward slashes work for me in Windows 10 / shell, both in cmd and file explorer.
Image Image Image Image Image
Windows 10 x64 Professional, Intel i5-8500, NVIDIA GTX 1060 6GB, 2x16GB Kingston FURY Beast - DDR4 3200 MHz | [About Me] | [About the AHK Foundation] | [Courses on AutoHotkey]
[ASPDM - StdLib Distribution] | [Qonsole - Quake-like console emulator] | [LibCon - Autohotkey Console Library]
lexikos
Posts: 9688
Joined: 30 Sep 2013, 04:07
Contact:

Re: Adding Important sentence to FileCreateDir documentation

04 Sep 2022, 03:38

Forward vs. back slash is generally only an issue when the program or API interprets the path for some purpose, and isn't merely passing it (directly or indirectly) to a Win32 function.

I had the impression forward slashes didn't work with shell-related UI, because I tested it, and it didn't work. It doesn't work consistently, even on Windows 11. For instance, if I type or copy C:/ into the file name field of a standard open/save file dialog and press Enter, it tells me the filename is invalid, whereas C:\ navigates there. This is true for Notepad (the new Windows 11 version), Wordpad, Visual Studio 2022, Firefox, SciTE, and probably most others. Oddly, it works with Notepad++.

By "shell" I mostly meant File Explorer and "shell32", which always seemed to have more stringent (unnecessary) restrictions on filenames than the underlying Win32 functions; but there are a couple of easy examples where forward slashes don't work with cmd.exe:
  • Tab completion. For example, type C:\ and press Tab, then compare to C:/ while in some other directory.
  • dir C:/Windows -> Parameter format not correct - "windows".
safetycar
Posts: 435
Joined: 12 Aug 2017, 04:27

Re: Adding Important sentence to FileCreateDir documentation

04 Sep 2022, 04:26

lexikos wrote:
04 Sep 2022, 03:38
dir C:/Windows -> Parameter format not correct - "windows".
If it's worth the mention, I tried with quotes arround the path and it worked (W10).
TAC109
Posts: 1128
Joined: 02 Oct 2013, 19:41
Location: New Zealand

Re: Adding Important sentence to FileCreateDir documentation

04 Sep 2022, 04:57

in Windows and DOS, \ is the directory separator, and / introduces a switch or parameter to a command. In my opinion, the fact that Windows makes allowances for Unix and html users and sometimes accepts / as a directory separator does not need to be documented in AutoHotkey. Users should be encouraged to use the standard \ directory separator, and the AutoHotkey documentation should reflect this.

Cheers
My scripts:-
XRef - Produces Cross Reference lists for scripts
ReClip - A Text Reformatting and Clip Management utility
ScriptGuard - Protects Compiled Scripts from Decompilation
I also maintain Ahk2Exe
User avatar
joedf
Posts: 8994
Joined: 29 Sep 2013, 17:08
Location: Canada
Contact:

Re: Adding Important sentence to FileCreateDir documentation

04 Sep 2022, 11:02

@lexikos I see, understood. I haven't tried windows 11 yet. :think:
Image Image Image Image Image
Windows 10 x64 Professional, Intel i5-8500, NVIDIA GTX 1060 6GB, 2x16GB Kingston FURY Beast - DDR4 3200 MHz | [About Me] | [About the AHK Foundation] | [Courses on AutoHotkey]
[ASPDM - StdLib Distribution] | [Qonsole - Quake-like console emulator] | [LibCon - Autohotkey Console Library]
User avatar
lmstearn
Posts: 698
Joined: 11 Aug 2016, 02:32
Contact:

Re: Adding Important sentence to FileCreateDir documentation

11 Sep 2022, 12:54

It was once possible back in the day to change backslash to forward slash and forward slash to dash in config.sys, and forward slash can still be used today with cmd. Type C:/Program Files/AutoHotkey in explorer (W10) and it bounces the slashes around to back!
Another issue is when \ and / are mixed in pathnames- which no doubt would bring in quite a bit of overhead and bugs to AHK and existing scripts. Edit: well possibly in existing scripts, like in odd situations where #EscapeChar.htm has been used to redefine the forward slash as an escape char.
:arrow: itros "ylbbub eht tuO kaerB" a ni kcuts m'I pleH

Return to “Suggestions on Documentation Improvements”

Who is online

Users browsing this forum: No registered users and 9 guests