Click here to Skip to main content
15,897,518 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
hi i have converted some c++ code and got below. i got the below code but i am still unable to solve few problems in this codei want it in c#



public static bool CheckFileExists (string rPathName, bool pbIsDir)
   {
       bool bReturnCode = false;
  
     
       if(pbIsDir)
          pbIsDir = false;
  
       // Check for trailing backslash.
       string PathNameString = rPathName;
       if(CPathNameHelper.HasTrailingBackslash(rPathName))
       {
           Debug.Assert(false);
       }
       else
       {
           CFileStatus FileStatus = new CFileStatus();
           // If it exists
           // Note: you can't pass a trailing backslash to CFile::GetStatus()
           if(CFile.GetStatus(PathNameString, FileStatus))
           {
               // If this is a directory
               if(FileStatus.m_attribute & CFile.directory)
               {
                   // Otherwise, it exists but it's already a directory!
                   if(pbIsDir)
                      pbIsDir = true;
                   //ASSERT( false );
                 ////  TRACE("WARNING: Expected file, but this is a directory: \"%s\"\n", (string)rPathName);
               }
               else
               {
                   // File exists
                   bReturnCode = true;
               }
           } // Otherwise, it doesn't exist.
       }
  
       return bReturnCode;
   }



[edit]Code block added - OriginalGriff[/edit]
Posted
Updated 27-Jun-11 23:10pm
v2
Comments
OriginalGriff 28-Jun-11 5:11am    
What problems? We aren't going to just do your job for you - or are you offering us your salary for the month?
Dave Kreskowiak 28-Jun-11 10:49am    
I wouldn't work for that cheap.
hakz.code 28-Jun-11 5:17am    
:)
Sergey Alexandrovich Kryukov 28-Jun-11 13:31pm    
No indication: what's the problem?
--SA

CheckFileExists is already implemented in .Net Framework
See FileInfo.Exist propety here (MSDN)[^]
 
Share this answer
 
v2
U can use File.Exists(Path);
for that u need to add the namespace System.IO

regards,
Jineesh
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900