PDA

View Full Version : listing files in a directory but displaying file names differently.


sammaell
04-14-2005, 09:18 PM
ive read the sticky post about listing files in the directory, my question is..

is it possible to have the displayed name different to the actual file name that it is referring to?

for example, if i had a directory with 20 pdf files in it, with obscure names like:

ped0405.pdf
der0405.pdf
fjk0305.pdf


i'd like them displayed as:

Comment April 05
Another Comment April 05
Yet Another Comment March 05

respectively. (i.e. parsing the file and understanding that ped = "comment" and 0405 = "April 05")

The actual scenario is every month i am handed a cd with 100 pdf files, they are newsletters. Right now i have to upload them to the web site, edit the webpage with new links (with meaningful names) pointing to the appropriate pdf file. I would love to jsut be able to upload the files into the directory/s and have them dynamically displayed (such as the examples in the sticky post) but without having to change the names of the pdf files each month.

is that possible?

oracleguy
04-14-2005, 09:36 PM
Assuming the format stays the same and consistant, yes you can.

You could just use the instr() function and the mid() function to break apart the filename and then you could do a case select on each part, it'd be pretty easy to do.

So then when you build the links, you have the link point to the actual filename while the title, the stuff between the <a></a> tags is your generated name.

sammaell
04-14-2005, 10:15 PM
could you provide a small example of how to use those functions please? im very new to ASP.

thank you.

oracleguy
04-15-2005, 05:07 AM
Alright, I can get you started with an example, here is how you'd break it apart:

Dim file, code, month, year
file="ped0405.pdf"
code=Mid(file, 1, 3) 'That should make code contain "ped"
month=Mid(file, 4, 2) 'That should make month equal "04"
year=Mid(6, 2) ' That should make year equal "05"


I might have got the values for the starting character on the mid function wrong (thats the second parameter and the first number). I can never remember which language starts with 1 and which ones use 0 as the first character.

Once you have those 3 values you can do a select case to get the information you want.