Issue
I am trying to script a filecount for various folders on an android phone
In a perfect world, the following should work
adb shell ls -l | wc -l /sdcard/dcim/Camera
In my head, that should output the filecount of ./sdcard/dcim/camera
But of course it doesn't, instead it says
The term 'wc' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling
of the name, or if a path was included, verify that the path is correct and try again.
At line:1 char:21
+ adb shell ls -l | wc <<<< -l /sdcard/dcim/Camera
+ CategoryInfo : ObjectNotFound: (wc:String) [], CommandNotFoundException
+ FullyQualifiedErrorId : CommandNotFoundException
I can do adb shell ls -l /sdcard/dcim/Camera
just fine
but as soon as I add the | wc -l
part it breaks.
Any idea of what I'm missing here?
Note: Yes, I could enter shell, navigate to the folder and then do it from there, but that is not the solution I am looking for today.
Edit: when I do adb shell "ls -l | wc -l" /sdcard/dcim/Camera
i get
wc: /sdcard/dcim/Camera: Is a directory
0 /sdcard/dcim/Camera
EDIT2: I can't run wc in windows powershell, however, I can run it in androids shell, so
adb shell "ls -l | wc -l"
outputs the filecount in the phones root without the need for actually entering shell.
However, I have yet to discover how to do this in sub-folders.
Solution
Since you are working within Power Shell on windows and the linux utility wc
is not available, one possible solution is to do the following:
- Download the BusyBox binary, specifically busybox-armv5 from here.
- Push busybox to the phone and install it.
adb push path/to/busybox-armv5 /data/local/tmp
adb shell chmod 755 /data/local/tmp/busybox-armv5
adb shell /data/local/tmp/busybox-armv5 --install .
- There should be a bunch of binaries in the /data/local/tmp directory. Pull off
wc
to your local machine.adb shell pull /data/local/tmp/wc /my/destination
Now that you have the wc
binary, you can use it in your Power Shell script as a resource by doing the following:
- Before you run the adb command to get the file count, push the
wc
binary to /data/local/tmp. Make it executable.adb shell /path/to/wc /data/local/tmp/wc
adb shell chmod 755 /data/local/tmp/wc
- Now run your adb file count command.
adb shell "ls -l /sdcard/dcim/Camera | /data/local/tmp/wc -l"
Note: Putting quotes around the ls
and wc
command will ensure both commands are ran on the device. If the quotes were not there, only the command before the pipe would be ran on the device, while the wc
command would be ran/interpreted by the power shell.
Answered By - MDrabic
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.