当前位置:网站首页>How to use nsfilemanager
How to use nsfilemanager
2022-06-24 02:30:00 【Juming 12255】
To summarize NSFileManager Some common methods of ,
NSArray *paths =NSSearchPathForDirectoriesInDomains(NSDocumentDirectory ,NSUserDomainMask,YES);
NSString *documentDirectory = [paths objectAtIndex:];
NSLog(@"%@", documentDirectory);// Path view
//1. Create folder
NSFileManager *fileManager = [NSFileManagerdefaultManager];
NSString *testDirectory = [documentDirectory stringByAppendingPathComponent:@"testbug1"];// Create folder
// Create directory
[fileManager createDirectoryAtPath:testDirectorywithIntermediateDirectories:YESattributes:nilerror:nil];
//2. create a file
NSString *test11 = [testDirectory stringByAppendingPathComponent:@"test111.txt"];
NSString *test22 = [testDirectory stringByAppendingPathComponent:@"test222.txt"];
NSString *string = @" Write content 1";
[fileManager createFileAtPath:test11contents:[string dataUsingEncoding:NSUTF8StringEncoding]attributes:nil];
[fileManager createFileAtPath:test22contents:[string dataUsingEncoding:NSUTF8StringEncoding]attributes:nil];
//3. see Document All the documents in
NSArray *files = [fileManager subpathsAtPath:documentDirectory];
//4. View all sub files in the directory
NSArray *subfiles = [fileManager subpathsAtPath:testDirectory];
NSLog(@"%@", subfiles);
NSLog(@"%@", files);
//5. Change to the directory to be operated
[fileManager changeCurrentDirectoryPath:[documentDirectorystringByExpandingTildeInPath]];
// create a file filename file name ,contents The content of the document
NSString *fileName [email protected]"testfilemanager.txt";
NSArray *array = [[NSArrayalloc]initWithObjects:@"hello world",@"hello World", nil];
[fileManagercreateFileAtPath:fileName contents:array attributes:nil];
//6. Delete file
[fileManagerremoveItemAtPath:fileName error:nil];
//7. Copy files from the latter to the former
NSError *error;
[fileManagercopyItemAtPath:test11 toPath:test22 error:&error];
//8. Moving files
NSString *test33 = [documentDirectory stringByAppendingPathComponent:@"test33.txt"];
if ([fileManager moveItemAtPath:test11toPath:test33 error:&error] !=YES) {
NSLog(@"111%@", [errorlocalizedDescription]);
}
//9. Does the file exist
if ([[NSFileManagerdefaultManager]fileExistsAtPath:@"/Users/dlios/Library/Application Support/iPhone Simulator/7.1/Applications/AC7B8788-BDCB-43AC-ABB6-8E9676CF94DC/Documents/testbug/test22333.txt"]) {
NSLog(@"yes");
}
else NSLog(@"no");
边栏推荐
- [Tencent cloud double 12 audio and video communication special session] from 9 yuan for Q4 counter attack artifact, SMS and security (New) package!
- How to design and make ppt gradient effect?
- What is the cloud desktop server configuration? What are the application scenarios of cloud desktop?
- Question: can you get download the resources of Baidu online disk?
- Select problem set 3
- How to handle the abnormal state of easycvr national standard cascading superior display?
- How does [lightweight application server] build a cross-border e-commerce management environment?
- Vivo global mall: design and practice of commodity system architecture
- Learning and life -- Talking about my learning methods
- How to query the cloud desktop server address? What are the advantages of using cloud desktop?
猜你喜欢

application. Yaml configuring multiple running environments

Advanced BOM tool intelligent packaging function

Leetcode969: pancake sorting (medium, dynamic programming)

How to fill in and register e-mail, and open mass mailing software for free

If there are enumerations in the entity object, the conversion of enumerations can be carried out with @jsonvalue and @enumvalue annotations

Introduction to development model + test model
Cloudpods golang practice

BIM model example

2020 language and intelligent technology competition was launched, and Baidu provided the largest Chinese data set

163 mailbox login portal display, enterprise mailbox computer version login portal
随机推荐
[security] Tencent cloud double 12 is not limited to new and old users! Safe sub venue - discount guide! Unlimited account types!
What is ITF barcode
Wwise + GME game voice scheme: unlock more voice playing methods and let players "sound in their environment"
What if the cloud desktop fails to connect to the server? How to use cloud desktop?
Flink practice tutorial: getting started 1- zero basic users realize simple Flink tasks
How to design and make ppt gradient effect?
Mainstay of network detection - nping User Guide
Why do cloud desktops use rack servers? What are the functions of cloud desktop?
How to fill in and register e-mail, and open mass mailing software for free
How about Tencent cloud game server? Can the cloud game server play games
DB2 database generates HTML patrol Report
Designing complex messaging systems using bridging patterns
What are the main functions of DNS? What are the benefits of IP address translation
Centeros environment setup
How to set up a cloud desktop server? What are the advantages of cloud desktop?
Cloudpods golang practice
Cloud recommendation Vol.1: quick start to remote control under f-stack, go modules and 5g!
Introduction to development model + test model
What is the industrial Internet? What is the industrial Internet platform?
What is the backbone of marketing website construction? What does it do?