CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3
  1. #1
    Join Date
    Jan 2002
    Location
    WA
    Posts
    223

    How do I check whether the file is empty or not? + 2 more questions about file path

    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"

  2. #2
    Join Date
    Dec 2000
    Location
    Slovakia
    Posts
    1,043
    1.)
    Code:
    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:
    Code:
    string currentDir = System.AppDomain.CurrentDomain.SetupInformation.DynamicBase;
    Path to the executable:
    Code:
    string path = System.AppDomain.CurrentDomain.SetupInformation.ApplicationBase;
    3.)
    Code:
    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

  3. #3
    Join Date
    Jan 2002
    Location
    WA
    Posts
    223
    Wow thanx!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured