fileManager move/remove/create/copy

// 查看文件夹下的文件

NSFileManager *fm = [NSFileManager defaultManager];

NSString *filePath = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) firstObject];

NSArray *fmarr = [fm contentsOfDirectoryAtPath:filePath error:nil];

[fmarr enumerateObjectsUsingBlock:^(id  _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {

NSLog(@"there are files at path: %@",obj);

}];

// 在指定路径创建文件夹

NSFileManager *fm1 = [NSFileManager defaultManager];

NSString *filePath1 = @"/Users/tangweiwei/Desktop";

NSString *createPath = [NSString stringWithFormat:@"%@/image",filePath1];

NSString *createpath1 = [NSString stringWithFormat:@"%@/MessageQueueImage",filePath1];

if (![[NSFileManager defaultManager]fileExistsAtPath:createPath]) {

[fm1 createDirectoryAtPath:createPath withIntermediateDirectories:YES attributes:nil error:nil];

[fm1 createDirectoryAtPath:createpath1 withIntermediateDirectories:YES attributes:nil error:nil];

}else {

NSLog(@"create file failed");

}

// 删除文件夹

NSFileManager *deleteObj = [NSFileManager defaultManager];

NSString *deletePath = [NSString stringWithFormat:@"/Users/tangweiwei/Desktop"];

NSString *dpath = [deletePath stringByAppendingPathComponent:@"image"];

NSString *dpath2 = [deletePath stringByAppendingString:@"/MessageQueueImage"];

BOOL dResult = [deleteObj removeItemAtPath:dpath error:nil];

BOOL dResult2 = [deleteObj removeItemAtPath:dpath2 error:nil];

if (dResult) {

NSLog(@"remove file success");

}

if (dResult2) {

NSLog(@"remove file2 success");

}

// 移动文件夹

NSFileManager *newFM = [NSFileManager defaultManager];

NSString *newFile = NSTemporaryDirectory();

NSString *fileName = [newFile stringByAppendingPathComponent:@"image"];

[newFM createDirectoryAtPath:fileName withIntermediateDirectories:YES attributes:nil error:nil];

NSString *destination = [NSString stringWithFormat:@"/Users/tangweiwei/Desktop/未命名文件夹"];

NSString *originPath = fileName;

NSString *newString = [destination stringByAppendingPathComponent:@"copied"];

BOOL copyResult = [newFM copyItemAtPath:originPath toPath:newString error:nil];

if (copyResult) {

NSLog(@"copied");

}

// 移动文件

NSString *destinateFile = [destination stringByAppendingPathComponent:@"moveFile"];

BOOL moveResult = [newFM moveItemAtPath:originPath toPath:destinateFile error:nil];

if (moveResult) {

NSLog(@"moved");

}

//     在指定文件夹创建图片

UIImage *img = [UIImage imageNamed:@"123"];

NSData *data = UIImagePNGRepresentation(img);

NSData *data1 = [@"123321" dataUsingEncoding:NSUTF8StringEncoding];

NSLog(@"data  :%@,data1:%@",data,data1);

NSFileManager *fm11 = [NSFileManager defaultManager];

NSString *filePath11 = [@"/Users/tangweiwei/Desktop/未命名文件夹" stringByAppendingPathComponent:@"newImage.png"];

NSString *newPath = filePath11;

BOOL result = [fm11 createFileAtPath:newPath contents:data attributes:nil];

if (result) {

NSLog(@"success to creat file");

}

时间: 2024-12-30 03:16:18

fileManager move/remove/create/copy的相关文章

Duplicate the UIButton and Move it

http://stackoverflow.com/questions/19241208/duplicate-the-uibutton-and-move-it/26438692#26438692 1down votefavorite I have one UIButton(lets say instance1).I have set target method when it moves.So when I try to move(drag) I want to do that create co

C++ 11 右值引用以及std::move

转载请注明出处:http://blog.csdn.net/luotuo44/article/details/46779063 新类型: int和int&是什么?都是类型.int是整数类型,int&则是整数引用类型.相同int&&也是一个类型.两个引號&&是C++ 11提出的一个新的引用类型.记住,这是一个新的类型.默念10次吧.假设你记住这个新类型,那么非常多疑问都能迎刃而解.而且对<Effective Modern C++>说到的void f(

(译)C++11中的Move语义和右值引用

郑重声明:本文是笔者网上翻译原文,部分有做添加说明,所有权归原文作者! 地址:http://www.cprogramming.com/c++11/rvalue-references-and-move-semantics-in-c++11.html C++一直致力于生成快速的程序.不幸的是,直到C++11之前,这里一直有一个降低C++程序速度的顽症:临时变量的创建.有时这些临时变量可以被编译器优化(例如返回值优化),但是这并不总是可行的,通常这会导致高昂的对象复制成本.我说的是怎么回事呢? 让我们

[转] C++11带来的move语义

PS: 通过引入接收右值的函数形参,可以通过接收右值来实现高效 C++ 11带来了move语义,可以有效的提高STL的效率,这篇文章写的非常好,可以参考,这里对原文进行翻译,加入我自己的理解 原文:http://www.cprogramming.com/c++11/rvalue-references-and-move-semantics-in-c++11.html 先看看这个例子: [cpp] view plaincopy #include <iostream> using namespace

C++ RVO/NRVO以及move语义的影响

C++返回值优化和具名返回值优化是编译器的优化,在大多数情况下能提高性能,但是却难以受程序员控制.C++11中加入了move语义的支持,由此对RVO和NRVO会造成一定影响.下面以一段代码来说明. RVO和NRVO在分别在copy/move construct,copy/move assignment八种简单情况,测试条件是g++ 4.8.2和clang++ 3.4,默认优化. #include <iostream> #include <vector> #include <s

How To Transact Move Order Using INV_PICK_WAVE_PICK_CONFIRM_PUB.Pick_Confirm API

In this Document Goal   Solution   Sample Code:   Steps:   FAQ   References APPLIES TO: Oracle Inventory Management - Version 11.5.10.2 to 12.1.3 [Release 11.5.10 to 12.1] Information in this document applies to any platform. This document includes 1

array copy rotate in Pointwise

goal: # # Copyright 2010 (c) Pointwise, Inc. # All rights reserved. # # This sample Pointwise script is not supported by Pointwise, Inc. # It is provided freely for demonstration purposes only. # SEE THE WARRANTY DISCLAIMER AT THE BOTTOM OF THIS FILE

Hadoop Balancer源码解读

前言 最近在做一些Hadoop运维的相关工作,发现了一个有趣的问题,我们公司的Hadoop集群磁盘占比数值参差不齐,高的接近80%,低的接近40%,并没有充分利用好上面的资源,但是balance的操作跑的也是正常的啊,所以打算看一下Hadoop的balance的源代码,更深层次的去了解Hadoop Balance的机制. Balancer和Distpatch 上面2个类的设计就是与Hadoop Balance操作最紧密联系的类,Balancer类负载找出<source, target>这样的起

Query runs slow via .NET

Slow in the Application, Fast in SSMS?Understanding Performance Mysteries An SQL text by Erland Sommarskog, SQL Server MVP. Last revision: 2013-08-30.This article is also available in Russian, translated by Dima Piliugin. Introduction When I read var