From b139b5d58b309ae054995400187ee3632188d732 Mon Sep 17 00:00:00 2001 From: Albert Martin Date: Wed, 26 Apr 2017 09:46:56 -0500 Subject: [PATCH] Add created and modified dates to `ReadDirItem` --- FS.common.js | 4 ++++ README.md | 2 ++ RNFSManager.m | 2 ++ android/src/main/java/com/rnfs/RNFSManager.java | 1 + 4 files changed, 9 insertions(+) diff --git a/FS.common.js b/FS.common.js index d4e4ea1..a205388 100644 --- a/FS.common.js +++ b/FS.common.js @@ -31,6 +31,8 @@ type MkdirOptions = { }; type ReadDirItem = { + created: date; // The creation date of the file (iOS only) + modified: date; // The last modified date of the file name: string; // The name of the item path: string; // The absolute path to the item size: string; // Size in bytes @@ -159,6 +161,8 @@ function readFileGeneric(filepath: string, encodingOrOptions:?string, command: F function readDirGeneric(dirpath: string, command: Function) { return command(normalizeFilePath(dirpath)).then(files => { return files.map(file => ({ + created: file.created && new Date(file.created) || null, + modified: new Date(file.modified), name: file.name, path: file.path, size: file.size, diff --git a/README.md b/README.md index 1e62722..d8bcc6a 100644 --- a/README.md +++ b/README.md @@ -295,6 +295,8 @@ The returned promise resolves with an array of objects with the following proper ``` type ReadDirItem = { + created: date; // The creation date of the file (iOS only) + modified: date; // The last modified date of the file name: string; // The name of the item path: string; // The absolute path to the item size: string; // Size in bytes diff --git a/RNFSManager.m b/RNFSManager.m index 45da1d9..06df7f0 100644 --- a/RNFSManager.m +++ b/RNFSManager.m @@ -52,6 +52,8 @@ RCT_EXPORT_METHOD(readDir:(NSString *)dirPath NSDictionary *attributes = [fileManager attributesOfItemAtPath:path error:nil]; return @{ + @"created": [attributes objectForKey:NSFileCreationDate], + @"modified": [attributes objectForKey:NSFileModificationDate], @"name": obj, @"path": path, @"size": [attributes objectForKey:NSFileSize], diff --git a/android/src/main/java/com/rnfs/RNFSManager.java b/android/src/main/java/com/rnfs/RNFSManager.java index 3269dbd..ff6a3f0 100644 --- a/android/src/main/java/com/rnfs/RNFSManager.java +++ b/android/src/main/java/com/rnfs/RNFSManager.java @@ -259,6 +259,7 @@ public class RNFSManager extends ReactContextBaseJavaModule { for (File childFile : files) { WritableMap fileMap = Arguments.createMap(); + fileMap.putString("modified", childFile.lastModified()); fileMap.putString("name", childFile.getName()); fileMap.putString("path", childFile.getAbsolutePath()); fileMap.putInt("size", (int)childFile.length());