Getting list of files in documents folder

Getting list of files in documents folder

Content Index :

Getting list of files in documents folder
Tag : ios , By : omaidog
Date : November 24 2020, 01:01 AM

may help you . This solution works with Swift 4 (Xcode 9.2) and also with Swift 5 (Xcode 10.2.1+):
let fileManager = FileManager.default
let documentsURL = fileManager.urls(for: .documentDirectory, in: .userDomainMask)[0]
do {
    let fileURLs = try fileManager.contentsOfDirectory(at: documentsURL, includingPropertiesForKeys: nil)
    // process files
} catch {
    print("Error while enumerating files \(documentsURL.path): \(error.localizedDescription)")
import Foundation

extension FileManager {
    func urls(for directory: FileManager.SearchPathDirectory, skipsHiddenFiles: Bool = true ) -> [URL]? {
        let documentsURL = urls(for: directory, in: .userDomainMask)[0]
        let fileURLs = try? contentsOfDirectory(at: documentsURL, includingPropertiesForKeys: nil, options: skipsHiddenFiles ? .skipsHiddenFiles : [] )
        return fileURLs

// Usage
print(FileManager.default.urls(for: .documentDirectory) ?? "none")

No Comments Right Now !

Boards Message :
You Must Login Or Sign Up to Add Your Comments .

Share : facebook icon twitter icon

Retrieving updated files from server to replace files on documents folder of an iPhone

Tag : iphone , By : leorick
Date : March 29 2020, 07:55 AM
Any of those help you can use NSUrlRequest to download the files, to move them to the correct place you can use NSFileManager, if you look at the apple docs for both these classes there should be sample code explaining how to copy/save a file from NSData, and also how to download it.

Write a list of files in the Documents folder and keep them in memory

Tag : iphone , By : AdrianB
Date : March 29 2020, 07:55 AM
seems to work fine U can save NSArray in Document Directory like this.
Note : saving and retrieving filename remains same.
 //check favourite saved in doc dir
 if(!saved) //not saved
   //NSMutableArray has not data first time
   //[NSMutableArray addObject:newFavourite];
   //save new data in doc dir
 else // saved
   //firstly retrieve data from doc dir as NSMutableArray
   //[NSMutableArray addObject:newFavourite];
   //Now save again NSMutableArray in doc dir.

How to delete files from a folder which is placed in documents folder

Tag : iphone , By : snk
Date : March 29 2020, 07:55 AM
wish helps you You can use the below code to delete the file from document directory:
NSError *error;
NSFileManager *fileMgr = [NSFileManager defaultManager];
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];
NSString *documents= [documentsDirectory stringByAppendingPathComponent:@"YourFolder"];
NSString *filePath = [documents stringByAppendingPathComponent:@"file2.txt"];
[fileMgr removeItemAtPath:filePath error:&error]

UWP : How to get a list of all the text file names from a sub folder of Documents folder

Tag : chash , By : Jim Davis
Date : March 29 2020, 07:55 AM
To fix the issue you can do If you want to access Documents folder, you can use FolderPicker or KnownFolders.DocumentsLibrary method.
About FolderPicker, you need to access folders by interacting with a picker, but you can directly choose the folder you want to. About KnownFolders.DocumentsLibrary method, you need to add extra broadFileSystemAccess capability and allow your app to access file system in settings. ​
var folderPicker = new Windows.Storage.Pickers.FolderPicker();
folderPicker.SuggestedStartLocation = Windows.Storage.Pickers.PickerLocationId.DocumentsLibrary;
Windows.Storage.StorageFolder subFolder = await folderPicker.PickSingleFolderAsync();

//StorageFolder Myfolder = KnownFolders.DocumentsLibrary;
//StorageFolder subFolder = await Myfolder.GetFolderAsync("YouSubFolder");
List<string> fileTypeFilter = new List<string>();
QueryOptions queryOptions = new QueryOptions(Windows.Storage.Search.CommonFileQuery.OrderByName, fileTypeFilter);
StorageFileQueryResult queryResult = subFolder.CreateFileQueryWithOptions(queryOptions);
var files = await queryResult.GetFilesAsync();
foreach (var file in files)
    string name = file.Name;

List all files in Documents Folder

Tag : objective-c , By : Fahad
Date : March 29 2020, 07:55 AM
Related Posts Related QUESTIONS :
  • How to get slider value with subview rotation angle
  • Can't pass custom UINavigationBar / UIToolbar to UINavigationController because they don't conform to AnyClass
  • Grab SELECTED text on UITextView
  • Clever ways to better test GPS code using only the iPhone simulator?
  • Remove app before simulator or device is lunched from Xcode
  • Auto Layout constraints for container view inside UITableView header broken for different devices
  • iPhone restarts after API call
  • What is the shortcut / How do I create function after writing it's usage in Xcode
  • Convert apple time stamp to Unix time
  • No podspec found for `React-fishhook`
  • How to test touch dialog and perform real in-app purchase?
  • Compiling Metal shaders from source on iOS 13 Simulator gives PCH error
  • conan error:I need to cross build packages for os:iOS with my Macos, but when the first package was done, it broke my cp
  • Update calendar 'start of week' from phones system calendar
  • Xcode is showing some warnings
  • How to remove the default Navigation Bar space in SwiftUI NavigiationView
  • Having trouble integrating multiple pickerviews in the same view
  • SCNNode not in SCNView hierarchy, still showing & getting touches & physics
  • How can I open my SwiftUI app and perform a function using NSUseractivity from within Siri Intent Extension?
  • NSCoding decodeObject always nil
  • Passing data in a segmented Controller?
  • Facing issue in Siri Integration with custom intents
  • ARKit3 Hardware Requirement Clarification
  • ARKit3 How to use TrueDepth camera for face tracking and face meshes of other people?
  • How to discriminate while decoding using Codable Protocol in Swift?
  • 'IPA processing failed' while distributing build in Xcode Beta
  • How to debug a crash which happened when come back from background
  • Synchronising old data with NSPersistentCloudKitContainer
  • iOS app opened from web app with url redirects to Appstore
  • How to change the color of seperator in tableView?
  • Is there a better way to watch for a key-value change?
  • How to make UIBezierPath to fill from the center
  • Why on Xcode 11, UICollectionViewCell changes size as soon as you scroll (I already set size in sizeForItem AtIndexPath:
  • How to scan non LE devices using Swift?
  • Unable to infer closure type in the current context in SwiftUI
  • What is the best way to write common code and use it entire project
  • UISegmentedControl inside UIStackView, segments text not centered - iOS 13
  • Swift & ObjC bridge - cannot find protocol declaration for "WKNavigationDelegate"
  • SwiftUI How to push to next screen when tapping on Button
  • 'NSApp' is unavailable in UIKit for Mac: How to embed Mac only framework in iOS app on macOS?
  • UserDefaults Binding with Toggle in SwiftUI
  • How to create a color with an alpha value using SwiftUI?
  • SwiftUI creates destination views before the user navigates to them
  • Streaming video from https with AVPlayer causes initial delay
  • Tap Action not working when Color is clear SwiftUI
  • SwiftUI NavigationButton: How to navigate to different destinations
  • Supported default light/dark mode colors for Color vs UIColor
  • XCUITest wait for a cell with a specific static text inside it
  • Not able to enable Development mode on iOS 13
  • How to hide the home indicator with SwiftUI?
  • How to write if condition with using label text (Int) values
  • Swift Cannot use instance member within property initializer
  • Issue while getting the frame of the keyboard
  • dynamicMemberLoookup ExpressibleByStringLiteral parameter swift
  • iOS Unity Firebase Messenger Xcode Compile Error: FIRDynamicLinks
  • Firebase Storage Image Cache not updating SWIFT
  • unhandled js exception: application main has not been registered expo TestFlight
  • App freezes on IOS when navigate to another screen - React Navigation
  • How to create haptic feedback for a Button in SwiftUI?
  • How can I achieve automatic scrolling in my text view when text comes down to the keyboard level in Swift?
  • shadow
    Privacy Policy - Terms - Contact Us © scrbit.com