.com.unity Forums
  The Official e-Store of Shrapnel Games

This Month's Specials

Raging Tiger- Save $9.00
winSPMBT: Main Battle Tank- Save $6.00

   







Go Back   .com.unity Forums > Shrapnel Community > Space Empires: IV & V

Reply
 
Thread Tools Display Modes
  #1  
Old October 16th, 2006, 03:02 PM
AngleWyrm's Avatar

AngleWyrm AngleWyrm is offline
Second Lieutenant
 
Join Date: Mar 2005
Location: Seattle, WA
Posts: 417
Thanks: 0
Thanked 0 Times in 0 Posts
AngleWyrm is on a distinguished road
Default OT: Python

With Python,

How would I change a directory of filenames from whatever_stuff.txt to new_stuff.txt?
Reply With Quote
  #2  
Old October 16th, 2006, 03:22 PM
Captain Kwok's Avatar

Captain Kwok Captain Kwok is offline
National Security Advisor
 
Join Date: Oct 2001
Location: Toronto, Canada
Posts: 5,623
Thanks: 1
Thanked 14 Times in 12 Posts
Captain Kwok is on a distinguished road
Default Re: OT: Python

CKrename is a handy little program that does this and more... google it!
__________________
Space Empires Depot | SE:V Balance Mod
Reply With Quote
  #3  
Old October 16th, 2006, 03:24 PM
Fyron's Avatar

Fyron Fyron is offline
Shrapnel Fanatic
 
Join Date: Jul 2001
Location: Southern CA, USA
Posts: 18,394
Thanks: 0
Thanked 12 Times in 10 Posts
Fyron is an unknown quantity at this point
Default Re: OT: Python

Personally, I'd use CK Rename for batch file renaming. But in a python script, you would need something like:

Code:
import os
import re

oldstring = 'whatever'
newstring = 'new'

name_match = re.compile(oldstring)

os.chdir('target')

print 'preop:'
print os.listdir('.')

for f in os.listdir('.'):
os.rename(f, name_match.sub(newstring, f, count=1))

print 'postop:'
print os.listdir('.')



Make sure to replace 'target' with the directory containing the files.

Alternatively without much extraneous bits:

Code:
import os
import re

name_match = re.compile('whatever')

os.chdir('target')

for f in os.listdir('.'):
os.rename(f, name_match.sub('new', f, count=1))



reference:
http://docs.python.org/lib/os-file-dir.html
__________________
It's not whether you win or lose that counts: it's how much pain you inflict along the way.
--- SpaceEmpires.net --- RSS --- SEnet ModWorks --- SEIV Modding 101 Tutorial
--- Join us in the #SpaceEmpires IRC channel on the Freenode IRC network.
--- Due to restrictively low sig limits, you must visit this link to view the rest of my signature.
Reply With Quote
  #4  
Old October 16th, 2006, 03:44 PM
AngleWyrm's Avatar

AngleWyrm AngleWyrm is offline
Second Lieutenant
 
Join Date: Mar 2005
Location: Seattle, WA
Posts: 417
Thanks: 0
Thanked 0 Times in 0 Posts
AngleWyrm is on a distinguished road
Default Re: OT: Python

Thanks, big help!
Reply With Quote
Reply

Bookmarks


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is On

Forum Jump


All times are GMT -4. The time now is 09:45 AM.


Powered by vBulletin® Version 3.8.1
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©1999 - 2024, Shrapnel Games, Inc. - All Rights Reserved.