create folder not creating folder

I have this piece of code…

every thing create just fine… except for the last create folder… Unless I specify a name for it, it doesn’t get created
It seems that adding the “a” to it stops it from being created.
I want my backups to be date based so I could have many backups
Is there a workaround?

dim f as folderitem dim d as date d=new date dim a as string a=str(d.AbbreviatedDate)+" at time "+str(d.ShortTime) a=a.Replace(",","-") f=SpecialFolder.Desktop.child("MyApp") if f.Exists then else f.CreateAsFolder end if f=SpecialFolder.Desktop.child("MyApp").child("Mass Backups") if f.Exists then else f.CreateAsFolder end if f=SpecialFolder.Desktop.child("MyApp").child("Mass Backups").child("Mass Backup from "+a) if f.Exists then else f.CreateAsFolder end if

it’s possible the data time includes characters that are not legal in a file name so the folder cant be created

depending on the OS there’s one or more characters that will do this

I can get it save if I use
a=str(d.LongDate)

but a=“2015-08-15 17:52:54” doesn’t work…

what are the characters invalidating the foldername? It’s not colons as I tried to replaceAll with “|” (which also didn’t work)

on OS X the : is a reserved character so youre probably actually getting an error and not checking last error code

https://support.apple.com/en-us/HT202808
https://msdn.microsoft.com/en-ca/library/windows/desktop/aa365247(v=vs.85).aspx

A reasonable summary across platforms
https://kb.acronis.com/content/39790

Generally I replace with _ as its safe everywhere

Norman already talks abou colon on OS X; same anweer for WIndows for both : and | (probably).

If you do not found on the internet the list of invalid characters in file / folder names for the different OS, you can try to create a folder on your running OS and check a character at a time to know what the OS will told.

On OS X it will tell you it cannot set the file name; on WIndows, a list of weird (illegal) characters is returned.

At last, be aware that some name will enter in conflict with the Xojo IDE. As an example, giving an image file (probably text or anything else too) the name Linux and importing it into the IDE will change the name to Linux1.

At last, a file name that start with a number (one or many numbers) and imported in the IDE will see these numbers cleared from the name.

Checkings have to be done to know if this is still the case with the current Xojo version.

Oh ! Do not create items that have a leading dot character (.): the OS will treat them as invisible files ;-:slight_smile:

Norman: nice links.

A couple of additional suggestions to your code…

f=SpecialFolder.Desktop.child("MyApp") if not f.Exists then f.CreateAsFolder end if //1 less line, easier to read f=SpecialFolder.Desktop.child("MyApp").child("Mass Backups") //no need to completely recreate f each time f=f.child("Mass Backups") if not f.Exists ... etc

Commas are ok, at least on Windows, but colons and | are not. A “|” is interpreted by the OS as a redirecting pipe and can’t be part of a file or folder name. Replacing the colons with “_” should work, as previously noted.

May I simply suggest this (portion of the code posted by the OP), per Norman’s suggestion of replacing by underscore :

dim a as string a=str(d.AbbreviatedDate)+" at time "+str(d.ShortTime) a=a.ReplaceAll(",","-") // Illegal characters Windows / ? < > \\ : * | " a=a.ReplaceAll("/","_") a=a.ReplaceAll("?","_") a=a.ReplaceAll("<","_") a=a.ReplaceAll(">","_") a=a.ReplaceAll("\","_") a=a.ReplaceAll(":","_") a=a.ReplaceAll("*","_") a=a.ReplaceAll("|","_") a=a.ReplaceAll(chr(34),"_")

That way you are certain.

Alternatively, you can also use
a=a.ReplaceAll(",","-")
a = encodeURLComponent(a)

Which will replace the illegal characters and accented letters by something like
"/ ? < > \ : * | " " replaced by %2F %3F %3C %3E %5C %3A %2A %7C %22 and space by %20.

It’s OK for a few ones. I prefer underscore.

Yes, I like it, but I promptly forgot it… :frowning:

Less than two month ago… sad to be old.