Zac Heimgartner
Zac Heimgartner

Reputation: 19

String in directory

I am defining a string called Folder and am using it in a directory. Would I just use C:\Windows\%Folder%\... or would I call the string differently? I have never really used directories instead of namespaces in C#, and I am wondering how to do this.

Upvotes: 0

Views: 167

Answers (3)

Robert Rouhani
Robert Rouhani

Reputation: 14668

If you're wondering about concatenating folders in C# (and it seems like you are based on your comment clarifying the question), you should really be using Path.Combine instead of raw string concatenation.

Example:

using System.IO;

string Folder = "System32";
string FullPath = Path.Combine("C:/Windows", Folder);

this results in FullPath being "C:/Windows/System32", or whatever the OS uses to separate folder names.

Upvotes: 2

Ken Kin
Ken Kin

Reputation: 4683

var folder=Environment.GetEnvironmentVariable("Folder");
var path=Path.Combine(root, folder);

Upvotes: 1

SLaks
SLaks

Reputation: 887225

It sounds like your asking how to concatenate strings:

"something" + someVariable + "something else"

Upvotes: -1

Related Questions