Add created and modified dates to ReadDirItem

This commit is contained in:
Albert Martin 2017-04-26 09:46:56 -05:00
parent a87fe3fe89
commit b139b5d58b
4 changed files with 9 additions and 0 deletions

View File

@ -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,

View File

@ -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

View File

@ -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],

View File

@ -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());