-
File IO
Would anybody know how to do this:
I'm making a program that allows the user to select an initial directory so that when the program starts up again next time they use it the default folder for saving will be the one in the txt file. For example.
@"C:\Program Files\Steam\SteamApps\<username>@<emaildomain>\cou nter-strike\hl.exe";
so what this does is they browse the the hl.exe file and then it saves the Path.GetDirectoryName() of it, but what i really want is i want it to save only the path to the <username>@<emaildoamin>and no subdirectories afterward, so that the text file would look like this:
C:\Program Files\Steam\SteamApps\<username>@<emaildomain>
since the folder varies throughout users and there are no files in <username>@<emaildomain>, only folders.
so as a summary i just want the user to be able to browse to hl.exe and then have the path go backwards two folders.
-
when you put the name of the filein your program write the path
not only the name
----
if you want another solution
make a shortcut in the defaut directory ...
-
Never mind, i figured it out:
Code:
OpenFileDialog dlg= new OpenFileDialog();
dlg.Filter="Half-Life exe (*.exe)|*.exe";
dlg.InitialDirectory=@"C:\Program Files\Steam\Steamapps";
if(dlg.ShowDialog()==DialogResult.OK)
{
string path=dlg.FileName;
const string _directpath=@"C:\Documents and settings\all users\BSP Config\";
path=Path.GetDirectoryName(path);
DirectoryInfo parent=Directory.GetParent(path);
textBox3.Text = parent.FullName;
if(Directory.Exists(_directpath)==false)
{
DirectoryInfo dir= Directory.CreateDirectory(_directpath);
}
StreamWriter file=new StreamWriter(@"C:\Documents and settings\all users\BSP config\steam.cfg");
string filein=textBox3.Text;
file.WriteLine(filein+"\\");
file.Close();
}