Welcome to XDA

Search to go directly to your device's forum

Register an account

Unlock full posting privileges

Ask a question

No registration required
Post Reply

Android ls and df parsing

OP k1ll3r8e

28th April 2014, 10:24 PM   |  #1  
OP Senior Member
Flag Delmenhorst
Thanks Meter: 100
156 posts
Join Date:Joined: Mar 2011
Donate to Me
Hey all together,

after a lot of searching and using Google for days with no really good results i created now my own reg-ex functions to parse some Android shell outputs. So i only want to share my functions coz i dun found something like that.

If u create a Android File-Explorer or something else like this u'll have to get the ls and df output in some situations, if u use C# like me this will be great for u.

here are my functions:

(command) ls -l
(command) busybox ls -aFl

u can use it like

GroupCollection groups = Regex.Match("the ls -l or busybox -aFl output line by line", @"^(?<TYPE>(-|b|c|d|l|s|p){1})(?<PERM>(-|r|w|x|s|t){9})\s{1,}(?<INCLUDES>([0-9]){1,}\s{1,})?(?<OWNER>(.*?))\s{1,}(?<GROUP>(.*?))\s{1,}(?<ID>([0-9]){1,},\s{1,})?(?<SIZE>([0-9]){1,}\s{1,})?(?<DATE>(.*?))\s{1,}(?<TIME>([0-9]{2}.[0-9]{2}|[0-9]{4}))\s{1}(?<NAME>(.*?))(\s{1}->\s{1}(?<SYMLINK>(.*?)))?(?<SUBTYPE>(\*|/){1})?$").Groups;
            string Type = groups["TYPE"].Value;
            string SubType = groups["SUBTYPE"].Value;
            string Perms = groups["PERM"].Value;
            string Owner = groups["OWNER"].Value;
            string Group = groups["GROUP"].Value;
            string Id = groups["ID"].Value;
            string Size = groups["SIZE"].Value;
            string Date = String.Join(" ", groups["DATE"].Value, groups["TIME"].Value);
            string Name = groups["NAME"].Value;
            string[] extTmp = Name.Split('.');
            string FileExtension = extTmp[extTmp.Length - 1];
            string SymPath = groups["SYMLINK"].Value;

(command) df
(command) busybox df -Pakh

u can use it like

GroupCollection groups = Regex.Match("the df or df -Pakh output line by line", @"^(df:\s{1,})?(?<NAME>(.*?))(:\s{1,}(.*?))?(\s{1,}(?<SIZE>([0-9]{1,}[a-zA-Z\.]?){1,}))?(\s{1,}(?<USED>([0-9]{1,}[a-zA-Z\.]?){1,}))?(\s{1,}(?<FREE>([0-9]{1,}[a-zA-Z\.]?){1,}))?(\s{1,}(?<BLOCKSIZE>([0-9]){1,}))?(\s{1,}(?<USE>([0-9]{1,})%))?(\s{1,}(?<PATH>(.*?)))?$").Groups;
            string Name = groups["NAME"].Value;
            string Size = groups["SIZE"].Value;
            string Used = groups["USED"].Value;
            string Free = groups["FREE"].Value;
            string BlockSize = groups["BLOCKSIZE"].Value;
            string Use = groups["USE"].Value;
            string Path = groups["PATH"].Value;

Hope this helps someone

Last edited by k1ll3r8e; 28th April 2014 at 10:27 PM. Reason: forgot the 1 busybox line
Post Reply Subscribe to Thread
Previous Thread Next Thread
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes