2021-02-14, 03:38
Hi All,
Im creating a very simple addon to rename and move files from one folder to another.
So far I have printed the list of the new filenames but now need to rename them based on the list.
Here is a what I have so far.
Files are for example
[Dog]test 2021-04-01 22-12-01.txt
[Dog]test2 2021-02-01 22-22-01.txt
[Dog]test3 2020-05-01 22-23-21.txt
[Dog]test4 2020-02-07 22-22-31.txt
and i need
test.txt
test2.txt
test3.txt
test4.txt
import os
source_dir = "C:\\Users\\ED\\Desktop\\testsource"
target_dir = "C:\\Users\\ED\\Desktop\\testdest"
data = os.listdir(source_dir)
print(data)
new_data = [file[8:].split(' 2021')[0] + '.txt' for file in data]
print(new_data)
Im creating a very simple addon to rename and move files from one folder to another.
So far I have printed the list of the new filenames but now need to rename them based on the list.
Here is a what I have so far.
Files are for example
[Dog]test 2021-04-01 22-12-01.txt
[Dog]test2 2021-02-01 22-22-01.txt
[Dog]test3 2020-05-01 22-23-21.txt
[Dog]test4 2020-02-07 22-22-31.txt
and i need
test.txt
test2.txt
test3.txt
test4.txt
import os
source_dir = "C:\\Users\\ED\\Desktop\\testsource"
target_dir = "C:\\Users\\ED\\Desktop\\testdest"
data = os.listdir(source_dir)
print(data)
new_data = [file[8:].split(' 2021')[0] + '.txt' for file in data]
print(new_data)