1 | initial version |
In Linux, you can use the rename
command to delete strings from multiple filenames. Here’s an example:
If you want to remove the string “_old” from all the filenames in a directory, you can use the following command:
rename 's/_old//' *
This command will replace “_old” with nothing in all filenames in the current directory.
In Python, you can use the os
module to rename files. Here’s an example:
import os
directory = "/your/directory/path/"
for filename in os.listdir(directory):
if "_old" in filename:
new_filename = filename.replace("_old", "")
os.rename(directory + filename, directory + new_filename)
This Python code will check all the filenames in the directory specified by directory
and remove “_old” from filenames that contain it. The modified filename is then used to rename the file using the os.rename
function.