Hi All,
I have a task in Python where I need to move .csv files into a new folder. I tried using the below code but it was throwing me an error.
import shutil
import os
source = os.listdir(r'C:\Users\mchalla\PycharmProjects\837_unzip\venv\SampleUnzipFiles\SampleZipFiles/')
destination = 'C:\Users\mchalla\PycharmProjects\837_unzip\venv\SampleUnzipFiles\DelimitedFiles'
for files in source:
if files.endswith("_new.csv"):
shutil.move(files,destination)
Error Message:
C:\Users\mchalla\PycharmProjects\837_unzip\venv\Scripts\python.exe C:/Users/mchalla/PycharmProjects/837_unzip/MoveFilesToNewFolder.py
File "C:/Users/mchalla/PycharmProjects/837_unzip/MoveFilesToNewFolder.py", line 4
destination = 'C:\Users\mchalla\PycharmProjects\837_unzip\venv\SampleUnzipFiles\DelimitedFiles'
^
SyntaxError: (unicode error) 'unicodeescape' codec can't decode bytes in position 2-3: truncated \UXXXXXXXX escape
Process finished with exit code 1
Could someone please help me to solve this issue?
Thank you!
Mamatha_1
rproffitt 2,662 "Nothing to see here." Moderator
Mamatha_1
rproffitt 2,662 "Nothing to see here." Moderator
ryantroop 177 Practically a Master Poster
Be a part of the DaniWeb community
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.