DZone Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world

Snippets has posted 5883 posts at DZone. View Full User Profile

URL List Sort By Filename

  • submit to reddit
        This little script sorts a url list by the filename of an url.

#! /usr/bin/python
import sys
filename = sys.argv[1]

f=open(filename, 'r')
url_list = contents.split('\n')

def get_filename(file):
    return file[file.rfind('/')+1:]

def filename_compare(x, y):
    file_x = get_filename(x)
    file_y = get_filename(y)
    if file_x > file_y:
        return 1
    elif file_x == file_y:
        return 0
        return -1


for url in url_list:
    if url != '':
        print url