Python Forum
changing characters in multiple strings in a list
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
changing characters in multiple strings in a list
#1
[b] I should added that I also need to change the file names in for example:

CT.1.2.840.113704.1.111.3056.1158834679
CT.1.2.840.113704.1.111.3056.1158834678
CT.1.2.840.113704.1.111.3056.1158834677
.
.
.
To these file names

CT-174-0001
CT-174-0002
CT-174-0003
.
.
.

This is a harder problem. Appreciate any help on both posts. Thanks ['/b]
Reply
#2
In what basis you want to rename to these files. i dont see any relation between original files and renamed files
Reply
#3
What have you tried?
We do not write solution without any effort.
(Feb-22-2018, 11:19 PM)newmanf Wrote: This is a harder problem.
It's not a hard problem,do just want a counter 0001 0002?
As asked bye @kannanv110 is there any relation between original files and renamed files.
Reply
#4
Sorry I have tried many things. I'm a neophyte at Python. Here is one code example just to see if something will get me close. Yes there is a relation between the original files and new files. There are many more files like this. I simply want some uniformity in the file names to they can be accessed in a more orderly way.

import os
os.chdir('C:\\Users\\franc\\Desktop\\CT-INSPIRIUM-8871')
for fileName in os.listdir("."):
 
    if fileName.startswith("CT"):
        i=1
        os.rename(fileName, fileName.replace("8871-*", "001" +i))
        
        i=i+1
So for example I need the 3rd file to be CT.174.003 (CT is the type of image, 174 is the patient number and 003 is the image number.)

I meant CT-174-003
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  How to read module/class from list of strings? popular_dog 1 422 Oct-04-2023, 03:08 PM
Last Post: deanhystad
  Trying to understand strings and lists of strings Konstantin23 2 696 Aug-06-2023, 11:42 AM
Last Post: deanhystad
  problem in using int() with a list of strings akbarza 4 646 Jul-19-2023, 06:46 PM
Last Post: deanhystad
  xml indent SubElements (wrapping) with multiple strings ctrldan 2 1,382 Jun-09-2023, 08:42 PM
Last Post: ctrldan
  Delete strings from a list to create a new only number list Dvdscot 8 1,466 May-01-2023, 09:06 PM
Last Post: deanhystad
  Help with Logical error processing List of strings dmc8300 3 1,029 Nov-27-2022, 04:10 PM
Last Post: Larz60+
  Splitting strings in list of strings jesse68 3 1,702 Mar-02-2022, 05:15 PM
Last Post: DeaD_EyE
  Search multiple CSV files for a string or strings cubangt 7 7,840 Feb-23-2022, 12:53 AM
Last Post: Pedroski55
  How to combine multiple rows of strings into one using pandas? shantanu97 1 3,096 Aug-22-2021, 05:26 AM
Last Post: klllmmm
  Why changing data in a copied list changes the original list? plumberpy 3 2,190 Aug-14-2021, 02:26 AM
Last Post: plumberpy

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020