create folder

Results 1 to 3 of 3

Thread: create folder

  1. #1
    Join Date
    Dec 1969

    Default create folder

    I am using FSO to create a folder that enables the user to upload images to the specified folder. At the moment The user types the name of the foler, if the folder already exists he is asked to type another folder name. I want to automate this so if the folder exists - say Jake1 then the folder Jake2 is created, if this exists then it creates Jake3 etc.<BR><BR>Below is the code I&#039;m using at the moment:<BR><BR>&#060;% Name = request("Name") <BR>set fs=createobject("scripting.filesystemobject") <BR>MyFolder=server.mappath(""&name&"") <BR>If fs.folderexists(MyFolder) then %&#062;<BR><BR>&#060;b&#062;&#060;font face="Arial, Helvetica, sans-serif" color="#FF0000"&#062;A folder named &#060;%=MyFolder%&#062; <BR>already exists.&#060;/font&#062;&#060;/b&#062;<BR><BR><BR><BR>&#060;form name="form1" method="post" action="folder.asp"&#062;<BR> &#060;font face="Arial, Helvetica, sans-serif"&#062;1. Create a folder&#060;/font&#062;<BR><BR> &#060;input type="text" name="name"&#062;<BR> &#060;input type="submit" name="Submit" value="Create"&#062;<BR> <BR> &#060;/form&#062;<BR><BR>&#060;% <BR>End If<BR>If NOT fs.folderexists(MyFolder) then<BR>fs.createfolder(MyFolder)<BR>%&#062;

  2. #2
    Join Date
    Dec 1969

    Default RE: create folder

    first server.mappath is pretty heavy in server resources, so put this line in your global.asa file<BR>application("root")=server.mappath("./"), then just append as you need to applicaiton("root")<BR><BR>You could write a simple loop that incremented and tested until a suitable folder was found,<BR>counter = 0<BR>while 1 = 1<BR>MyFolder = MyFolder + counter<BR>If not fs.folderexists(MyFolder) then <BR>break<BR>end if<BR>next<BR><BR>you&#039;ll exist the loop with MyFolder set to the first number that doesnot exists.<BR><BR>This will again be heavy as you will be hitting the file system each time.<BR><BR>Why not append a date time stamp to the end of the folder instead, you will need to replace the spaces and colons but should be unique enough<BR><BR>MyFolder = MyFolder & replace(replace(now()," ",""), ":", " ")<BR><BR>(all code is untested by you should get the idea)<BR>

  3. #3
    Join Date
    Dec 1969

    Default Create folder Jakenn

    Try this..<BR><BR> strFolder="jake12"<BR> &#039;get numeric part of name..<BR> for i=1 to len(strFolder)<BR> if isnumeric(mid(strFolder,i,1)) then<BR> intStart=i<BR> exit for<BR> end if<BR> next<BR> strFolderRoot=left(strFolder,i-1)<BR> intNumber=right(strFolder,len(strFolder)-i+1)<BR> strFolder=strFolderRoot & (intNumber+1)<BR> <BR> &#039;TEST OUTPUT : New Folder Name<BR> alert (strFolder)<BR>

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts