FileInfo - get some information about files and folders

:point_up: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:
blocks

[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.

Testing

Android 4:


Android 5:

Android 6:

Android 7:

Android 8:

Android 9:

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.
    Screenshot_2019-03-25_15-36-38
    (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):
ablocks
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)

16 Likes

If this is your first extension Robert, good job!!!

2 Likes

You learn English, not I do…
However, fine extension. By the way, I knew you were doing this all in a GitHub repo, below GPL, or now you don’t want to make it?

EDIT: found another typo/issue

If I’m true, it’s spelled as contain, but I’m not certain, Nathan or Cian, you’re the essential English speakers I know around there, can you verify it?

Good job Robert for the first extension! :+1::slightly_smiling_face:


By the way, @Daaniiieel I didn’t understand why you want to fix Robert’s grammar errors. :sweat_smile:

I know, I’m not an essential English speaker but just checked for you in grammar checker. :joy:

image
(not sponsored don’t worry :rofl:)

4 Likes

Because he’s my brother :joy:

3 Likes

UPDATE

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.
    Screenshot_2019-03-25_15-36-38
    (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
Download: com.robertcrum.FileInfo.aix (8.1 KB)

1 Like

thank you for your contribution
you might want to follow the naming conventions, which is UpperCamelCase for property, method and event names (i.e. the first letter should be a capital letter) and lowerCamelCase for parameter names

example:
naming

rather than having a method name like isExist let me suggest you to rename it to Exists

Taifun

3 Likes

Corrected the mistakes. Sorry for not providing image. Extension: com.robertcrum.FileInfo.aix (8.1 KB)

3 Likes

New version is here!

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):

Download: com.robertcrum.FileInfo.aix (10.3 KB)

As you can see, it is 4,2 KB larger than the first version (what stands for 110 new lines of code)

4 Likes

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):
ablocks
Download extension: com.robertcrum.FileInfo.aix (10.6 KB)

2 Likes

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! Download extension: com.robertcrum.FileInfo.aix (10.7 KB)

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.

*That square in code is () with rectangular end-sign [ .

Hi @Robert
Download link is not working :sob:

I will re-upload it tomorrow.

1 Like

Hi @Robert

I also have problems to download. Could you help me with this?

Thanks.

1 Like

I cant download it…

1 Like

I am going to recompile it after IDE’s performance issue is fixed.

1 Like

Download error :cry:, please , fixed it.

I need this extension, please share the download link.

1 Like

No the link will not be shared. Look through the topic, the issue has already been reported.

Please consider to make an option to delete folder (not files).