473,387 Members | 1,791 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,387 software developers and data experts.

New to Python (only 7 weeks in ) and I would like any help on renaming files.

Good afternoon, all,
I am new to python and I have a problem that requires a user to input starting/ending file numbers, and the suffix of the files to rename. The output will show the newly renamed file as 'rename bak/file(number).doc(or eml or JPEG) old_file(number).doc(oreml or JPEG). I keep going round in circles, any nudge in the right direction would be greatly appreciated!
Thanks
Mar 3 '13 #1
1 1366
bvdet
2,851 Expert Mod 2GB
The first thing I would do is compile a list of file names to rename meeting your criteria. In the following example, a list of file names found in the current working directory will be created with a file extension that the user enters:
Expand|Select|Wrap|Line Numbers
  1. import glob
  2. import os
  3.  
  4. ext = raw_input("Enter file extension")
  5. filepath = os.getcwd()
  6. filenames = [os.path.join(filepath, fn) for fn in glob.glob("*.%s" % (ext))]
  7. print "\n".join(filenames)
Is that enough of a nudge?
Mar 4 '13 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

5
by: MiLF | last post by:
Is it possible to write a Audio CD Player by using python only?
4
by: Kamilche | last post by:
I have a very unusual application written in C, one which uses dictionaries for all data storage, and a unique file structure. After staring at a current task for a bit, I decided I REALLY wanted...
4
by: Sarir Khamsi | last post by:
Is there a way to get help the way you get it from the Python interpreter (eg, 'help(dir)' gives help on the 'dir' command) in the module cmd.Cmd? I know how to add commands and help text to...
27
by: Florian Lindner | last post by:
Hello, I've been using Python a lot for scripting (mainly scripts for server administration / DB access). All these scripts were shell based. Now I'm considering using Python (with mod_python on...
3
by: Colin | last post by:
I have two files and I want to rename file B to file A without doing a system call - can I do this in C using file pointers ?
1
by: Christina Feichter | last post by:
Hello All How can i start a help-file like help.chm? Thanks
3
by: | last post by:
I am a novice in C# and need help. I want to write a simple program to read a bunch of files from a specified directory and rename those files in a sequential fashion., changing a bunch of image...
1
by: GeoDW | last post by:
Hell All, I have looked around and not found the solution I am looking for within the old threads. Here is my problem: I have a directory full of .img and .rrd files that have long filenames...
1
by: Davy | last post by:
Hi all, Is there any Python Profiler GUI like Matlab? I found the Matlab Profiler is very intuitive and easy to use. Best regards, Davy
7
by: Phillip B Oldham | last post by:
Are there any python micro-frameworks (like ruby's Camping)?
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: 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
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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.