In the folder
test0.tif, test1.tif, test2.tif, test3.tif, test4.tif, test5.tif, test6.tif
File name, such as
test_x0_y0, test_x1_y0, test_x2_y0, test_x0_y1, test_x1_y1, test_x2_y1, test_x0_y2
I want to express it using two serial numbers.
In the code below, you can serialize only x like test_x0.tif, test_x1.tif, test_x2.tif, but if you try to include the serial number of y, it will not work.
# Get a file with a .txt extension
path ='test/filename/*. Tif'
i = 000
# Get a tif file
flist = glob.glob (path)
print ('before change')
print (flist)
#Rename files all at once
for i, file in enumerate (flist):
os.rename (file,'test/filename/test_x' + str (i) +'.tif')
list = glob.glob (path)
print ('after change')
print (list)
You can enter values for x and y using the following loop, but I don't know how to apply it to the above code.
for i in range (2):
for j in range (2):
print ("x" + str (i) + "y" + str (j))
I would appreciate it if you could answer. Thank you.
Added below
___
Regarding the range of x and y, if there are 12 files in one example, we would appreciate it if you could answer with x as the range of 0 to 3 and y as the range of 0 to 2.
This range depends on the data, so I would like you to be able to set it to that range if you enter the number yourself.
-
Answer # 1
-
Answer # 2
If the number of divisions of x is 4 (from 0 to 3), the number attached to x is
i% 4
, The numbers attached to y arei // 4
Since it is calculated by, a variable so that the number of divisions can be changedx_div
Set tox_div = 4 for i, file in enumerate (flist): print (f "test_x {i% x_div} _y {i // x_div} .tif")
The file name after renaming is decided as follows. After that, add a directory etc. to this
os.rename
Please specify in.
Related articles
- python - i want to change the value of the list using a function
- about external libraries when using multiple versions of python
- python - about the display screen using django
- python - about the fibonacci sequence using recursion
- about data acquisition using python from becoming a novelist
- python - about scraping using selenium
- python - about deep learning programs using keras
- i want to change the row value using the value of the previous row in python: pandasdataframe
- python - i'm not sure about add_axes in matplotlib
- about decoding with python opencv
- python - about the average value calculation method of mass calculation
- error when using t-sne python
- python - about the implementation of fibonacci sequence
- python 3x - when splitting data using iloc, settingwithcopywarning appears even if copy () is added
- specifying the range of the graph using python date
- python: about loops in leap motion programs
- python 3x - about return code of python3 subprocess
- python - aggregation processing using pandas
- about python ctypesstructure
- python - you may need to restart the kernel to use updated packages error
- dart - flutter: the instance member'stars' can't be accessed in an initializer error
- php - coincheck api authentication doesn't work
- php - i would like to introduce the coincheck api so that i can make payments with bitcoin on my ec site
- [php] i want to get account information using coincheck api
- the emulator process for avd pixel_2_api_29 was killed occurred when the android studio emulator was started, so i would like to
- javascript - how to check if an element exists in puppeteer
- sh - 'apt-get' is not recognized as an internal or external command, operable program or batch file
- i want to check the type of a shell script variable
- i want to call a child component method from a parent in vuejs
How about the following?