文章作者 : weblu [ weblu@21cn.com ] Web URL : http://
上载日期 : 2000-12-13
问题:当文件上传或系统创建了一个文件后,你需要一些代码来处理,进行检测。
解决方案:这段代码是由Rob Brooks-Bilson友情提供的,它可以检测文件是否存在。程序使用了一个条件循环,而且不会给服务器带来很大的负荷。
<!--- this snippet of code executes a conditional loop that continues to
itterate until one of two conditions are met. If the file text.txt
(the example) exists, the loop breaks out. Likewise, if the timer increments
to 20000 milliseconds (20 seconds), the loop also breaks out. --->
<CFSET Continue=0>
<CFSET TimerStart = GetTickCount()>
<CFSET TotalTime = 0>
<!--- Loop until Continue = False --->
<CFLOOP CONDITION="(Continue LESS THAN 1) AND (TotalTime LESS THAN OR EQUAL TO
20000)">
<CFIF FileExists(ExpandPath("text.txt"))>
<CFSET Continue=1>
The file exists! Done waiting...<BR>
<CFELSE>
<CFSET TimerEnd = GetTickCount()>
<CFSET TotalTime = TimerEnd - TimerStart>
</CFIF>
</CFLOOP>
|