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>定义函数: ...
随机推荐
- UVa Online Judge 工具網站
UVa Online Judge 工具網站 UVa中译题uHuntAlgorithmist Lucky貓的ACM園地,Lucky貓的 ACM 中譯題目 Mirror UVa Online Judg ...
- TOJ 4325 RMQ with Shifts / 线段树单点更新
RMQ with Shifts 时间限制(普通/Java):1000MS/3000MS 运行内存限制:65536KByte 描述 In the traditional RMQ (Range M ...
- iOS开发——总结篇&常用开发总结
一.通知1.监听通知 - (void)addObserver:(id)observer selector:(SEL)aSelector name:(NSString *)aName object:(i ...
- SQL Server 之 在与SQLServer建立连接时出现与网络相关的或特定于实例的错误
背景:在用数据库时,打开SQL Server 2008 R2 的 SQL Server Management Studio,输入sa的密码发现,无法登陆数据库,提示信息如上: 解决方案: 1.打开Sq ...
- Npoi 导出Excel 下拉列表异常: String literals in formulas can't be bigger than 255 Chars ASCII
代码: public static void dropDownList(string[] datas, string filePath) { HSSFWorkbook workbook = new H ...
- storyBoard中的Segue跳转
//———————————————--------------在不确定的Segue跳转----------------------------------- 多个按钮指向要跳转的视图 1.在一个恰 ...
- CSS: Float a div on another div, Ex: Text caption on picture
<style type="text/css"> .figure { width: 316px; height: 205px; display: block; borde ...
- Agile software architecture design document style..( sketches and no UMLs)
http://www.infoq.com/articles/agile-software-architecture-sketches-NoUML If you're working in an agi ...
- 如果将WCF服务发布为rest模式
WCF是支持多种协议的,其中basicHttpBinding是基础协议绑定,类似于传统的webservice. 如果要将WCF发布成rest,绑定协议要使用webHttpBinding,并且在终结点的 ...
- CentOS(四)--Linux系统的启动级别
对于绝大多数Linux程序员来说,进入Linux系统后一般看到的是黑乎乎的界面(开发模式),因为系统如果启动选择开发模式,会减少启动时间,优化内存等.但是通常我们刚安装完Linux系统,然后进去以后是 ...