I have a question about applying Python for loop file name.

Asked 2 years ago, Updated 2 years ago, 84 views

BL0001, BL0002, BL0003, there are thousands of files like this

I want to spin this specific command and create an output file with the same name.

I was going to make this for loop, but when I designated it as a variable, it became difficult because the variable was in the path designation ''.

print("start")

arcpy.interop.QuickExport(r"C:\InputPath\BL0001", r'3DS,C:\OutputPath\BL0001,"OPTION"')
arcpy.interop.QuickExport(r"C:\InputPath\BL0002", r'3DS,C:\OutputPath\BL0002,"OPTION"')
arcpy.interop.QuickExport(r"C:\InputPath\BL0003", r'3DS,C:\OutputPath\BL0003,"OPTION"')
arcpy.interop.QuickExport(r"C:\InputPath\BL0004", r'3DS,C:\OutputPath\BL0004,"OPTION"')
arcpy.interop.QuickExport(r"C:\InputPath\BL0005", r'3DS,C:\OutputPath\BL0005,"OPTION"') 

## ...

print("end")

All I have to do is change the name of the input-output file, but it looks simple, but it's not as simple as I'm trying to do it.

I'd like to automate this by using LOOP from BL0001 to thousands of times, so please give me some advice.

loops

2022-09-20 15:43

1 Answers

>>> for i in range(10):
    print(f"C:\\InputPath\\BL{i+1:04d}")


C:\InputPath\BL0001
C:\InputPath\BL0002
C:\InputPath\BL0003
C:\InputPath\BL0004
C:\InputPath\BL0005
C:\InputPath\BL0006
C:\InputPath\BL0007
C:\InputPath\BL0008
C:\InputPath\BL0009
C:\InputPath\BL0010


2022-09-20 15:43

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.