๋ฐ์ํ
ํด๋น ๊ฒฝ๋ก์ ๋๋ ํ ๋ฆฌ๋ฅผ list ํํ๋ก ๋ฐํ
os.listdir(path)
Data๋ฅผ ํฌํจํ๋ ํ์ผ๋ช ์ฐพ๊ธฐ
file_name = [s for s in files if "Data" in s]
with os.scandir(path) as files:
for file in files:
print(file.name)
ํ์ผ ๋ณต์ฌ ํ๊ธฐ
ํ์ผ์ ๋ณต์ฌํ๋ copyfile, copy, copy2 ํจ์๋ ๊ธฐ๋ณธ์ ์ธ ์ฌ์ฉ๋ฐฉ๋ฒ์ ๊ฐ์ต๋๋ค.
import shutil
shutil.copyfile("./test1/test1.txt", "./test2.txt")
shutil.copy("./test1/test1.txt", "./test3.txt")
shutil.copy2("./test1/test1.txt", "./test4.txt")
copyfile๊ณผ copy๋ ๋ฉํ์ ๋ณด๋ ๋ณต์ฌ๋์ง ์์ต๋๋ค.
copy2๋ ๋ฉํ์ ๋ณด๋ ๋ณต์ฌํฉ๋๋ค.
์ฆ, copy2๋ฅผ ์ฌ์ฉํ๋ฉด ํ์ผ์ ์์ฑํ ๋ ์ง๋ ๋ณต์ฌ๋์ง๋ง copyfile๊ณผ copy๋ ํ์ผ์ ์์ฑํ ๋ ์ง๊ฐ ๋ณต์ฌํ ๋ ์ง๋ก ๋ณ๊ฒฝ๋ฉ๋๋ค.
https://blog.naver.com/hankrah/221826518915
https://blog.naver.com/hankrah/221829206710
https://ponyozzang.tistory.com/439
๋ฐ์ํ
'Python > Basic' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
[Python] Pillow ์ด๋ฏธ์ง ์ฌ์ด์ฆ ํ์ธ (0) | 2022.08.06 |
---|---|
[Python] PDF ๊ด๋ จ ํจํค์ง ์ ๋ฆฌ (0) | 2022.08.05 |
[Python] Excel, Word ๋ค๋ฃจ๊ธฐ (0) | 2021.07.26 |
[Python] XlsxWriter - Excel ๋ค๋ฃจ๊ธฐ (0) | 2021.07.26 |
[Python] sqlalchemy, json์ผ๋ก ๋ณ๊ฒฝ ํ ๋ฆฌํด (2) | 2021.04.16 |