I have PNG and JSON files on a folder whose names are numbered from 1 to 1000. In other words, I have 2000 files. The PNG files match the JSON files by the number in their names. For example, the information of 15.png is in 15.json. What I want to do is randomly rename these files while maintaining the association of the png files to the json files. For instance, I would like to rename 15.png to 321.png and that would mean renaming 15.json to 321.json. To prevent using a number that is already in the folder, it would be better to copy both the png and its json to a new folder and then assigning a random number/name (between 1 and 1000) for both files and repeating the process. I have tried using the .split, .startswith and . endwith functions but am having difficulty. Any insight is much appreciated.
Associating PNG FileNames With JSON FileNames and Randomizing
24 Views Asked by Nilo dos Santos Orlandi At
1
There are 1 best solutions below
Related Questions in PYTHON
- How to store a date/time in sqlite (or something similar to a date)
- Instagrapi recently showing HTTPError and UnknownError
- How to Retrieve Data from an MySQL Database and Display it in a GUI?
- How to create a regular expression to partition a string that terminates in either ": 45" or ",", without the ": "
- Python Geopandas unable to convert latitude longitude to points
- Influence of Unused FFN on Model Accuracy in PyTorch
- Seeking Python Libraries for Removing Extraneous Characters and Spaces in Text
- Writes to child subprocess.Popen.stdin don't work from within process group?
- Conda has two different python binarys (python and python3) with the same version for a single environment. Why?
- Problem with add new attribute in table with BOTO3 on python
- Can't install packages in python conda environment
- Setting diagonal of a matrix to zero
- List of numbers converted to list of strings to iterate over it. But receiving TypeError messages
- Basic Python Question: Shortening If Statements
- Python and regex, can't understand why some words are left out of the match
Related Questions in RENAME
- Use sed or rename find series of alphabet then replace with with the same alphabet and a dash -
- Macro to copy, rename and organize a template worksheet
- Mapping to rename a single column label with a function?
- How to rename columns with pattern in R?
- Rename a file before uploading using plupload.Uploader code and remove file from queue not working
- Crystal report export functionality change pdf name
- MySQLdb.OperationalError: and django.db.utils.OperationalError 1054, "Unknown column" after field rename in Django and MySql
- How to rename file name in Linux using the command "rename"?
- purrr::set_names using pipe operator in R
- Is this the most performant way to rename a Polars DF column?
- I was trying to rename a CSV file in the same folder as "(today's date).csv" but I am getting path specified errors
- A bash script for replacing patterns in multiple files names based on a 2-column mapping file
- Remove elements of a named list based on the naming match in R
- Modify the names of a named list in R based on a logic
- Refactor / Rename does not update View Binding references in java
Related Questions in COPYING
- how to convert backslash to forward slash in path name on gcp using python
- EWS Operation Item.Copy fails with 'full_access_as_app' permission
- Operator overload = not copying to 2nd variable-object
- Associating PNG FileNames With JSON FileNames and Randomizing
- Copying address of one array into another
- How to copy a variable to blank observations by other variables
- How can I repeat complex element multiple times on the same page?
- Linux sendfile()/splice() alternative for FreeBSD?
- Copying data with small changes in SQL Server
- Copying delegates behavior
- Alternative for python shutils.copytree?
- 'rb') as f: PermissionError: [Errno 13] Permission denied
- Copy folder from container to host after docker run
- Copying objects in js (need guidance on pass by reference from docs)
- Is there a way to loop copying values in R?
Trending Questions
- UIImageView Frame Doesn't Reflect Constraints
- Is it possible to use adb commands to click on a view by finding its ID?
- How to create a new web character symbol recognizable by html/javascript?
- Why isn't my CSS3 animation smooth in Google Chrome (but very smooth on other browsers)?
- Heap Gives Page Fault
- Connect ffmpeg to Visual Studio 2008
- Both Object- and ValueAnimator jumps when Duration is set above API LvL 24
- How to avoid default initialization of objects in std::vector?
- second argument of the command line arguments in a format other than char** argv or char* argv[]
- How to improve efficiency of algorithm which generates next lexicographic permutation?
- Navigating to the another actvity app getting crash in android
- How to read the particular message format in android and store in sqlite database?
- Resetting inventory status after order is cancelled
- Efficiently compute powers of X in SSE/AVX
- Insert into an external database using ajax and php : POST 500 (Internal Server Error)
Popular # Hahtags
Popular Questions
- How do I undo the most recent local commits in Git?
- How can I remove a specific item from an array in JavaScript?
- How do I delete a Git branch locally and remotely?
- Find all files containing a specific text (string) on Linux?
- How do I revert a Git repository to a previous commit?
- How do I create an HTML button that acts like a link?
- How do I check out a remote Git branch?
- How do I force "git pull" to overwrite local files?
- How do I list all files of a directory?
- How to check whether a string contains a substring in JavaScript?
- How do I redirect to another webpage?
- How can I iterate over rows in a Pandas DataFrame?
- How do I convert a String to an int in Java?
- Does Python have a string 'contains' substring method?
- How do I check if a string contains a specific word?
I can't tell if this is the most elegant or performant way to do it, but you could try the following:
To move your json files too, you only have to add one line to the loop, but I'll leave it to you to figure that one out. It involves the .with_suffix-method that is available on Path-objects.