๋ณธ๋ฌธ ๋ฐ”๋กœ๊ฐ€๊ธฐ

Python/Basic

[Python] ํŒŒ์ผ ๊ด€๋ จ

๋ฐ˜์‘ํ˜•

 

 

ํ•ด๋‹น ๊ฒฝ๋กœ์˜ ๋””๋ ‰ํ† ๋ฆฌ๋ฅผ 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

 

024 ํŒŒ์ด์ฌ ํŒŒ์ผ ๋‹ค๋ฃจ๊ธฐ - 02. ๋””๋ ‰ํ† ๋ฆฌ ๋ฆฌ์ŠคํŠธ

#ํŒŒ์ด์ฌ #python #ํŒŒ์ผ๋‹ค๋ฃจ๊ธฐ #ํŒŒ์ผ #file #open #read #write #readline #readlines #seek #file_pointer ...

blog.naver.com

 

 

https://blog.naver.com/hankrah/221829206710

 

027 ํŒŒ์ด์ฌ ํŒŒ์ผ ๋‹ค๋ฃจ๊ธฐ - 05. ํŒŒ์ผ๋ช… ํŒจํ„ด ๋งค์นญ

#ํŒŒ์ด์ฌ #python #ํŒŒ์ผ๋‹ค๋ฃจ๊ธฐ #ํŒŒ์ผ #file #open #read #write #readline #readlines #seek #file_pointer ...

blog.naver.com

 

https://ponyozzang.tistory.com/439

 

Python ํŒŒ์ผ, ํด๋” ๋ณต์‚ฌ(shutil) ์‚ฌ์šฉ ๋ฐฉ๋ฒ• ์˜ˆ์ œ

ํŒŒ์ผ์„ ๋ณต์‚ฌํ•˜๊ฑฐ๋‚˜ ํด๋”๋ฅผ ๋ณต์‚ฌํ•˜๊ณ  ์‹ถ์€ ๊ฒฝ์šฐ๊ฐ€ ์žˆ์Šต๋‹ˆ๋‹ค. copyfile, copy, copy2 ํ•จ์ˆ˜๋ฅผ ์‚ฌ์šฉํ•ด์„œ ๋ณต์‚ฌ๊ฐ€ ๊ฐ€๋Šฅํ•ฉ๋‹ˆ๋‹ค. ํ•˜์ง€๋งŒ ์กฐ๊ธˆ์”ฉ ์ฐจ์ด๊ฐ€ ์žˆ์Šต๋‹ˆ๋‹ค. ํŒŒ์ผ ๋ณต์‚ฌ ํ•˜๊ธฐ ํŒŒ์ผ์„ ๋ณต์‚ฌํ•˜๋Š” copyfile, copy,

ponyozzang.tistory.com

 

๋ฐ˜์‘ํ˜•