Issue
Consider i have 5 files in 5 different location. Example = fileA in XYZ location fileB in ZXC location fileC in XBN location so on
I want to check if these files are actually saved in that location if they are not re run the code above that saves the file.
Ex:
if:
fileA, fileB so on are present in their particular location the proceed with code further
else:
re run the file saving code above
How do i do this in python i am not able to figure out.
Solution
You can store all your file with their locations in a list and then iterate all locations for existance then you can decide further what to do a python example is following
from os.path import exists
#all files to check in different locations
locations = [ '/some/location/xyz/fileA', '/other/location/fileB', '/yet/another/location/fileC' ]
#iterate to check each file existance
status = [exists(location) for location in locations]
#check status of all files if any of the file not exists, else will be called
if(all(status)):
print('All files are present')
else:
print('May be all or any one of them is not actually exist')
Answered By - Zain Ul Abidin
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.