我想将此代码转换为C# [英] i want this code to be converted in c#

查看:69
本文介绍了我想将此代码转换为C#的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经转换了一些C ++代码并得到了下面的内容.我得到了以下代码,但是我仍然无法解决此编码中的一些问题,我希望在c#中使用它



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]已添加代码块-OriginalGriff [/edit]




[edit]Code block added - OriginalGriff[/edit]

推荐答案

CheckFileExists已在.Net Framework中实现
请参见FileInfo.Exist属性.此处(MSDN) [ ^ ]
CheckFileExists is already implemented in .Net Framework
See FileInfo.Exist propety here (MSDN)[^]


U可以使用File.Exists(Path);
为此,您需要添加名称空间System.IO

问候,
吉尼斯(Jineesh)
U can use File.Exists(Path);
for that u need to add the namespace System.IO

regards,
Jineesh


这篇关于我想将此代码转换为C#的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆