OC7_目录操作
//
// main.m
// OC7_目录操作
//
// Created by zhangxueming on 15/6/19.
// Copyright (c) 2015年 zhangxueming. All rights reserved.
// #import <Foundation/Foundation.h> int main(int argc, const char * argv[]) {
@autoreleasepool {
NSFileManager *fm = [NSFileManager defaultManager]; //- (NSDictionary *)attributesOfItemAtPath:(NSString *)path error:(NSError **)error
//获取文件或者目录的属性信息
NSDictionary *attribute = [fm attributesOfItemAtPath:@"/Users/zhangxueming/Desktop/city.plist" error:nil];
NSLog(@"attribute = %@", attribute);
NSLog(@"size = %@", [attribute objectForKey:@"NSFileSize"]);
//- (NSDictionary *)attributesOfFileSystemForPath:(NSString *)path error:(NSError **)error NSDictionary *attri = [fm attributesOfFileSystemForPath:@"/Users/zhangxueming/Desktop/city.plist" error:nil];
NSLog(@"attri = %@", attri); NSLog(@"size = %lli", [attri fileSize]); //文件及目录拷贝
// - (BOOL)copyItemAtPath:(NSString *)srcPath toPath:(NSString *)dstPath error:(NSError **)error
//dstPath:必须包含目的文件名或者目录名
BOOL ret = [fm copyItemAtPath:@"/Users/zhangxueming/Desktop/city.plist" toPath:@"/Users/zhangxueming/Desktop/Test/city.plist" error:nil];
if (ret) {
NSLog(@"拷贝成功");
}
else{
NSLog(@"拷贝失败");
}
//文件及目录移动(重命名)
// - (BOOL)moveItemAtPath:(NSString *)srcPath toPath:(NSString *)dstPath error:(NSError **)error
//srcPath与dstPath路径相同是重命名的功能, 否则是移动功能
ret = [fm moveItemAtPath:@"/Users/zhangxueming/Desktop/Test/中国象棋" toPath:@"/Users/zhangxueming/Desktop/Test/chess" error:nil];
if (ret) {
NSLog(@"移动成功");
}
else
{
NSLog(@"移动失败");
} //删除文件或者目录
// - (BOOL)removeItemAtPath:(NSString *)path error:(NSError **)error
ret = [fm removeItemAtPath:@"/Users/zhangxueming/Desktop/Test/chess" error:nil];
if (ret) {
NSLog(@"删除成功");
}
else{
NSLog(@"删除失败");
} //- (BOOL)fileExistsAtPath:(NSString *)path;
//判断文件是否存在
ret = [fm fileExistsAtPath:@"/Users/zhangxueming/Desktop/Test/file1"];
NSLog(@"ret = %i", ret);
}
return ;
}
OC7_目录操作的更多相关文章
- 【C#公共帮助类】FTPClientHelper帮助类,实现文件上传,目录操作,下载等动作
关于本文档的说明 本文档使用Socket通信方式来实现ftp文件的上传下载等命令的执行 欢迎传播分享,必须保持原作者的信息,但禁止将该文档直接用于商业盈利. 本人自从几年前走上编程之路,一直致力于收集 ...
- liunx学习(一):linux下目录操作大全
Linux C函数之文件及目录函数(全):http://blog.sina.com.cn/s/blog_695e489c01013ldd.html linux目录操作发:http://www.cnbl ...
- Java基础知识系列——目录操作
Java对目录操作的许多方法与上一篇文件操作的方法很多是一样的. java.io.File file = new File( "D:\1\2\3\4"); 1.递归创建目录 fil ...
- Python目录操作
Python目录操作 os和os.path模块os.listdir(dirname):列出dirname下的目录和文件os.getcwd():获得当前工作目录os.curdir:返回但前目录('.') ...
- PHP 文件与目录操作函数总结
>>>文件操作 打开 fopen(); 打开文件 读取内容 fread(); 从文件指针 handle 读取最多 length 个字节 readfile(); 读入 ...
- Python::OS 模块 -- 文件和目录操作
os模块的简介参看 Python::OS 模块 -- 简介 os模块的进程管理 Python::OS 模块 -- 进程管理 os模块的进程参数 Python::OS 模块 -- 进程参数 os模块中包 ...
- Matlab命令系列之目录操作
Matlab命令系列之目录操作 filesep 用于返回当前平台的目录分隔符,Windows是反斜杠(),Linux是斜杠(/).有时此命令结合ispc命令使用,可以灵活的设置目录分割符. fullf ...
- Matlab命令——目录操作(windows&Linux)
Matlab命令——目录操作(windows&Linux) 1. filesep用于返回当前平台的目录分隔符,Windows是反斜杠(\),Linux是斜杠(/).有时此命令结合ispc命令使 ...
- 【Linux C中文函数手册】之 目录操作函数
目录操作函数 1)closedir 关闭目录 相关函数: opendir表头文件: #include<sys/types.h> #include<dirent.h>定义函数: ...
随机推荐
- BZOJ 2120: 数颜色 分块
2120: 数颜色 Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://www.lydsy.com/JudgeOnline/problem.php? ...
- 禁止Android的StatusBar下拉
Android中有许多隐藏的Service,StatusBarManager就是其中一个,在Context.java中可以看到: /** * Use with {@link #getSystemSer ...
- boost.asio源码剖析(一) ---- 前 言
* 前言 源码之前,了无秘密. ——侯捷 Boost库是一个可移植.提供源代码的C++库,作 ...
- 类的this指针 总结
类的this指针有以下特点: (1)this只能在成员函数中使用 全局函数,静态函数都不能使用this. 实际上,成员函数默认第一个参数为T* const this. 如: class A { pub ...
- 申请TexturePacker 或 PhysicsEditor free licenses
有一个跟开发有关的blog,就可以去 http://www.codeandweb.com/request-free-license 申请一个free licenses. 可以申请TexturePack ...
- php对象当参数传递 && php深复制和浅复制
把对象当参数传递给方法,在方法里改过对象后,影响到外面的对象 因为对象是引用传递过去的 class Book { public $name; public function __construct( ...
- BloomFilter——读数学之美札记
之前接触过bitmap,读吴军先生的数学之美,看到了一个更强大的数据结构,布隆过滤器(Bloomfilter),赶紧记下来吧,忘了怪可惜的. bitmap的使用是很有局限性的,往往只能用于海量数值型数 ...
- 美国L1签证和B1,E2签证的区别
L1是跨国公司派驻工作人员到美国关联公司工作所需的签证.L1有两种: L1A是给管理人员的.L1B是给关键技术人员的.通过延期,L1A最长时间可达7年. L1B最长时间可达五年. 最初的L1申请,如果 ...
- oracle顺序控制语句goto、null和分页过程中输入输出存储、java程序的调用过程
顺序控制语句1 goto建议不要使用 declare i number:=; begin loop dbms_output.put_line(i); then goto end_loop; end i ...
- hadoop学习记录(四)hadoop2.6 hive配置
一.安装mysql 1安装服务器 sudo apt-get install mysql-server 2安装mysql客户端 sudo apt-get install mysql-client sud ...