Author |
Topic |
|
andygenge
Starting Member
United Kingdom
30 Posts |
Posted - 23 July 2001 : 10:59:18
|
Hi all, A few days ago I asked how I can search a directory and display an icon if the file exists.
E.g a staff directory lists all the people. If there is a photo of the user called user.jpg an icon is displayed and this takes you to a profile page.
I have now cracked it. I am sure there are many errors, but I feel good right now.
<%'Declare our FileSystemObject variable Dim objFSO Dim objFolder Dim strRootFolder Dim objFile
Set objFSO = Server.CreateObject("Scripting.FileSystemObject") strRootFolder = "d:\www\docs\Staffphotos\"
'set our folder object to the web root folder Set objFolder = objFSO.GetFolder(strRootFolder) set objFiles = objFolder.Files
'Now, use a for each...next to loop through the Files collection
<% set jp = conn.execute(SQL) %> <% if jp.eof then response.write ("sorry, no results have been returned") end if %> <%do while not jp.eof names = trim(jp(1)) names = names & trim(jp(2)) names = names & ".jpg"%> <% for each objFile in objFiles%> <%if objFile.Name = names then%> <%response.write ("weyhay") end if %> <%next%> jp is each name in a database 1 is first name and 2 the surname.
I doubt this helps anyone, but I though I would let you all know.
Andy
|
|
cevans
Junior Member
Canada
101 Posts |
Posted - 23 July 2001 : 15:15:32
|
If all you're looking for is a boolean value of whether the file exists or not, you can save yourself some work, as you don't need to use the folder object (your objFolder) or its files collection (your objFiles). This way gets rid of the entire For Each loop.
Set up your objFSO, recordset, and names variable exactly the same way you have, then do this:
... <% if objFSO.FileExists(strRootFolder & names) then response.write ("weyhay") end if %> ...
Clark |
|
|
SaiyanJin
Junior Member
115 Posts |
Posted - 23 July 2001 : 21:22:52
|
How hard would it be to use the filesystem object to:
Find if a folder already exist in a given folder. IF it doesn't exist, create it, if it does, then prompt for another name. After the folder has been created, copy a file from another folder and put it inside of that folder?
Can anyone familiar with filesystem help? The folder name will come from a form.
Thanks for any help.
|
|
|
andygenge
Starting Member
United Kingdom
30 Posts |
Posted - 24 July 2001 : 08:01:41
|
Sorry, my knowledge ended at searching for a file, I have heard in the rumour mill of the exist function. Thanks.
I don't see why you can't do the search you are after. I would try building it bit by bit. I.E search for a folder as above. Then insert an if exist do one thing. and so on. To search for the folder simply change the code above.
Andy
|
|
|
HuwR
Forum Admin
United Kingdom
20584 Posts |
Posted - 24 July 2001 : 08:09:18
|
quote:
How hard would it be to use the filesystem object to:
Find if a folder already exist in a given folder. IF it doesn't exist, create it, if it does, then prompt for another name. After the folder has been created, copy a file from another folder and put it inside of that folder?
Can anyone familiar with filesystem help? The folder name will come from a form.
Thanks for any help.
Very Simple, this checks if a folder exists, and creates it if it doesn't. strRoot is a physical path, so if the directories are relative to your website, you will need to use server.mappath to generate the correct path
If not fso.FolderExists(strRoot) then
fso.createFolder(strRoot)
end if
to copy a file use fso.CopyFile source, destination[, overwrite]
where overwrite is either True or False
|
|
|
SaiyanJin
Junior Member
115 Posts |
Posted - 25 July 2001 : 00:24:29
|
strRootFolder = "Y:\rootDIR\" userdirectory = "MYDIR" If not objFSO.FolderExists(strRootFolder & userdirectory) then objFSO.createFolder(strRootFolder & userdirectory) 'to copy a file use 'FILE NOT FOUND ERROR ON BELOW LINE OF CODE objFSO.CopyFile strRootFolder & "login.asp", strRootFolder & userdirectory, false
The login.asp file is inside of strRootFolder (Y:\rottDIRC\) and I want to copy it to strRootFolder\userdirectory which is (Y:\rottDIRC\MYDIR)
Thanks HuwR. I used what you suggested.
|
|
|
HuwR
Forum Admin
United Kingdom
20584 Posts |
Posted - 25 July 2001 : 03:21:13
|
you may need to do
objFSO.CopyFile strRootFolder & "login.asp", strRootFolder & userdirectory & "\", false
|
|
|
SaiyanJin
Junior Member
115 Posts |
Posted - 25 July 2001 : 07:03:51
|
I tried that as well. Forgot to mention it but I get the same error.
|
|
|
HuwR
Forum Admin
United Kingdom
20584 Posts |
Posted - 25 July 2001 : 07:21:59
|
my first question would be, did it create the directory ? and is it able to find the source file, check using fileExists
|
|
|
SaiyanJin
Junior Member
115 Posts |
Posted - 25 July 2001 : 07:44:28
|
The folder is created if it doesn't exist. If it exists, it gives me the message I tell it to give.
The file is not found.
Here is what I've tried:
<% If not objFSO.FileExists("login.asp") then %> File does not exist <% end if%>
AND this: <% If not objFSO.FileExists(strRootFolder & "login.asp") then %> File does not exist <%end if%>
|
|
|
HuwR
Forum Admin
United Kingdom
20584 Posts |
Posted - 25 July 2001 : 08:11:41
|
can you post your code, so I can see the flow of it, it is difficult trying to solve something if you only see a few lines of code written out of context.
|
|
|
SaiyanJin
Junior Member
115 Posts |
Posted - 25 July 2001 : 08:16:15
|
<%'Declare our FileSystemObject variable Dim objFSO Dim objFolder Dim strRootFolder Dim objFile dim userdirectory
userdirectory = Request.form("userdirectory")
Set objFSO = Server.CreateObject("Scripting.FileSystemObject")
strRootFolder = "E:\myweb\"
'set our folder object to the web root folder 'Set objFolder = objFSO.GetFolder(strRootFolder) 'set objFiles = objFolder.Files
If not objFSO.FolderExists(strRootFolder & userdirectory) then objFSO.createFolder(strRootFolder & userdirectory) 'to copy a file use If not objFSO.FileExists(strRootFolder & "login.asp") then %> The file does not exists. <%end if%> Congratulations!!!!! Your homepage is: <b>http://www.myweb.com/<%= userdirectory%> <p> To login to your account, click on <a href=http://www.myweb.com/<%= userdirectory%>/login.asp target="myhome">http://www.myweb.com/<%= userdirectory%>/login.asp</a><p> Your password will be: <b>members</b>. Please change it as soon as possible to avoid others from accessing your account.<p><p> <% else Response.write ("The requested url: <b>http://www.myweb.com/" & userdirectory & " has been taken. Press ""Back"" to choose another one") end if %>
|
|
|
HuwR
Forum Admin
United Kingdom
20584 Posts |
Posted - 25 July 2001 : 08:27:46
|
You don't appear to be copying the file ?
|
|
|
SaiyanJin
Junior Member
115 Posts |
Posted - 25 July 2001 : 09:27:04
|
<%'Declare our FileSystemObject variable Dim objFSO Dim objFolder Dim strRootFolder Dim objFile dim userdirectory
userdirectory = Request.form("userdirectory")
Set objFSO = Server.CreateObject("Scripting.FileSystemObject")
strRootFolder = "E:\myweb\"
'set our folder object to the web root folder 'Set objFolder = objFSO.GetFolder(strRootFolder) 'set objFiles = objFolder.Files
If not objFSO.FolderExists(strRootFolder & userdirectory) then objFSO.createFolder(strRootFolder & userdirectory) 'to copy a file use If not objFSO.FileExists(strRootFolder & "login.asp") then %> The file does not exists. <% else objFSO.CopyFiles strRootFolder & "login.asp", strRootFolder & userdirectory, false end if %>
Congratulations!!!!! Your homepage is: <b>http://www.myweb.com/<%= userdirectory%> <p> To login to your account, click on <a href=http://www.myweb.com/<%= userdirectory%>/login.asp target="myhome">http://www.myweb.com/<%= userdirectory%>/login.asp</a><p> Your password will be: <b>members</b>. Please change it as soon as possible to avoid others from accessing your account.<p><p>
<% else Response.write ("The requested url: <b>http://www.myweb.com/" & userdirectory & " has been taken. Press ""Back"" to choose another one")
end if %>
NOTE: I was checking if the file exist like you suggested and removed the code to copy because it keeps on blowing up on me and forgot to put it back in on the previous post.
ERROR: FILE NOT FOUND.
Thanks HuwR for the help.
|
|
|
HuwR
Forum Admin
United Kingdom
20584 Posts |
Posted - 25 July 2001 : 09:53:04
|
Ok, thanks.
Which file is it saying doesn't exist, the source or the destination file after copying ?
|
|
|
SaiyanJin
Junior Member
115 Posts |
Posted - 25 July 2001 : 10:24:05
|
I would say the source file doesn't exist because the directory is created and the directory is present.
AHHHHHHHHHHHHHHHHHHHHHHHH stupid me! The file does not exist after all. I have a the file name as login.asp.asp and using windows, it says login.asp.
But I get Permission denied now. I guess that's a permission thing that I have to set on IIS? Please give a clue if anyone knows.
thanks huwr!!!!!!!!!!
Edited by - Saiyanjin on 25 July 2001 10:52:10 |
|
|
|
Topic |
|