Matching Duplicate file names with different extentions - Printable Version +- Python Forum (https://python-forum.io) +-- Forum: Python Coding (https://python-forum.io/forum-7.html) +--- Forum: General Coding Help (https://python-forum.io/forum-8.html) +--- Thread: Matching Duplicate file names with different extentions (/thread-4315.html) |
Matching Duplicate file names with different extentions - wmc326 - Aug-07-2017 Hi all, I'm relatively new to python and need some help with creating a script that is able to pair duplicate file names with different extensions. For example, say I have a image named 'test1.jpg' and a text file with description of that image named 'test1.txt' and multiple files just like that, with different numbers. How can i group the two and make a new folder each time there is a match? So with a match for 'test1' there would be a folder named test1, which would include the image and text file. I have done a little research but have been unable to find anything I can use. Let me know what this would look like or direct me to a link that explains how to do this please Thanks in advance! RE: Matching Duplicate file names with different extentions - ichabod801 - Aug-07-2017 I would look at the os module and the glob module. They should have the tools you need to do this. RE: Matching Duplicate file names with different extentions - wavic - Aug-07-2017 glob.glob(pattern) will return a list of file names matching that pattern. You can use it to check for each of this file but with .txt extension. If it exists - os.path.exists('test99.txt') for example. If that happens use os.mkdir() to create a directory with a proper name and move the files there - os.rename(). |