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

Dynamically created folders 2

Status
Not open for further replies.

profwannabe

Programmer
Jan 6, 2001
53
US
I need to dynamically generate folders and subfolders into which a file will be posted using <cffile>. The folder name = #attributes.ClientName# and the subfolder is #attributes.ContractTitle#.

I can create the folders using <cfdirectory> without problem. However, I need to evaluate whether or not those folders exist.

<cfdirectory action=&quot;LIST&quot; directory=&quot;#directoryroot#\documents&quot; name=&quot;CheckDirectory&quot;>
... shows me any ClientName folders. How do I evaluate the query results to see if CheckDirectory.#Name# = #attributes.ClientName#? Using <cfif> I can then avoid trying to create a folder that already exists (which is the error I cannot seem to avoid).
 
Unless you are using an earlier version of CF, you can just use the directoryExists() function like this.

<cfif directoryExists(&quot;#attributes.ClientName#\#attributes.ContractTitle#&quot;)>
.... code to run if directory exists ....
<cfelse>
.....code to create directory ....
</cfif>

Hope this helps,
GJ
 
GJ,

I need to successively create the directories because a Client will have multiple contracts.

My code is thus:
<cfif NOT directoryExists(&quot;/documents/#ClientName#&quot;)>
<cfdirectory action=&quot;CREATE&quot; directory=&quot;#directoryRoot#/documents/#ClientName#&quot;>
</cfif>
<cfif NOT directoryExists(&quot;/documents/#ClientName#/#ContractTitle#&quot;)>
<cfdirectory action=&quot;CREATE&quot; directory=&quot;#directoryRoot#/documents/#ClientName#/#ContractTitle#&quot;>
</cfif>

I get an error that I think is a result of the second cfdirectory statement, as it errors on trying to create the ClientName folder. How can I have cfdirectory create only a ContractName subfolder where the ClientName folder already exists?

 
GJ,

Actually, further testing seems to indicate that the problem lies with the cfif statement not evaluating the directory name. Can I not negate the statement with NOT (what I need to do is check for the existence of the directories, create them if they do not exist, then proceed with the cffile upload).

 
Yes, you can use <cfif not directoryExists()...> but you'll need to use a full path to the directory. Unless you're on Unix, Linux, etc.. you'll need something like &quot;D:\inetpub\ If you are on Unix, what error are you getting?

GJ
 
Thanks GJ! You solved in a few minutes what took me hours to screw up!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top