项目文件的文件路径? [英] File path for project files?

查看:20
本文介绍了项目文件的文件路径?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 C# 开发媒体播放器,但是当我想进行测试时遇到了问题.

I am working on a media player in C# but when I want to make my test I have a problem.

我必须使用以下路径创建一首新的对象歌曲:

I have to create a new object song with the following path:

@"C:UsersJesus AntonioDesktopJukeboxV2.0JukeboxV2.0Datosich will.mp3"

它可以工作,但是当我更换计算机时,我必须重写整个路径,我的项目叫 JukeboxV2.0

It works but when I change the computer I have to rewrite the entire path, My project is called JukeboxV2.0

在java中我记得你可以写路径例如

In java I remember you can just write the path for example

@"JukeboxV2.0JukeboxV2.0Datosich will.mp3"

这会节省很多时间,因为我可以将我的项目带到不同的计算机上并且它可以工作,但是在这里我不知道如何做到这一点,有人知道吗?

This will save a lot of time because I can take my project to different computers and it works, but here I don't known how to do that, anyone know?

推荐答案

您可以执行类似操作以获取应用程序环境文件夹中的路径Dataich_will.mp3".

You would do something like this to get the path "Dataich_will.mp3" inside your application environments folder.

string fileName = "ich_will.mp3";
string path = Path.Combine(Environment.CurrentDirectory, @"Data", fileName);

就我而言,它将返回以下内容:

In my case it would return the following:

C:MyProjectsMusicMusicAppinDebugDataich_will.mp3

我在示例中使用了 Path.CombineEnvironment.CurrentDirectory.这些非常有用,允许您根据应用程序的当前位置构建路径.Path.Combine 组合两个或多个字符串以创建位置,Environment.CurrentDirectory 为您提供应用程序的工作目录.

I use Path.Combine and Environment.CurrentDirectory in my example. These are very useful and allows you to build a path based on the current location of your application. Path.Combine combines two or more strings to create a location, and Environment.CurrentDirectory provides you with the working directory of your application.

工作目录不一定与您的 executable 所在的路径相同,但在大多数情况下应该是,除非另有说明.

The working directory is not necessarily the same path as where your executable is located, but in most cases it should be, unless specified otherwise.

这篇关于项目文件的文件路径?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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