How to select a drive?

  • Thread starter Thread starter Harry J. Smith
  • Start date Start date
H

Harry J. Smith

How do you select a drive to write a file to?
In Visual Basic it is

ChDrive("D")

where D is the new drive letter. How do you do it in C#?

I could not find it in the msdn Library or at the Visual C# .NET Support
Center.

-Harry
 
Hi Harry,
How do you select a drive to write a file to?
In Visual Basic it is

ChDrive("D")

where D is the new drive letter. How do you do it in C#?

I could not find it in the msdn Library or at the Visual C# .NET Support
Center.

-Harry

Drive list you can get by:
Directory.GetLogicalDrives

Directory.GetCurrentDirectory & Directory.SetCurrentDirectory
can be used to keep your drive.

Why do you want drive to write files instead of any directory path?

Marcin
 
Include your drive letter in your read or write operations that accept a
path.

xmlDS.WriteXml(path + "XmlDataSource.xml", XmlWriteMode.WriteSchema);

where path could be "d:\\yourPath\\yourDirectory\\subDirectory\\"

Let me know if this is what your looking for. If not please include your
code.
Phil
http://www.telysium.org
 
Marcin Grzêbski said:
Hi Harry,


Drive list you can get by:
Directory.GetLogicalDrives

Directory.GetCurrentDirectory & Directory.SetCurrentDirectory
can be used to keep your drive.

Why do you want drive to write files instead of any directory path?

Marcin

I am converting one of my programs from Visual Basic to C#, and I guess you
don't need to change drives before you write to a file be file name only,
just set the current directory.

-Harry
 
I am converting one of my programs from Visual Basic to C#, and I guess you
don't need to change drives before you write to a file be file name only,
just set the current directory.

-Harry
 
How do you select a drive to write a file to?
In case anyone wonders how the question came up, this is actually an echo of
DOS 1.0 and 1.1. Before DOS 2.0 (1983), there were no subdirectories and
instead of selecting a current directory, all you could do was select drive
A or B (first or second diskette). (No hard disks in those days either.)

Nowadays you can still select current disk, and there is (at all times) a
current directory selected on each disk. So your complete current directory
at any given time = the current disk + the selected directory on that disk.

Nowadays some files are on a network path (such as \\blah\blither) and not a
drive letter at all.
 
Back
Top