How to convert a file name from empty to short file name (DOS style) in Adobe AIR?

How to convert file name with path to short file name (DOS style) in Adobe AIR?

For example, convert the following path

"C:\Program Files\Common Files\Adobe AIR\Versions\1.0\Resources\Adobe AIR Updater.exe" 

to

 "C:\PROGRA~1\COMMON~1\ADOBEA~1\VERSIONS\1.0\RESOUR~1\ADOBEA~1.EXE" 

Is there any algorithm?

+4
source share
2 answers

Assuming your text part is a string variable, you can split it using "\" as a delimiter. You will then have an array that you can use to check if each block is longer than 8 characters. When you loop the array, you can slice the last characters of each long block and put ~ 1. Since you are in a loop, you can gradually add all these changes to the temporary variable, which will ultimately give the final edited result.

The only part that is a bit complicated is to pay attention to the .exe part at the end.

So, if I were you, I would start reading String.split (), String.substring (), for loop, arrays

+2
source

Here is my handy method that does this below:

 public static string GetShortPathName(string path) { string[] arrPath = path.Split(System.IO.Path.DirectorySeparatorChar); path = arrPath[0]; // drive // skip first, ( drive ) and last program name for (int i = 1; i < arrPath.Length - 1; i++) { string dosDirName = arrPath[i]; if (dosDirName.Count() > 8) { dosDirName = dosDirName.Substring(0, 6) + "~1"; } path += System.IO.Path.DirectorySeparatorChar + dosDirName; } // include program name if any path += System.IO.Path.DirectorySeparatorChar + arrPath[arrPath.Length - 1]; return path; } 
+1
source

Source: https://habr.com/ru/post/1301093/


All Articles