Skip to content

Instantly share code, notes, and snippets.

@ashtonx
Created February 20, 2021 02:27
Show Gist options
  • Save ashtonx/92df848c5c8b809cbcf1f49c4cae4731 to your computer and use it in GitHub Desktop.
Save ashtonx/92df848c5c8b809cbcf1f49c4cae4731 to your computer and use it in GitHub Desktop.
sort wbfs
import os
import subprocess
import shutil
def get_id6(file):
result = subprocess.run(['wit','ID6', file], stdout=subprocess.PIPE)
return result.stdout.decode('utf-8')
def make_new_dir(dir_name):
cwd = os.getcwd();
if os.path.basename(cwd)=="wbfs":
path = os.path.join(cwd,dir_name)
try:
os.mkdirs(path, exist_ok=True)
except OSError as error:
print("error making directory {}".format(error))
else:
print("current directory{} is not \"wbfs\"".format(cwd))
return path
def rename_files(dir):
for file in os.listdir(dir):
if file.endswith(".wbfs") or file.endswith(".wbf1"):
fname, ext = os.path.splitext(fname)
new_name = get_id6(file)[0:6]+ext
move_target = makedir(fname)
shutil.rename_file(os.path.join(cwd,file), os.path.join(move_target,new_name))
def main():
cwd = os.getcwd();
rename_files(cwd)
if __name__ == "__main__":
main()
# and i could've done it all with just one command line
# wit mv . -D %T/%I.%E
@ashtonx
Copy link
Author

ashtonx commented Feb 20, 2021

and i could've done it all with just one command line
wit mv . -D %T/%I.%E

@ashtonx
Copy link
Author

ashtonx commented Feb 20, 2021

wit mv . -D %Y/%I.%E
folder name needs Title ID = '%T [%I]'

%Y = '%T [%I]'

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment