Renaming files with Python

I downloaded some PowerPoint slides and wmv programming videos from a college website and the original file names had spaces in them, so my browser’s downloader plugin converted the spaces to _20. I wanted to rename them so they wouldn’t have the _20 in them, and the following is the code I used to do so. Hope someone finds it useful.

import os
import os.path

files = os.listdir(os.getcwd())

for file in files:
    #if '20' and 'wmv' in file:
    if ' ' and 'ppt' in file:
        new_name = file.replace(' ', '_')
        print "%s   %s" % (file, new_name)
        os.rename(file, new_name)

C++ Overloading, overriding and hiding, oh my!

Continuing where I left off previously, I’ve been going through chapter 9, Inheritance and Polymorphism from Ivor Horton’s Beginning Visual C++ 2008 and consulting various other books a little more often than I had been up until now. One of those books was C++ Programming: Visual QuickStart Guide, by Larry Ullman and Andreas Signer.

Edit: There is a slightly better (cleaned up) version here.

I was reading chapter 8, Class Inheritance where I ran afoul of this warning:

Pay attention when overriding methods. If you don’t use the exactly same parameters and return values, you’ll end up with an overloaded method, and not an overridden one. Such mistakes are very hard to debug

Continue reading

Why a base class pointer to a derived class object is ok

As I’ve mentioned in previous posts, I’ve been going through Ivor Horton’s Beginning Visual C++ 2008 and thanks to the good folks at cprogramming.com, I’ve been steered back on course by numerous helpful posts while working through chapter exercises.

For a few weeks now, I’ve been in chapter 9, Inheritance and Polymorphism, and have been extensively taking notes. At one point I veered off course long enough to purchase or checkout from the library several other books, several of which I explored and ended up learning about Inheritance and Polymorphism; so much for a sabbatical!

Continue reading

You Can Do It! A Beginner’s Introduction to Computer Programming

Edit:

The author’s page for this book is now offline. Please see this post for more details, including where you can still obtain the library sources and other updated content for the book.


I picked up this book and the follow-up You Can Program in C++: A Programmer’s Introduction book several years ago while flailing about in an attempt to learn C++. The short version of why I didn’t succeed was that I didn’t have the required patience to take things slow and fully understand each new idea before moving on.

Well, I’m forcing myself to have the required patience this time around (started most recent attempt Sept 2011), and I’ve made good progress going through Ivor Horton’s Beginning Visual C++ 2008.

Now that I’ve made it through the first eight chapters, I’m seriously considering taking a break and going back to You Can Do It! A Beginner’s Introduction to Computer Programming. There are several reasons for this, and I’m thinking the biggest one is that both of these books by Francis Glassborow are sub-400 pages, while Ivor Horton’s Beginning Visual C++ 2008 is 1392 pages. To be fair, those pages are not only dedicated to Standard C++, but code specific to Microsoft Visual C++ and C++/CLI. Still, with only 543 of 1392 pages down, I’m thinking I need the emotional pick-me-up from completing a smaller book. Then I can return to that one.

All of that said, I’ve just started looking at the errata, the contents of the CD that came with the book and the latest updates to the CD contents and source code.

I had no idea how spoiled I had become from always heading to the website to grab the very latest and authoritative version of software/code. A few things I’ve figured out:

  • The CD contents are superseded by the contents available on the CD Substitute page.
  • The fgwlib library sources from the Resources page supersede the sources available from tutorial.exe on the CD Substitute page. Oddly enough, some of the comment misspellings that were fixed in the CD Substitute page are back in the latest fgw library sources, so it’s likely the author wasn’t using version control.
  • The Quincy download link on that page is no longer working.
  • There is a newer version of the IDE used by the book, Quincy, available here.

Bottom line:

The fgwlib library sources available from the Resources page supersede all other library sources.

Now that I’ve figured that out, I’m off to build the library to work with the latest MinGW install.