Hi. I am totally new to python. I have a problem that I have been trying to solve without any form of solution.
I have a group of files in Directory A that are named like:

Text__###__TEXT___###.tif

These are dummy files.

The real files are in Directory B and are named like:
00001.tif
00002.tif
00003.tif
and so on...
These files are the ones that have important images.

The problem is I need to take the names of the images in Directory A and apply them to the images in Directory B.

Any ideas?
Thanks.

The problem is I need to take the names of the images in Directory A and apply them to the images in Directory B.

What does this mean? Rename a file with some unknown name combination? See if a name in is both dirs?

Welcome to my job buddy. LOL. Maybe the Text__###__TEXT___###.tif was a bad example. But it is close to what they need to be named. Its a Hollerith code style naming pattern.
Anyway, those names need to be transfered to the real images which were named 0001, 0002,etc.

import os
folderA = []
for path, dirs, files in os.walk("C:\\Folder A"):
   for f in files:
      folderA.append(f)

i = 0

for path, dirs, files in os.walk("C:\\Folder B"):
   for f in files:
      os.rename(f, folderA[i])
      i += 1

Something like that should work nicely for you. Not tested so if it doesn't work just post back xD

Chris

Chris, you forgot the escape the forward slashes in your example with the directories :P

Cwolfraven, don't forget to use "\\", for every directory name.

lol thanks for pointing that out, i've updated it to avoid confusion. In actually fact although it is bad, in that example it will work fine. The only time you will have a problem with that is if you do something liek "C:\", which will be obvious when you do it that it is an error.

Chris

Yeah, that example works well enough for a solution.

My friend used to always forget to escape. After he learned that, he went on to url's. He was extremely confused, mixing up backspaces along with forwardspaces, and all he needed was a simple backslash :P

Thanks, Chris. I'll try it out when I get back to work on Wednesday. I'm currently in the hospital with my wife and new 8 lbs. baby boy!!
I'll post back on how it works.

Hope it works for you, like i say we can always change it.

Congratulations, with the new born.

Chris

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.