Folder path / System name problem

I ran across a problem today that I’m not sure how to correct.

My program loads a database based on the path.

In Windows I had a user that got errors every time he loaded
my program. Well a long story short I found he had his system
user name (Windows) as S&S. This caused my program to
crash. His path looked something like C:\Users\S&s\AppData\ and so on.

The program crashed with an error of can’t find C:\Users\s

It drops off the whole folder path after the &

Is there a way to get around this if a user uses these types of characters
for a system name ?

Can you post the code that locates and loads the database file?

I just tried several ways of constructing a folderitem to a path containing an ampersand, and they all worked. Please post some code.

And if it’s in appdata, you should be using SpecialFolder.ApplicationData.Child…
(I did not test that, however)

Sorry I miss spoke, The routine crashes trying to delete files in a folder, not loading a database.
Here is some code and comments where it screws up.
The path gets lost with the shell command.

 if theFolder = nil or not theFolder.Exists() then
    return 0
  end if
  
///// The path is correct at this point:   TheFolder = C:\\Users\\S&S\\AppData\\Roaming\\TheUltimateCampgroundLogMW\\TempPictures\\
  
  Dim theShell As New Shell
  
  #If TargetWin32
    theShell.Timeout = - 1
    
    ///////// This is where the path will screw up in the next step.
    ///////// While step debugging when it hits the shell execute it drops part of the path as shown. 
    //////// The ERROR is as shown:
    ////////                        Could Not Find C:\\Users\\S
    ////////                        The system cannot find the path specified.
    
    theShell.Execute "DEL /f/s/q " + theFolder.ShellPath + "\\*.*"           //<<<<< It ERRORS here
  #Else
    theShell.Execute "rm -f " + theFolder.ShellPath + "/*.*"
  #EndIf

The path is still correct at this point: TheFolder = C:\Users\S&S\AppData\Roaming\TheUltimateCampgroundLogMW\TempPictures\

You need to Quote your shellpath. This C:\Users\S&S\AppData\Roaming\TheUltimateCampgroundLogMW\TempPictures\. needs to be “C:\Users\S&S\AppData\Roaming\TheUltimateCampgroundLogMW\TempPictures\.”. In Windows any non-standard characters require the path to be quoted - just like having a space in the path.

theShell.Execute “DEL /f/s/q “””" + theFolder.ShellPath + “\.”""

Should fix the problem but I think you need to move the switches to the end also

theShell.Execute “DEL “””" + theFolder.ShellPath + “\.”" /f/s/q"

May work better.

HTH

Wayne

Thanks Wayne but both lines give a syntax error

I hate double quoting.

Try this one

theShell.Execute “DEL “”” + theFolder.ShellPath + “\.”" /f/s/q"

Wayne… Your the man… It worked… Thank you very much.

Happy to have helped.