file-rename

Python program to rename files doesn't work on files on external drives

Python program to rename files doesn't work on files on external drives Question: I wrote this program to rename all files in a directory to title case, and it works fine on files on the system. But when I use it to rename files on an external drive, the program executes successfully without any exceptions …

Total answers: 1

How to change file name in a folder based on a DataFrame column

How to change file name in a folder based on a DataFrame column Question: I have a folder consists several files in the directory E:folder and looks like the following. -folder -old1.jpg -old2.jpg -old3.jpg -… and I would like to change the name of these files based on the dataframe df column "new_name". new_name abc1 …

Total answers: 1

Add Two Zeroes in front of file sequence number

Add Two Zeroes in front of file sequence number Question: I’m fairly new to python and I want to format my filenaming with an extra two zeros infront for single digit and a single zero for 2 digit numbers depending on the file sequence. My current file naming just renames my file like ex. 1930L1.mp3 …

Total answers: 2

Python add prefix to file names inside a directory

Python add prefix to file names inside a directory Question: I need to add a prefix to file names within a directory. Whenever I try to do it though, it tries to add the prefix to the beginning of the file path. That won’t work. I have a few hundred files that I need to …

Total answers: 2

Change the file name by using python

Change the file name by using python Question: I would like to change the file name in the folder, there are jpg file but corrupted with product id number. I tried to rename it and delete the string after ".jpg" by using python, here is the code, but there is no any change. Do you …

Total answers: 1

ValueError: not enough values to unpack (expected 2, got 1) when splitting strings

ValueError: not enough values to unpack (expected 2, got 1) when splitting strings Question: I’ve tried to write a script that moves files from one folder to a selection of folders depending on what I have named the file. For example, ‘Physics – a’ would be moved from the ‘ts’ folder to ‘/Physics/Assignments’ in an …

Total answers: 4

Rename and move file with Python

Rename and move file with Python Question: I have a Python script that compares existing file names in a folder to a reference table and then determines if it needs to be renamed or not. As it loops through each filename: ‘oldname’ = the current file name ‘newname’ = what it needs to be renamed …

Total answers: 5

batch renaming 100K files with python

batch renaming 100K files with python Question: I have a folder with over 100,000 files, all numbered with the same stub, but without leading zeros, and the numbers aren’t always contiguous (usually they are, but there are gaps) e.g: file-21.png, file-22.png, file-640.png, file-641.png, file-642.png, file-645.png, file-2130.png, file-2131.png, file-3012.png, etc. I would like to batch process …

Total answers: 7

Enforce unique upload file names using django?

Enforce unique upload file names using django? Question: What’s the best way to rename photos with a unique filename on the server as they are uploaded, using django? I want to make sure each name is used only once. Are there any pinax apps that can do this, perhaps with GUID? Asked By: zjm1126 || …

Total answers: 7

How to rename a file using Python

How to rename a file using Python Question: I want to change a.txt to b.kml. Asked By: zjm1126 || Source Answers: import shutil shutil.move(‘a.txt’, ‘b.kml’) This will work to rename or move a file. Answered By: Andy Balaam Use os.rename: import os os.rename(‘a.txt’, ‘b.kml’) Usage: os.rename(‘from.extension.whatever’,’to.another.extension’) Answered By: YOU os.rename(old, new) This is found in …

Total answers: 17