Click to See Complete Forum and Search --> : How do I check whether the file is empty or not? + 2 more questions about file path


Silver Ghost
November 27th, 2002, 11:47 AM
1. Subj

2. How can I get a full path to a current directory?

3. How can I place some string in this path string in _HERE_:
"c:/some foler/more folders/myFileName_HERE_.ext"

MartinL
November 27th, 2002, 12:12 PM
1.)

public bool SomeClass::IsFileEmpty(string fileName)
{
bool _ret = false;
try
{
FileStream fs = File.OpenRead(strFileName);
_ret = (fs.Length == 0);
}
catch (Exception e)
{
throw new Exception("IsFileEmpty method exception", e);
}
return _ret;
}


2.)
Full path to the current directory or full path to the directory where your executable is stored???

Current dir:

string currentDir = System.AppDomain.CurrentDomain.SetupInformation.DynamicBase;


Path to the executable:

string path = System.AppDomain.CurrentDomain.SetupInformation.ApplicationBase;


3.)

public string SomeClass::AppendFileName(string path, string appendText)
{
// you have to check if the path or appendText are valid (not null) and if the path is really path to the file before this code...
string _ret = path.Substring(0, path.LastIndexOf('.')) +
appendText + path.Substring(path.LastIndexOf('.'));
return _ret;
}


Martin

Silver Ghost
November 27th, 2002, 10:51 PM
Wow thanx!