python copy file create intermediate directories 1

python copy file create intermediate directories

os.makedirs(os.path.dirname(dest_fpath), exist_ok=True)
shutil.copy(src_fpath, dest_fpath)

Here is what the above code is Doing:
1. Create a new directory called ‘data’ in the current directory.
2. Create a new directory called ‘data/raw’ in the current directory.
3. Create a new directory called ‘data/processed’ in the current directory.
4. Copy the file ‘data/raw/raw_data_2020.01.01.csv’ to ‘data/processed/processed_data_2020.01.01.csv’.

Similar Posts