Spaces:
Runtime error
Runtime error
File size: 2,161 Bytes
30c8b41 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 |
import os
from os import path
def rename_file(old_path, new_path):
"""
νμΌ μ΄λ¦μ μμ νλ ν¨μ
Parameters:
old_path (str): νμΌ κ²½λ‘ + κΈ°μ‘΄ νμΌ μ΄λ¦
new_path (str): νμΌ κ²½λ‘ + μμ ν νμΌ μ΄λ¦
Changes:
old_path > new_path
"""
if path.exists(new_path)==False:
if path.exists(old_path):
# νμΌμ΄ μλ λλ ν 리 κ²½λ‘ μ»κΈ°
src = path.realpath(old_path)
# μλ³ΈνμΌ νμΌλͺ
λ³κ²½
os.rename(old_path,new_path)
else:
print("{old_path} doesn't exist")
def extract_text_from_filename(filename):
"""
νμΌ μ΄λ¦μμ 'x'μ 'y' μ¬μ΄μ ν
μ€νΈμ 'y'μ 'w' μ¬μ΄μ ν
μ€νΈλ₯Ό μΆμΆνλ ν¨μ
ex) x10y148w157h184.jpg
Parameters:
filename (str): νμΌ μ΄λ¦
Returns:
tuple: 'x'μ 'y' μ¬μ΄μ ν
μ€νΈ, 'y'μ 'w' μ¬μ΄μ ν
μ€νΈ
"""
start_x = filename.index('x')
end_x = filename.index('y')
start_y = end_x + 1
end_y = filename.index('w')
x_text = filename[start_x+1:end_x]
y_text = filename[start_y:end_y]
return x_text, y_text
def get_folder_contents_with_text(folder_path, file_extension=".jpg"):
"""
ν΄λ λ΄λΆμ νμΌλ€μ μ΄λ¦μμ 'x'μ 'y' μ¬μ΄μ ν
μ€νΈλ₯Ό 리μ€νΈ xμ,
'y'μ 'w' μ¬μ΄μ ν
μ€νΈλ₯Ό 리μ€νΈ yμ κ°κ° μ μ₯νλ ν¨μ
Parameters:
folder_path (str): ν΄λ κ²½λ‘
file_extension (str, optional): κ°μ Έμ¬ νμΌμ νμ₯μ (κΈ°λ³Έκ°: ".jpg")
Returns:
list, list: 'x'μ 'y' μ¬μ΄μ ν
μ€νΈλ₯Ό μ μ₯ν 리μ€νΈ x,
'y'μ 'w' μ¬μ΄μ ν
μ€νΈλ₯Ό μ μ₯ν 리μ€νΈ y
"""
x_list = []
y_list = []
folder_contents = os.listdir(folder_path)
print(folder_contents)
jpg_files = [filename for filename in folder_contents if filename.endswith('jpg')]
for jpg_file in jpg_files:
x_text, y_text = extract_text_from_filename(jpg_file)
x_list.append(x_text)
y_list.append(y_text)
return x_list, y_list, jpg_files |