0

I am trying to move the contents from one folder to another while excluding some types of files. The script used so far,

OD_daily_files = "C:\\Users\\" + checkuser + "\\Gas South\\SRM Team - General\\Risk Management\\Storage\\EBB Downloads\\Daily_Files"
SD_daily_files = "S:\\Supply\\Risk Management\\Daily auto downloads\\Storage\\Daily_Files"
files = os.listdir(OD_daily_files)
 for x in files:
 shutil.copytree(OD_daily_files + "\\" + x, SD_daily_files, 
 ignore=ignore_patterns('File_Examples*', '*.lnk', '*.pptx', '*.accdb', '*.bat'))

I keep getting the following error,

NotADirectoryError: [WinError 267] The directory name is invalid: 'C:\\Users\\GAS02224\\Gas South\\SRM Team - General\\Risk Management\\Storage\\EBB Downloads\\Daily_Files\\Access_Storage_Rev7.bat'

This file is in that directory/folder.

asked Sep 29, 2022 at 21:19

2 Answers 2

0

Use r-string.

OD_daily_files = r"C:\\Users\\" + checkuser + r"\\Gas South\\SRM Team - General\\Risk Management\\Storage\\EBB Downloads\\Daily_Files"
SD_daily_files = r"S:\\Supply\\Risk Management\\Daily auto downloads\\Storage\\Daily_Files"
files = os.listdir(OD_daily_files)
 for x in files:
 shutil.copytree(OD_daily_files + "\\" + x, SD_daily_files, 
 ignore=ignore_patterns('File_Examples*', '*.lnk', '*.pptx', '*.accdb', '*.bat'))
answered Sep 29, 2022 at 21:34
Sign up to request clarification or add additional context in comments.

1 Comment

I had tried that and it had given the below error, NotADirectoryError: [WinError 267] The directory name is invalid: 'C:\\\\Users\\\\GAS02224\\\\Gas South\\\\SRM Team - General\\\\Risk Management\\\\Storage\\\\EBB Downloads\\\\Daily_Files\\Access_Storage_Rev7.bat'
0

This was solved with the below code,

if checkuser != "ROBOT":
 OD_daily_files = "C:\\Users\\" + checkuser + "\\Gas South\\SRM Team - General\\Risk Management\\Storage\\EBB Downloads\\Daily_Files"
 SD_daily_files = "S:\\Supply\\Risk Management\\Daily auto downloads\\Storage\\Daily_Files"
 files = os.listdir(OD_daily_files)
 for x in files:
 try:
 shutil.copy(OD_daily_files + "\\" + x, SD_daily_files)
 print(x + " file was copied over to the S Drive.")
 except:
 print("")
 print(x + " file and/or folder was not copied over.")
 print("")
 next 
answered Sep 30, 2022 at 15:34

Comments

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.