Thread: File IO

  1. #1
    Registered User
    Join Date
    Apr 2004
    Posts
    26

    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.

  2. #2
    /*enjoy*/
    Join Date
    Apr 2004
    Posts
    159
    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 ...

  3. #3
    Registered User
    Join Date
    Apr 2004
    Posts
    26
    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();
    			}

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. A development process
    By Noir in forum C Programming
    Replies: 37
    Last Post: 07-10-2011, 10:39 PM
  2. Formatting the contents of a text file
    By dagorsul in forum C++ Programming
    Replies: 2
    Last Post: 04-29-2008, 12:36 PM
  3. Can we have vector of vector?
    By ketu1 in forum C++ Programming
    Replies: 24
    Last Post: 01-03-2008, 05:02 AM
  4. Batch file programming
    By year2038bug in forum Tech Board
    Replies: 10
    Last Post: 09-05-2005, 03:30 PM
  5. File IO with .Net SDK and platform SDK
    By AtomRiot in forum Windows Programming
    Replies: 5
    Last Post: 12-14-2004, 10:18 AM