I want to get a list of all subdirectories of a given directory, and
within each directory, change the name of each file using a
predetermined rule.
The function glob in module glob will give me a list of all the
subdirectories, and by looping over this list and repeatedly calling
glob, I can create lists of files within each directory, which are
easily edited to create lists of new filenames.
How then can I change the existing filenames to these new filenames?
What python functions should I be using, and what modules are they
contained in?
Thomas Philips 5 3317
Thomas Philips wrote: How then can I change the existing filenames to these new filenames? What python functions should I be using, and what modules are they contained in? http://docs.python.org/lib/os-file-dir.html
See "rename", obviously.
Holger
Thomas Philips wrote: How then can I change the existing filenames to these new filenames? What python functions should I be using, and what modules are they contained in?
os.rename(oldfilename, newfilename)
--Irmen
Thomas Philips wrote: The function glob in module glob will give me a list of all the subdirectories, and by looping over this list and repeatedly calling glob, I can create lists of files within each directory, which are easily edited to create lists of new filenames.
How then can I change the existing filenames to these new filenames? What python functions should I be using, and what modules are they contained in?
os.rename(oldname, newname)
found under "files and directories" in the library reference: http://docs.python.org/lib/os-file-dir.html
</F> tk****@hotmail.com (Thomas Philips) wrote: I want to get a list of all subdirectories of a given directory, and within each directory, change the name of each file using a predetermined rule.
The function glob in module glob will give me a list of all the subdirectories, and by looping over this list and repeatedly calling glob, I can create lists of files within each directory, which are easily edited to create lists of new filenames.
How then can I change the existing filenames to these new filenames? What python functions should I be using, and what modules are they contained in?
Thomas Philips
There is a "rename" function in the "os" module.
----== Posted via Newsfeed.Com - Unlimited-Uncensored-Secure Usenet News==---- http://www.newsfeed.com The #1 Newsgroup Service in the World! >100,000 Newsgroups
---= 19 East/West-Coast Specialized Servers - Total Privacy via Encryption =---
Sounds like you want to use os.path.walk function
which recursively drills down through directories and
subdirectories. Then (as everyone else has pointed
out). You can use os.rename.
HTH,
Larry Bates
Syscon, Inc.
"Thomas Philips" <tk****@hotmail.com> wrote in message
news:b4**************************@posting.google.c om... I want to get a list of all subdirectories of a given directory, and within each directory, change the name of each file using a predetermined rule.
The function glob in module glob will give me a list of all the subdirectories, and by looping over this list and repeatedly calling glob, I can create lists of files within each directory, which are easily edited to create lists of new filenames.
How then can I change the existing filenames to these new filenames? What python functions should I be using, and what modules are they contained in?
Thomas Philips This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: Cengiz Ulku |
last post by:
Hi all,
I know now how to change the font name of a RTF file in a RTB control using,
for example:
RTextBox1.SelFontName = cmbFonts.Text
I have a RTF file -created with Word- displayed in a...
|
by: oom |
last post by:
I am a bit of a newbie when it comes to python, when working with
lists today I noticed some very odd behaviour, any suggestions
welcome:
Python 2.2.3 (#1, Nov 6 2003, 14:12:38)
on linux2...
|
by: Satish Kumar Chimakurthi |
last post by:
Hi all,
An external solver program is dynamically producing files with different
names 0000001.dat, 0000002.dat, 0000003.dat etc.....at regular intervals.
These files contain all numeric data....
|
by: Cecilia Bergengruen |
last post by:
2 questions:
1)I inserted a menu in an mdi window form. I right clicked on a menu
item and pressed edit names. I therefore edited all my menu item names.
Then I right clicked and pressed edit...
|
by: John Pass |
last post by:
I saved a project accepting the defaults name “ConsoleApplication2â€. After
adding the code, I changed the name using “Rename†in the file directory.
After opening the file, the project name...
|
by: Greg Wickham |
last post by:
Hi All,
Earlier this year there was a discussion between Tom and Ezra regarding extending 'set session authorization' to facilitate changing
the identity of a connection. A synopsis of the...
|
by: Mikael Olofsson |
last post by:
Hi!
This is in Python 2.3.4 under WinXP.
I have a situation where I think changing the behaviour of a namespace
would be very nice. The goal is to be able to run a python file from
another in...
|
by: Steave |
last post by:
Hi, using Managed C++ (.Net 2.0), I want to embed some images within an
executable using a .resX file, and upon an event (in this case a combo
box changing), I want the picture box to update with a...
|
by: Jay |
last post by:
What's the recommended way to change file/folder names within a project?
I want to change the solution name from (say) sol1.sln to sol2.sln, and also everything else named
sol1.* (eg sol1.suo,...
|
by: 7stud |
last post by:
Hi,
I'm experimenting with a basic socket program(from a book), and both
the client and server programs are on my computer. In both programs,
I call socket.gethostname(), but I discovered that...
|
by: CloudSolutions |
last post by:
Introduction:
For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome former...
|
by: taylorcarr |
last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: ryjfgjl |
last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
|
by: ryjfgjl |
last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
|
by: emmanuelkatto |
last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud.
Please let me know.
Thanks!
Emmanuel
|
by: BarryA |
last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
| |