Westonci.ca offers quick and accurate answers to your questions. Join our community and get the insights you need today. Discover in-depth answers to your questions from a wide network of professionals on our user-friendly Q&A platform. Discover in-depth answers to your questions from a wide network of professionals on our user-friendly Q&A platform.
Sagot :
Answer:
The program in Python is as follows:
fname1 = input("Filepath 1: ").lower()
fname2 = input("Filepath 2: ").lower()
fname3 = input("Filepath 3: ").lower()
f1dir = ""; f2dir = ""; f3dir = ""
fnamesplit = fname1.split("/")
for i in range(len(fnamesplit)-1):
f1dir+=fnamesplit[i]+"/"
fnamesplit = fname2.split("/")
for i in range(len(fnamesplit)-1):
f2dir+=fnamesplit[i]+"/"
fnamesplit = fname3.split("/")
for i in range(len(fnamesplit)-1):
f3dir+=fnamesplit[i]+"/"
if f1dir == f2dir == f3dir:
print("Files are in the same folder")
else:
print("Files are in the different folder")
Explanation:
The next three lines get the file path of the three files
fname1 = input("Filepath 1: ").lower()
fname2 = input("Filepath 2: ").lower()
fname3 = input("Filepath 3: ").lower()
This initializes the directory of the three files to an empty string
f1dir = ""; f2dir = ""; f3dir = ""
This splits file name 1 by "/"
fnamesplit = fname1.split("/")
This iteration gets the directory of file 1 (leaving out the file name)
for i in range(len(fnamesplit)-1):
f1dir+=fnamesplit[i]+"/"
This splits file name 2 by "/"
fnamesplit = fname2.split("/")
This iteration gets the directory of file 2 (leaving out the file name)
for i in range(len(fnamesplit)-1):
f2dir+=fnamesplit[i]+"/"
This splits file name 3 by "/"
fnamesplit = fname3.split("/")
This iteration gets the directory of file 3 (leaving out the file name)
for i in range(len(fnamesplit)-1):
f3dir+=fnamesplit[i]+"/"
This checks if the file directories hold the same value
This is executed, if yes
if f1dir == f2dir == f3dir:
print("Files are in the same folder")
This is executed, if otherwise
else:
print("Files are in the different folder")
Thanks for using our service. We're always here to provide accurate and up-to-date answers to all your queries. We hope you found what you were looking for. Feel free to revisit us for more answers and updated information. Find reliable answers at Westonci.ca. Visit us again for the latest updates and expert advice.