![]() |
| FileSystem Object |
|
eriweb
|
Hi all,
We have legal pdf documents that we allow our members to download. The naming convention that we use on these documents is <4 digit document #> _ + <document title> _ ".pdf". The 4 digit document number is passed in as a query string and I am trying to grab those digits and search in a directory for that document. So something like "Search in this directory for a file with these 4 digits on its file name". Now I am not sure if there is a way to search using maybe FileSystemObject with Coldfusion or something else. Any help in this is really appreciated. Thanks in advance. |
||||||||||||
|
|
|||||||||||||
|
Jason101
Forum Regular
|
You could use <cfdirectory>, and then query the returned query "FileName" Feild.
You can then use ListFirst(list [, delimiters ]) to get the first element (Your 4 digit number) Just use "_" as the delimiter. If you have more than say 100 files in the directory, I would avoid using cfdirectory. I also use java objects to read from the filesystem it is 1000 times faster than cfdirectory. Let me know if you need example code. |
||||||||||||
|
|
|||||||||||||
| FSO Object |
|
eriweb
|
Thank you very much for your reply Jason.
Yea if you don't mind I would appreciate a sample code. I tried the following code:
This did return the one I wanted but it also returned other files that did have the "0814_" in the filename. |
||||||||||||||
|
|
|||||||||||||||
| Correction |
|
eriweb
|
Sorry on the previous post I meant to say there were returned results that did not have the "0814_" in the filename.
|
||||||||||||
|
|
|||||||||||||
| Re: FSO Object |
|
Jason101
Forum Regular
|
Try to do a query or queries to get your results like as follows:
That should bring you back what you want. Since you're queying the set of data for file LIKE 0814. |
||||||||||||||||||
|
|
|||||||||||||||||||
|
Jason101
Forum Regular
|
Ok, I use java.io.File when i really need it. I have a directory with about 8,000+ images and it returns them in about 2 seconds. CFDirectory times out trying to return the same set.
Here you go..
That creates the java object. This will not return a fancy query like CFDirectory. It is just going to return a Coldfusion 1d array. It won't tell you if the item is a directory, or a file. Just try it and do a CFDump and see what it returns I distinguish files from dirs by looking if there is a file extension. If there is not a file extension, I assume it is a directory. Like So: (Assuming your file extensions are only 3 characters long) While Looping through the array
To Sort the array by file name (since it comes back unsorted)
Hoep this helps. |
||||||||||||||||||
|
|
|||||||||||||||||||
| Thanks... |
|
eriweb
|
Thank you very much Jason, you rock dude
|
||||||||||||
|
|
|||||||||||||
| FileSystem Object |
|
||
|


