|
import os
|
|
|
|
def process_path(input_path):
|
|
|
|
path_elements = input_path.split('\\')
|
|
directory = '\\'.join(path_elements[:-1])
|
|
filename = path_elements[-1]
|
|
if '.' in filename:
|
|
input_path = input_path.replace(f'\\{filename}','')
|
|
return input_path
|
|
else:
|
|
return input_path
|
|
|
|
def generate_datas(direktori_input):
|
|
datas = []
|
|
for root, dirs, files in os.walk(direktori_input):
|
|
for file in files:
|
|
file_path = os.path.join(root, file)
|
|
relative_path = os.path.relpath(file_path, direktori_input)
|
|
datas.append((file_path, process_path(file_path)))
|
|
|
|
return datas
|
|
|
|
def write_to_file(datas, output_file):
|
|
with open(output_file, 'w') as file:
|
|
for data in datas:
|
|
file.write(f"('{data[0]}', '{data[1]}'),\n")
|
|
|
|
|
|
direktori_input = 'qiskit'
|
|
output_file = 'qiskit.txt'
|
|
|
|
result_datas = generate_datas(direktori_input)
|
|
write_to_file(result_datas, output_file) |