判断文件是否存在的另一种方法 _access 和 _waccess

函数原型:

int _access( const char *path, int mode );

int _waccess( const wchar_t *path, int mode );

示例代码:

[cpp] view plain copy

  1. #include <io.h>
  2. #include <stdio.h>
  3. #include <stdlib.h>
  4. int _tmain(int argc, _TCHAR* argv[])
  5. {
  6. //如果文件具有指定的访问权限,则函数返回0
  7. //如果文件不存在或者不能访问指定的权限,则返回-1
  8. //备注
  9. //当path为文件时,_access函数判断文件是否存在,并判断文件是否可以用mode值指定的模式进行访问
  10. //当path为目录时,_access只判断指定的目录是否存在,在WindowsNT和Windows2000中,所有目录都有读写权限
  11. //mode值
  12. //00    只检查文件是否存在
  13. //02    写权限
  14. //04    读权限
  15. //06    读写权限
  16. //_waccess是_access的宽字符版本
  17. if (_access("demo.txt", 0) != -1)
  18. {
  19. printf("the demo.txt exist\n");
  20. //判断文件是否可写,假定文件是只读的
  21. if (_access("demo.txt", 2) == -1)
  22. {
  23. printf("the demo.txt does not have write permission\n");
  24. }
  25. else
  26. {
  27. printf("the demo.txt have write permission\n");
  28. }
  29. }
  30. else
  31. {
  32. printf("the demo.txt does not exist\n");
  33. }
  34. system("pause");
  35. return 0;
  36. }

https://blog.csdn.net/hellokandy/article/details/78471006

原文地址:https://www.cnblogs.com/findumars/p/8732315.html

时间: 2024-08-28 04:35:00

判断文件是否存在的另一种方法 _access 和 _waccess的相关文章

[C#.Net]判断文件是否被占用的两种方法

第一种方法:API using System.IO; using System.Runtime.InteropServices; [DllImport("kernel32.dll")] public static extern IntPtr _lopen(string lpPathName,int iReadWrite); [DllImport("kernel32.dll")] public static extern bool CloseHandle(IntPtr

spring在xml文件中配置bean的三种方法

一.最常见,也是缺省,是调用spring的缺省工厂类 spring缺省工厂类:org.springframework.beans.factory.support.DefaultListableBeanFactory使用其静态方法preInstantiateSingletons() 配置文件中最普通最基本的定义一个普通bean<bean id="DvdTypeDAOBean" class="com.machome.dvd.impl.DvdTypeDAO" >

判断是否从微信进入的两种方法:

JS方法: $(function(){ is_weixn(); }) function is_weixn(){ var ua = navigator.userAgent.toLowerCase(); if(ua.match(/MicroMessenger/i)=="micromessenger") { return true; } else { alert('请在微信中打开!'); window.location.href="<?php echo site_url('w

Java 判断字符串是否为空的四种方法、优缺点与注意事项

以下是Java 判断字符串是否为空的四种方法: 方法一: 最多人使用的一个方法, 直观, 方便, 但效率很低: if(s == null ||"".equals(s));方法二: 比较字符串长度, 效率高, 是我知道的最好一个方法: if(s == null || s.length() <= 0);方法三: JavaSE 6.0 才开始提供的方法, 效率和方法二几乎相等, 但出于兼容性考虑, 推荐使用方法二. if(s == null || s.isEmpty()); 方法四:

iOS 获取文件的目录路径的几种方法 [转]

iOS 获取文件的目录路径的几种方法 2 years ago davidzhang iphone沙箱模型的有四个文件夹,分别是什么,永久数据存储一般放在什么位置,得到模拟器的路径的简单方式是什么. documents,tmp,app,Library. (NSHomeDirectory())手动保存的文件在documents文件里 Nsuserdefaults保存的文件在tmp文件夹里 1.Documents 目录:您应该将所有的应用程序数据文件写入到这个目录下.这个目录用于存储用户数据或其它应该

判断js中的数据类型的几种方法

判断js中的数据类型有一下几种方法:typeof.instanceof. constructor. prototype. $.type()/jquery.type(),接下来主要比较一下这几种方法的异同. 先举几个例子: 1 var a = "iamstring."; 2 var b = 222; 3 var c= [1,2,3]; 4 var d = new Date(); 5 var e = function(){alert(111);}; 6 var f = function()

转:判断js中的数据类型的几种方法

判断js中的数据类型有一下几种方法:typeof.instanceof. constructor. prototype. $.type()/jquery.type(),接下来主要比较一下这几种方法的异同. 先举几个例子: var a = "iamstring."; var b = 222; var c= [1,2,3]; var d = new Date(); var e = function(){alert(111);}; var f = function(){this.name=&

JAVA中判断char是否是中文的几种方法

1.方法一 Java代码   char c = 'a'; if((c >= 0x4e00)&&(c <= 0x9fbb)) { System.out.println("是中文"); } 上面的方法很简单,但只能判断是否是中文,但不能判断是否是中文标点. 下面的方法很全面,中文字符标点都可以判断 2.方法二 Java代码   private static final boolean isChinese(char c) { Character.UnicodeBl

xml文件转化为View的几种方法

在Android中,我们常常需要将一个布局文件转化为View对象,然后再在这个View对象中查找子控件,以下是几种常见的转化方式,主要是通过打气筒实现转化,Infalte方法的使用 http://bbs.itcast.cn/thread-77838-1-1.html