-2

I have this file in the following path:

A = I:\user\me\count.txt

I want to check whether or not the count.txt exists in another path because I want to tag them as existing in the other folder.

As an example, lets say:

path1 = I:\user\me\personal\
path2 = I:\user\me\work\
  • Welcome to SO - please add some attempt what you did and why it failed. Perhaps have a look at [ask] and [mcve]. And you definitely should describe clearly your expected result. Do you just want to know if there's a file with the same name in those other folders or do you want to verify e.g. equality in date and size before deciding to draw any consequences from the computed information? – SpghttCd Oct 06 '19 at 13:00

2 Answers2

0

You can check if file in path:

import os
isFile = os.path.isfile('/your_path/file.txt') 

Will return true if file exists in {/your_path}

Martín Alcubierre
  • 4,341
  • 1
  • 27
  • 27
0

Assuming you are using two variables pointing to the folders, you can do the following:

import os.path

filename = "count.txt"
path1 = "I:/user/me/personal/"
path2 = "I:/user/me/work/"

if path.isfile(path.join(path1, filename)) and path.isfile(path.join(path2, filename)):
    # Do something

This checks if a file count.txt exists in the folder I:/user/me/personal and I:/user/me/work and acts if found in both

If you would like to find files and folders named count.txt, you may substitute path.isfile with path.exists.