As you know, it is possible with the shell component to get the modified date
However sometimes a directory contains a lot of files and the ls -l command crashes from about more than 600-700 files. I wanted something which has no crashes or lags so I wrote this very simple extension:
GetModDate
It is a faster and better solution to get modified date.
Blocks what you can use:
[Download at the end of post!]
How to use extension:
Here is an example (remember that it works both with files and folders, not just one of them!):
Your path mustn’t start with
file://
As you can see, you don’t have to write “/” after the folder name.
If the object does not exist or it’s modified date is not accessible, it will return to the devices “zero” time (which is not actually zero but the system can’t think of time e.g. before 1970).
It should work on all Android devices from 4.4.
Changelogs:
1. Added new blocks. With this extension now you can…
-
Get modified date
-
Format modified date. For example MM/dd/yyyy HH:mm:ss will return 10/10/2020 12:34:34.
(It supports many formats.) -
Get file length (size in bytes)
-
Get content list from a folder (which contains both files and folders, with only their name: command.txt, data) It working fast: loading 4000 items took only 1-2s, it doesn’t lag.
-
Check if the file/folder exist
-
Check if the given path is a directory
It’s functions:
This extension is no longer just a modifieddate-extension. New name is: FileInfo
2. Added some blocks:
- ExecuteLinuxCommand : run linux commands with result.
Example:
-
GetFileList: Get only the files from a directory, with names.
-
GetFolderList: Get only foders from a directory, with names.
(Why don’t I put containsPath property to them? Because of there are no subdirectories’ files contained, you can easily make the full paths with join block [join(path + name)]. For subdirectories, use your logic or Taifun’s File extension.)
- GetName: Returns to the name of the file from its path. For example /system/app/AutoDialer will return AutoDialer. Works with files and folders too.
Here are the blocks (sorry for that low quality):
3. Added protection against non-readable folders (like /cache
). They were causing an error “Attempt to get length of a null array”. Created another block to check if a folder is accessible (for files use this with parent folder):
4. The block ExecuteLinuxCommand did not work properly. Commands with ’ or " in them returned to empty string and did nothing. Like cp -r ‘/system/app’ ‘/mnt/sdcard/system apps’ or echo “hello world”.
Now it has been fixed!
Source-code of that block
View code
@SimpleFunction(description = “Execute a linux command. You can also use this for file options e.g. cp - copy mv - move rm - remove. Example: cp -r ‘/system/app’ ‘/mnt/sdcard/My Documents/systemapps’”)
public String ExecuteLinuxCommand(String command){
String s;
Process p;
String result = “”;
try {
p = Runtime.getRuntime().exec(new String{“sh”,"-c",command});
BufferedReader br = new BufferedReader(new InputStreamReader(p.getInputStream()));
while ((s = br.readLine()) != null)
result = result + s + System.lineSeparator();
p.waitFor();
p.destroy();
} catch (Exception e) {}
return result;
}
Why do I publish that? Because finding the right way take me hours.
Download extension: com.robertcrum.FileInfo.aix (10.7 KB)