如何在 Adob​​e AIR 中将带有路径的文件名转换为短文件名(DOS 样式)?

发布于 2024-08-21 16:10:15 字数 299 浏览 4 评论 0原文

如何在 Adob​​e AIR 中将带有路径的文件名转换为短文件名(DOS 样式)?

例如将下一个路径转换

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

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

有没有算法?

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

For example convert next 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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

給妳壹絲溫柔 2024-08-28 16:10:15

假设您的文本部分是字符串变量,您可以使用“\”作为分隔符来分割它。然后,您将拥有一个数组,可用于检查每个块的长度是否超过 8 个字符。在循环数组时,您可以砍掉每个长块的最后一个字符并放入 ~1。由于您处于循环中,因此您可以逐步将所有这些更改添加到临时变量中,这将在最后为您提供最终的编辑结果。

唯一有点棘手的部分是注意最后的 .exe 部分。

所以,如果我是你,我会开始阅读 String.split()、String.substring()、for 循环、数组

Assuming your text portion is a string variable, you can split it by using "\" as delimiter. Then, you will have an array which you can use to check if each block is longer than 8 characters. While looping the array you can chop the last characters of each long block and put ~1. Since you're in the loop, you can progressively add to a temporary variable all these changes which will give you the final edited result at the end.

The only part that's a bit tricky is to pay attention to .exe part at the end.

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

2024-08-28 16:10:15

这是我的方便方法,如下所示:

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;
 }

Here's 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;
 }
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文