-4

How can I check if a physical file is located in index file?

For example:

Let's say we have 5 files in the folder C:\Users.

I have a file with a link to this location

C:\Users\1.txt C:\Users\2.txt C:\Users\3.txt C:\Users\4.txt

We can see that we are missing 1 file from C:\Users in that index file?

How can I do it? If you could give me some way to do it, it would be great. Is it even possible to do such thing?

Juan T
  • 1,219
  • 1
  • 10
  • 21
Sam
  • 1,206
  • 2
  • 12
  • 27
  • 1
    So what's the problem? Reading filenames from a file? Checking if a specific name exists in a directory? – timgeb Mar 23 '17 at 15:49
  • I want to check if a index file has all index from physical file location. For example if C:\Users\ has 2 file. I want to make sure it is in a index file location.txt. – Sam Mar 23 '17 at 15:50
  • Yes and I want to know what the problem is. Your question will get downvoted/ignored/closed if you don't state at what specific part you have run into a problem. – timgeb Mar 23 '17 at 15:53
  • I think I just realized how I can solve it. I can read each file in that location create a index file and compare? Thanks. – Sam Mar 23 '17 at 15:56

1 Answers1

0
path = "C:\Users"
for file_item in os.listdirs(path):
    file_item_full = path + "/" + file_item
    #check if the file_item_full name exists in the index file

i would do it like this, you can first read the file and add all lines in a list so you are not reading all the times the index file.

Ivan
  • 782
  • 11
  • 23