Thank you for being almost mind readers and asking questions about what I failed to include in my posts. Thank you all.
Bart, I have tested your code now and had to adjust it a bit as
some ()- characters were missing.
if (Length(LE_ProgPath.Text) > 1) and (LE_ProgPath.Text[Length(LE_ProgPath.Text)] = ':') then
LE_ProgPath.Text := LE_ProgPath.Text + '\NC_clean.ini'
else
LE_ProgPath.Text:=IncludeTrailingPathDelimiter(LE_ProgPath.Text)+'NC_clean.ini';
This code works as I want/expect.
What exactly do yo mean by "I want to check that it is a real path"?
- A path that actually exists? --> See: DirectoryExists() function
- A string that Windows would accept as being a path? --> a bit tricky
The option: A path that actually exists? --> See: DirectoryExists() function
I will read up on DirectoryExists
I've done some testing and on my Windows 10 system C:\ is read-only in the CMD window so my program probably can't put the NC_clean.ini file there even after checking that it's a real path.
Typing C: in the cmd window just takes you directly to the drive and folder you were in when you left the drive or opened the CMD window, but for example if I want to see the files in drive C and the root I type
DIR C:\ and everything in the root is listed on the screen.
If I want to look in a file in the C drive root, when I am not in that folder, for example:
type C:\App.txt this will cause the contents of the file to be listed on the screen.
The idea is thus that:
A; Check that the text the user entered as a path is really a path that exists on the system and discard unknown commands/nonsense text from the user.
B; Once the user wants to save their settings in the program to the NC_clean.ini file, the location should be writable.