I GOT THE ANSWER OF M POST THANKS FOR HELPING ME AND WISH OTHERS LEARN FROM MY MISTAKES GOOD LUCK ALL
I Have Folders that take in .meta files and want to save each filename in variable , all folder take in the same meta file name but I added the folder name into the file with hypthen means -> foldername + '-' + filename
and want to print the file name in each folder into file that I created in specific driver and used os.chdir() to load into file path
so when im going to print each folder meta file name into this file its not saving the var
for dirpath, dirnames, files in os.walk('.') :
print('loop')
for file in files :
print('file')
if file.endswith('.meta'):
print('meta')
METAPath = os.path.abspath(os.path.join(dirpath, file))
METABase = os.path.basename(dirpath)
if True :
if file.startswith(METABase + '-' + 'handling'):
HandlingFile = "'" + file + "'"
return HandlingFile
elif file.startswith(METABase + '-' + 'vehicles'):
VehiclesFile = "'" + file + "'"
return VehiclesFile
elif file.startswith(METABase + '-' + 'carvariations'):
CarVariationsFile = "'" + file + "'"
return CarVariationsFile
elif file.startswith(METABase + '-' + 'carcols'):
CarcolsFile = "'" + file + "'"
return CarcolsFile
elif file.startswith(METABase + '-' + 'dlctext'):
DLCTextFile = "'" + file + "'"
return DLCTextFile
print(HandlingFile, VehiclesFile ,CarVariationsFile ,CarcolsFile ,DLCTextFile)
Error :
Traceback (most recent call last):
File "D:\pythonEx\MyFiveMPython\test.py", line 220, in <module>
Stress_Veh()
File "D:\pythonEx\MyFiveMPython\test.py", line 213, in Stress_Veh
print(HandlingFile, VehiclesFile ,CarVariationsFile ,CarcolsFile ,DLCTextFile)
NameError: name 'HandlingFile' is not defined
Aucun commentaire:
Enregistrer un commentaire