473,386 Members | 1,820 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

Mass-Renaming folders win32

I've a folder structure like this :

"Folder A"
|--"1"
|--"2"
---"3"

"Folder B"
|--"4"
---"5"
And I want to obtain a structure like this :

"Folder A - 1"
"Folder A - 2"
"Folder A - 3"
"Folder B - 4"
"Folder B - 5"

Can someone help me ? I am python beginner

Oct 28 '06 #1
1 1244
I've a folder structure like this :
>
"Folder A"
|--"1"
|--"2"
---"3"

"Folder B"
|--"4"
---"5"

And I want to obtain a structure like this :

"Folder A - 1"
"Folder A - 2"
"Folder A - 3"
"Folder B - 4"
"Folder B - 5"

Can someone help me ? I am python beginner
I'd try something like:

import os
from shutil import move

for path, dirs, files in os.walk('.'):
if path <os.curdir and files:
# the "2:" strips of the ".[os.sep]" at the beginning
newdir = path[2:].replace(os.sep, ' - ')
try:
os.mkdir(newdir)
for f in files:
try:
move(
os.sep.join([path, f]), #the old location
os.sep.join([newdir, f]) #the new location
)
except:
print 'Could not move %s to %s' % (f, newdir)
except:
print 'Could not create %s' % newdir

It doesn't clean up the original directories along the way, but
that may be better, depending on the nesting depth of your
directories...you'd want to make sure that you deal with all the
files within a directory before deleting it.

Feel free to tweak as needed.

-tkc


Oct 28 '06 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
by: Jeffrey Silverman | last post by:
Hi, all. Sorry, first off, for the kidna weird selection of crossposted groups, but this question touches on aspects of discussion in each of the groups. So I have a group of around 500 email...
1
by: John Rauhe | last post by:
Hello, Does anybody know how to detect if an mass-storage device has been added to the system ? I am making a program that will (should) detect when a CompactFlash memory card has been inserted...
1
by: kartik | last post by:
Hi , I am in need to find a way, to mass copy the data from db2 table running in mainframe to universal database db2 on NT. I know that DB2 connect gives the flexiblity of connecting and...
3
by: Strasser | last post by:
In Access2000 mass emailing worked perfectly (very powerful tool!). Doesn't work when using XP version of both Access and Outlook, even though I checked the box to ensure that I was sending the...
0
by: Ivan | last post by:
Hi, all, How to get BusRelations of a USB Mass Storage Device in C#? Or, do we have any function to get BusRelations of a USB Mass Storage Device, even not in C#? Any information is...
3
by: Gil \(Asp.net Developer\) | last post by:
1
by: johnny | last post by:
hi all, I would like to understand which are the best ways to send bulk mailings like for newsletters and so on ( not spamming, always to receivers who opt-in ). I am not looking for code for...
3
by: cordial_camaraderie | last post by:
I need to send 30,000 emails to our NewsLetter Subscriber, I tried to use our hosting Site and for the worst part We we banned and our site was stopped. I am using PHP script, mail() function to...
2
by: Bob Alston | last post by:
I am looking for suggestions for software or access code or utilities to assist in doing mass emailings from an Access database. The emailings would likely be a few thousand at a time. Generally...
1
by: teo | last post by:
Hallo, I'm performing a mass insertion from a text file to a db table with AdoNet commands, like this: myCommand.CommandText = "BULK INSERT ..." from a Win form no problem
0
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,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
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...
0
BarryA
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...
0
marktang
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,...
0
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...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
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...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.