Validate the StringEdit as a folder path


I have a string path and in that I can give a folder path , I need to validate it shold be in correct format , \

e.g D:\test\

and if user gives the correct but miss the last slash() e.g D:\test then on tab click the last should automatically populate e.g e.g D:\test\

Kindly help me in this.



So you want to verify whether the string is a valid path to an existing directory, or just to check whether the last character is “” and add it if not?


I want to check whether the string is in a valid path format like D:\folder name\ or DriveName:\foldername\foldername1\

and if the user misses to give last " \ " on tab out " \ " this should automatically populate.

like if user gives D:\test\test1 then on tab out it should have D:\test\test1\



To add backslash is pretty simple:

str path = @'c:\xyz'
if (!strEndsWith(path, @'\'))
    path += @'\';

If you want to allow just existing directories, validate the path by WinAPI::folderExists().

If you want to accept even non-accessible paths, you can verify that the path doesn’t contain invalid characters (get them by System.IO.Path::GetInvalidPathChars()) or implement your own, stronger validation.