Created
February 14, 2016 23:19
-
-
Save karllindmark/08a13e14b8134e3b3240 to your computer and use it in GitHub Desktop.
Getting rid of those :nopm: files since 2016
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python2.7 | |
""" | |
This is a script to remove weird characters (currently only :) from | |
filenames found in the given path. | |
""" | |
import os | |
import subprocess | |
import sys | |
def main(): | |
""" | |
Main method of the script | |
""" | |
print "######## %s ########" % sys.argv[0] | |
if len(sys.argv) < 2: | |
sys.exit("No directory specified") | |
path = " ".join(sys.argv[1:]) | |
ls_command = ['adb', 'shell', 'ls', path] | |
mv_command = ['adb', 'shell', 'mv'] | |
print ' '.join(ls_command) | |
all_files = subprocess.check_output(ls_command).split() | |
dirty_files = [x for x in all_files if ":" in x] | |
ok_count = 0 | |
tot_count = len(dirty_files) | |
for fname in dirty_files: | |
src = os.path.join(path, fname) | |
dst = os.path.join(path, fname.replace(':', '_')) | |
cmd = mv_command + [src, dst] | |
print ' '.join(cmd) | |
if subprocess.call(cmd) == 0: | |
ok_count += 1 | |
else: | |
print "Unable to move '{fname}'".format(fname=fname) | |
print "Completed {ok}/{total} renames".format(ok=ok_count, total=tot_count) | |
return ok_count - tot_count | |
sys.exit(main()) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment