I am on Windows. This might be a simple question but I don't know how to use the OS module to conduct the following
I have a folder named 'modules' with a few text files. File location:
F = C:\\X\\Data\modules
And within this folder I have about 3000 text files with good and bad reviews about a product in the form of .txt
files.
I also have two .txt
files good.txt
and bad.txt
which have a list of the names of the good and bad reviews.
Location of the files are
good.txt = C:\\X\\Data\good.txt
bad.txt = C:\\X\\Data\bad.txt
For example the file good.txt
looks as follows and contains the names of the good files in the folder modules
.
['cv148_18084.txt', 'cv652_15653.txt', 'cv444_9975.txt', 'c282_6833.txt', 'cv602_8830.txt',
'cv941_10718.txt', 'cv223_28923.txt', 'cv198_19313.txt', 'cv481_7930.txt','cv723_9002.txt',...]
The file bad.txt
also looks the same way with the names of bad reviews about the product.
My doubt being, how do I use these file names and then look through the folder module
and when I find the file segregate it into two other folders called good
and bad
.
Locations being:
Good folder = C:\\X\\Data\good
Bad folder = C:\\X\\Data\bad
How do I use python to complete this task.
I am new to stack and I don't know if I have asked the question in the right format, forgive me for I am still learning.
Thank you for your time, support and effort.
EDIT
I know I must use
>>> os.path.exists(r'C:\\x\\Data\modules\'nameoffile'.txt)
But I do now know how to go through the entire file, good.txt and iterate this process. I also do now know how to save the file in case I find it into the other foder