命令行参数和短文件名 [英] Command line argument and short file names

查看:93
本文介绍了命令行参数和短文件名的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述


我有一个C#应用程序,它以自定义格式创建文件.我已将此应用程序的exe链接到这些自定义文件的文件类型.因此,当某人双击该文件时,应用程序将打开指定的文件.

除通过命令行参数传递给此应用程序的文件名被缩短外,此方法运行良好.双击文件时,我正在使用Environment.GetCommandLineArgs()函数来获取参数.通过此功能接收的文件名被缩短,并且为8点3格式.我想获取长文件名.如何在应用程序中获取长文件名?

任何建议或帮助都非常感谢!

谢谢
Kalyani

Hi
I have a C# application which creates files in custom format. I have the exe of this application linked to the file type of these custom files. So when some one double clicks the file the application opens the specified file.

This is working well, except the file name passed via command line argument to this application is shortened. I am using Environment.GetCommandLineArgs() function to get the argument when the file is double clicked. The file name received via this function is shortened and is in the 8 dot 3 format. I would like to get the long file name. What should I do to get the long file name in my application?

Any suggestion or help is appreciated very much!

Thanks
Kalyani

推荐答案

using System;
using System.Runtime.InteropServices;
using System.Text;

public class _Main
{
    [DllImport("kernel32.dll", CharSet = CharSet.Auto)]
    public static extern int GetLongPathName(
        [MarshalAs(UnmanagedType.LPTStr)]
        string path,
        [MarshalAs(UnmanagedType.LPTStr)]
        StringBuilder longPath,
        int longPathLength
        );
        
    public static void Main()
    {
        StringBuilder longPath = new StringBuilder(255);
        GetLongPathName(@"D:\MYTEMP~1\RESOUR~1\sql.txt", longPath, longPath.Capacity);
        Console.WriteLine(longPath.ToString());
    }
}


这篇关于命令行参数和短文件名的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆