Skip to main content
Inspiring
April 20, 2006
Answered

problem creating new dir

  • April 20, 2006
  • 13 replies
  • 1789 views
Hi there,

Here is the scope. If the directory does exist, continue to upload the file otherwise It should create a new directory by his username and upload the file but having problems doing it. here is the code.

    This topic is closed to new replies. Start a new post to keep the conversation going.
    Correct answer hannash
    What's the difference between TempDir and NewDir? Actually, nevermind, I don't really want to know. Say for the sake of convenience a variable, TheDir, has been set to d:\Customers\Files\Steve

    <cfif NOT DirectoryExists(TheDir)>
    <cfDirectory create........... TheDir ................> <!--- if not already there, create it --->
    </cfif>
    <cffile Upload...............TheFile..into..TheDir....>

    shoud give you what you're looking for right now.
    If you want to get into Directory renaming, consult the Help docs, but you'll still need to check if it's there already.

    Thanks JMGibson3,

    Big help, I had to tune it a liitle bit to work properly but your code helped. Thanks again. Here is the last code if somebody needs it.

    <cfset TempDir= "#application.drivepath##Session.username#">
    <cfif NOT DirectoryExists(#TempDir#)>
    <cfdirectory directory="#TempDir#" action="create">
    <CFFILE ACTION="UPLOAD"
    FILEFIELD="File"
    DESTINATION="#TempDir#"
    NAMECONFLICT="OVERWRITE">
    <cfelse>
    <CFFILE ACTION="UPLOAD"
    FILEFIELD="File"
    DESTINATION="#TempDir#"
    NAMECONFLICT="OVERWRITE">
    </cfif>

    13 replies

    hannashAuthor
    Inspiring
    April 20, 2006
    don't mind if I ask, never seen this in cf
    April 20, 2006
    See below. I hope your next post contains the results of the CFOUTPUT.
    hannashAuthor
    Inspiring
    April 20, 2006
    Again, I can add a new directory if the user login for the first time and upload the file succesfully but if I try again with tha same user I get this error.

    Error Occurred While Processing Request
    The specified Directory attribute value d:\Customers\Files\Temp could not be created.
    The most likely cause of this error is that the 'd:\Customers\Files\Temp' already exists on your file system. The exception occurred during a cfdirectory action="CREATE".

    The Error Occurred in D:\WWW\Clients\upload.cfm: line 61

    59 : <!--- <CFSET Session.username = #getinfo.username#> --->
    60 : <cfset NewDir= "#application.drivepath#">
    61 : <cfdirectory action="CREATE" directory="#NewDir#" name="#NewDir#">
    62 : <cfoutput><CFFILE ACTION="UPLOAD"
    63 : FILEFIELD="File"
    hannashAuthor
    Inspiring
    April 20, 2006
    +++#TempDir#+++#NewDir#+++<BR>
    +++#application.drivepath##Sep##Session.username#+++
    ??

    I didn't even try to put them in
    April 20, 2006
    You might learn something about the values of these variables. That's what you want, isn't it?
    hannashAuthor
    Inspiring
    April 20, 2006
    No, I am running on a test server and I am the admin. Now if it doesn't find a dir with that user, it creates ones and he can upload but if he tries again, gets that message. It is trying now to create a new dir everytime and don't look if the dir exists.
    April 20, 2006
    After your CFELSE, place the following. Perhaps it will shed some light on the issue.
    April 20, 2006
    I suspect you do not have write permissions on the server.
    hannashAuthor
    Inspiring
    April 20, 2006
    Nothing changed, any new user I use, I get this error

    The specified Directory attribute value d:\Customers\Files\Steve could not be created.
    The most likely cause of this error is that the 'd:\Customers\Files\Steve' already exists on your file system. The exception occurred during a cfdirectory action="CREATE".


    Still looking at the same dir.
    April 20, 2006
    Change your CFIF statement to
    <cfif IsDefined("TempDir") AND NOT IsDefined("NewDir")>
    and see what happens.