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 3338
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(oldfi lename, 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(oldna me, 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 predetermine d 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.goo gle.com... 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 RTB control. Whenever I
change the font type during the runtime by selecting a font name from a
combobox -of all system fonts, the text changes its font correctly but I
loose some formatting such as a bold text and/or titles become normal text.
|
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
Type "help", "copyright", "credits" or "license" for more information.
>>> firstlist=
>>> secondlist=firstlist
>>> print (firstlist,secondlist)
|
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. Is it possible to read each of these
dynamically in python ?? If so, how should my code look like ?? If it was
not dynamically required, then, I would change the name of the file in my
*open* statement every time and read the corresponding one. But...
|
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 names again to return to the
normal view of the menu.
When I returned later on to muy menu names, they hadnt been saved. How
do I use this utility (edit names), since the changes I edit dont
prevail?
2) Is there a way to change the font and...
|
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 is indeed changed, but the solution
name (in the Solution explorer window) is still listed as
‘ConsoleApplication2’. How to I change that? What is the recommended way to
change the names of the various file types?
Thanks for your help,
...
| |
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 discussion is that Tom felt this was bad and the web application should have more
responsibility for handling session security.
I need to implement some session based authentication / authorization and would like to learn from others experience before...
|
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 a separate namespace in such a way that a NameError is not
raised if a non-existing variable is used in the file. The file that I
want to run is taken out of context, and some needed variables may be
missing that are normally there when used 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 different one.
I tried the following code:
System::ComponentModel::ComponentResourceManager^ resources =
(gcnew
System::ComponentModel::ComponentResourceManager(formDebayer::typeid));
|
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, the folder sol1, and within this folder, sol1.csproj, and also, files within
Debug and Release folders)
Also, how do I change other names (eg .cs files)?
I'm using VS C# 2005 Express.
|
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 when I am connected
to the internet, both the client and server hang and nothing happens.
I discovered that the hostname of my computer automatically changes to
that of my isp when I'm connected to the internet, and presumably the
server program...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, well explore What is ONU, What Is Router, ONU & Routers main usage, and What is the difference between ONU and Router. Lets take a closer look !
Part I. Meaning of...
| |
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new presenter, Adolph Dupr who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms.
Adolph will...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
| |
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
|
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...
| |