RegExp pattern for creating file safe names

By Sean Christmann | Posted September 2nd, 2007 | AIR

Different operating systems restrict specific characters from being used in file and folder names. The following code snippet will allow you to trim those special characters when creating File references in AIR.

var fileSafePattern:RegExp = new RegExp('["\\\\ *?<>|:]', 'gi');
var fileSafeName:String = myString.replace(fileSafePattern, "_");
var myFile:File = File.applicationStorageDirectory.resolvePath(fileSafeName);