bare functionality
This commit is contained in:
parent
6100ccad12
commit
7abbbec69f
49
main.py
49
main.py
|
|
@ -2,22 +2,49 @@
|
||||||
import os
|
import os
|
||||||
import sys
|
import sys
|
||||||
|
|
||||||
def get_file_list(path):
|
def reduce_string(string, min_len):
|
||||||
'''present a list of files'''
|
versions = []
|
||||||
os.li
|
for i in range(min_len, len(string) + 1):
|
||||||
return None
|
versions.append(string[:i])
|
||||||
|
versions.reverse()
|
||||||
|
return versions
|
||||||
|
|
||||||
def maximum_common_string(string, listofstrings, minimum_length):
|
def maximum_common_string(listofstrings, min_len):
|
||||||
'''compare items of a list, grouping by common strings, keeping groups as small as possible'''
|
'''compare items of a list, grouping by common strings, keeping groups as small as possible'''
|
||||||
return None
|
for filepath in listofstrings:
|
||||||
|
base = os.path.splitext(os.path.basename(filepath))[0]
|
||||||
|
string_versions = reduce_string(base, min_len)
|
||||||
|
for string in string_versions:
|
||||||
|
common_strings = [x for x in listofstrings if string in x]
|
||||||
|
if len(common_strings) > 2:
|
||||||
|
return (string, common_strings)
|
||||||
|
return
|
||||||
|
|
||||||
def move_files_into_directory(files, directory):
|
def safe_move(files, directory):
|
||||||
return None
|
if not os.path.exists(directory):
|
||||||
|
os.makedirs(directory)
|
||||||
|
for item in files:
|
||||||
|
newPath = os.path.join(directory, item)
|
||||||
|
if not os.path.exists(newPath):
|
||||||
|
currentPath = os.path.join(os.path.dirname(directory), item)
|
||||||
|
print(f"moving {os.path.join(os.path.dirname(directory), item)} to {os.path.join(directory, item)}")
|
||||||
|
os.rename(currentPath, newPath)
|
||||||
|
else:
|
||||||
|
print("file exists, skipping")
|
||||||
|
return
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
filepaths = os.listdir(sys.argv[1])
|
if len(sys.argv) > 1:
|
||||||
print(filepaths)
|
workingPath = os.path.abspath(sys.argv[1])
|
||||||
return None
|
else:
|
||||||
|
print("need directory")
|
||||||
|
sys.exit()
|
||||||
|
filepaths = os.listdir(workingPath)
|
||||||
|
while strings := maximum_common_string(filepaths, 6):
|
||||||
|
for x in strings[1]:
|
||||||
|
filepaths.pop(filepaths.index(x))
|
||||||
|
safe_move(strings[1], os.path.join(workingPath, strings[0]))
|
||||||
|
return
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
main()
|
main()
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue