Last active
September 1, 2019 13:54
-
-
Save fripSide/fd6f560dbd325022cf1cba69ca127bdd to your computer and use it in GitHub Desktop.
windows set directory file name case senstitive recursively
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
# encode=utf-8 | |
import os | |
import sys | |
import subprocess | |
""" | |
or one line powershell command: | |
(Get-ChildItem -Recurse -Directory).FullName | ForEach-Object {fsutil.exe file setCaseSensitiveInfo $_ enable} | |
https://stackoverflow.com/questions/51591091/apply-setcasesensitiveinfo-recursively-to-all-folders-and-subfolders | |
""" | |
BASE_DIR = "F:\\Android_9.0\\aosp" | |
def run_cmd(cmd, cwd=None, timeout=60): | |
proc = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE, cwd=cwd, shell=True) | |
try: | |
outs, errs = proc.communicate(timeout=timeout) | |
except subprocess.TimeoutExpired: | |
import os | |
import signal | |
proc.kill() | |
outs = "" | |
return str(outs, "gbk") | |
def set_case_senstive(name, enable=True): | |
flag = "enable" if enable else "disable" | |
cmd = 'fsutil.exe file SetCaseSensitiveInfo "{}" {}'.format(name, flag) | |
print(cmd) | |
outs = run_cmd(cmd) | |
if outs: | |
print(outs) | |
# sys.exit(-1) | |
def set_all_dir(work_dir): | |
all_dirs = os.listdir(work_dir) | |
# print(all_dirs) | |
for d in all_dirs: | |
cur_path = os.path.join(work_dir, d) | |
if os.path.isdir(cur_path) and not d.startswith("."): | |
set_case_senstive(cur_path) | |
set_all_dir(cur_path) | |
if __name__ == "__main__": | |
set_all_dir(BASE_DIR) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment