Archive for the 'Python' category

Use Python to Save an FTP Directory List to File

Mar 13 2009 Published by under Python

Written for Python 2.6


import ftplib

ftp = ftplib.FTP("")
ftp.login("username", "password")

data = []



outputFile = open('dirList.txt','wb')

for line in data:
    outputFile.write(line + "\n")

Reblog this post [with Zemanta]

No responses yet

Using Python to replace spaces with underscores in filenames.

Feb 25 2009 Published by under Python

Python can be used on Window, Linux and Mac. It just a simple install.

download code


import string
import os
import re

# task:
# loop thur input directory
# look for .pdf
# replace space with underscore
# rename/move to output directory

inputDir = "./" # Current directory
outputDir = "./new_location"

for filename in os.listdir(inputDir):
    if filename[-4:] == ".pdf":
        tempName = filename
        tempName = tempName.replace(' ', '_')
        os.rename(inputDir + "/" + filename, outputDir + "/" + tempName)

One response so far