将长文件名转换成短文件名

Posted feiyucha

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了将长文件名转换成短文件名相关的知识,希望对你有一定的参考价值。

实现效果:

  技术分享图片

知识运用:

   系统API函数GetShortPathName

  [DllImport("Kernel32.dll")]
  private static extern Int16 GetShortPathName(string IpszLongPath,StringBuilder IpszShortPath,Int16 cchBuffer);

  技术分享图片

实现代码:

        [DllImport("Kernel32.dll")]
        private static extern Int16 GetShortPathName(string IpszLongPath,StringBuilder IpszShortPath,Int16 cchBuffer);
        private void button1_Click(object sender, EventArgs e)
        {
            if (OFDlog.ShowDialog() == DialogResult.OK)
            {
                textBox1.Text = OFDlog.FileName;
                string longName = textBox1.Text;
                StringBuilder shortName = new System.Text.StringBuilder(256);
                GetShortPathName(longName,shortName,256);
                string myInfo = "长文件名:" + longName;
                myInfo += "
" + "短文件名:" + shortName;
                label2.Text = myInfo;
            }

  


以上是关于将长文件名转换成短文件名的主要内容,如果未能解决你的问题,请参考以下文章

sqlServer日期函数转换成短日期

535. Encode and Decode TinyURL - LeetCode

将长日期转换为特定的短日期格式

将长整数列表转换为整数

如何将长文本文件字段放入列表框?

如何将字节转换为mbs,gbs