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 John Tel on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Problem with FileExists 2

Status
Not open for further replies.

nohandlesleft254

IS-IT--Management
Apr 19, 2006
58
GB
Hi,

Im using the below code to write then check a txt file. The problem being it always returns false. I thought this may be the delay in writing the file so i added a loop from 1 to 50000 before checking but it still returned false. Do i need to wait longer? Also is there a better way of delaying the check?

Thanks

<!--- Write the text file --->
<cffile action="Write" file="#Application.ImportDir##FileName#.txt" charset="ASCII" output="#Body#">

<!--- Check the file was written --->
<cfloop index="i" from="1" to="50000">
</cfloop>

<cfset FileLocation = Application.ImportDir & FileName & '.txt'>

<cfif FileExists(FileLocation)>
<cfset FileSaved eq "True">
</cfif>
 
first of
<cfset FileSaved = <True">

also could you try this instead


<cfif Len(ExpandPath(myFileNameGoesHere))>
<cfset fileSaved = "true">
<Cfelse>
<cfset fileSaved = "false">
</cfif>


o by the way, you don't need that loop...
hope it helps

 
Hi,

I should have been more specific

Application.ImportDir = \\Server\SharedFolder (not relative)

so expandpath does me no good?
+ how does 'len' help me?

thanks for your help!

 
ok then

<cfif Len(FileExists('myFile.txt'))>
<cfset fileSaved = "true">
<Cfelse>
<cfset fileSaved = "false">
</cfif>
<cfoutput>#fileSaved#</cfoutput>


len() checks for a string and returns the length. if not found it returns 0...
hope it helps

 
That works great! Thanks.

So why doesnt FileExists work on its own?
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top