Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

get directory listing

Status
Not open for further replies.

olmos

Technical User
Oct 25, 2000
135
US
How can I get a list of files returned based on a file which
contains part of the file name ?

For example, I have a file which contains
test1
test2
test3

and I need to find all the files within the directory which begin with each line . I then need to input the date of the file. How can this be done with coldfusion ?


Thanks,
olmos
 
hi olmos,

If you know the directory name that may or may not contain the files listed in your 'file list' file, then use the steps that I have posted below.

1. read in the file that contains the other file names
Code:
<!--- You can use the function expandPath() to find the absolute path, given that the file you are reading is under your webroot. --->
<cffile action="read" file="absolute_path_to_file\filename.txt" variable="myFileContents">

2. Iterate through the results and check for the existance of file
Code:
<cfloop list="#myFileContents#" index="fname" delimiters="#chr(13)##chr(10)#">
	<cfset lookupfilePath = expandPath('.') &"\"& fname>
	<cfif fileExists(lookupfilePath)>
		<!--- Since there is no native CF way of reading lastmodified dates --->
		<!--- on files (except when using <cfdirectory>), you will need to  --->
		<!--- use something else. CFLib.org provides a ton of filesystem  --->
		<!--- functions written by fellow CFers, I've included the link below --->
		<!--- to download the source need to use the 'FileDateLastModified' function --->		
		<cfset fModDateTime = FileDateLastModified(lookupfilePath)>
	</cfif>	
</cfloop>

You can download the source for the 'FileDateLastModified()' function here:

I hope this helps,

jalpino
 
thanks for your help
olmos
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top