Do you have a requirement also that for any given url it must be possible to look up the short code for it? A system of just counting up numbers would do the trick to just generate unique filenames but of course this is not a repeatable method so if the same url went in multiple times it would come out with different keys each time.
If this is acceptable then I'd just suggest a counter, possibly in base 36 (case insensitive alphanumeric) or similar to give you maximum key space size. You could have one file that contains the current count (could also be stored in memory but would need to be reloaded on restart) and then of course you have to be careful about multi-thread access both reading the next value at the same time.
If you need a given url to be consistently given the same id then you could have a second directory storing files named after the url (escaped as appropriate) containing the key that you generated the first time for them. When generating new keys you can look up in this file directory for if the url already has a key and return that if it is there.
As you can see this is basically crudely replicating the way the database will work with the two directories basically being indexes on a table of url and key.
The only other way I can think to do it would be to have some function that is one-to-one that will be guaranteed for the input you are looking at to generate a string under a certain length. I can't think where you would find such a function. Compression algorithms are the closest thing but they of course generate output that is unlikely to suit your need (since the binary it compresses to will probably as big as the original string once it has been base64 encoded or similar)
A hashing function as suggested by fardjad will probably be alright but there is no way to go from a hashed value back to the url and there is no guarantee that two inputs will be unique (though the chances of them not being so are extremely small).
I suspect fardjad's solution will be as good as you need in practice but it depends how robust this needs to be.
I should note finally that I have never written or looked much into the shorter url services so none of what I say is expert advice, just thoughts on how I would do it if it were me having done no research. :)