unity string path="C:\\Program Files\\Program\\File.exe"; 我怎样才能得到“File.exe”
时间: 2023-09-10 21:11:09 浏览: 48
你可以使用 Unity 的内置函数 Path.GetFileName 来提取路径中的文件名。在你的例子中,你可以这样写:
```csharp
string path = "C:\\Program Files\\Program\\File.exe";
string fileName = System.IO.Path.GetFileName(path);
```
这样,变量 fileName 就会包含字符串 "File.exe"。请确保在使用之前引入 System.IO 命名空间。
相关问题
string path = Application.dataPath + "/../外部程序的相对路径";相对路径怎么改
相对路径的更改取决于您存储外部程序的位置和您想要访问它的 Unity 项目的位置。以下是一些可能的相对路径更改示例:
1. 如果您的外部程序存储在 Unity 项目的根目录中,相对路径应为:
```
string path = Application.dataPath + "/../外部程序.exe";
```
2. 如果您的外部程序存储在 Unity 项目的一个名为 `ExternalProgram` 的文件夹中,相对路径应为:
```
string path = Application.dataPath + "/../ExternalProgram/外部程序.exe";
```
3. 如果您的外部程序存储在 Unity 项目的父文件夹中,相对路径应为:
```
string path = Application.dataPath + "/../../外部程序.exe";
```
请注意,这里的 `../` 表示返回到上一级文件夹。您可以根据外部程序的实际位置,相应地更改相对路径。
unity打开外部程序 例如 D:\Program Files (x86)\DingDing\DingtalkLauncher.exe
你可以使用C#中的Process类来启动外部程序。以下是一个示例代码段来打开DingtalkLauncher.exe:
```
using System.Diagnostics;
Process.Start(@"D:\Program Files (x86)\DingDing\DingtalkLauncher.exe");
```
你可以将路径替换为你想要启动的任何外部程序的路径。如果需要传递参数,可以在第二个参数传递参数。
相关推荐
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![-](https://csdnimg.cn/download_wenku/file_type_column_c1.png)
![-](https://csdnimg.cn/download_wenku/file_type_column_c1.png)
![-](https://csdnimg.cn/download_wenku/file_type_column_c1.png)
![-](https://csdnimg.cn/download_wenku/file_type_column_c1.png)
![-](https://csdnimg.cn/download_wenku/file_type_column_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)