Snitz Forums 2000
Snitz Forums 2000
Home | Profile | Register | Active Topics | Members | Search | FAQ
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 Community Forums
 Code Support: ASP (Non-Forum Related)
 filesystem object solution
 New Topic  Topic Locked
 Printer Friendly
Author Previous Topic Topic Next Topic  

andygenge
Starting Member

United Kingdom
30 Posts

Posted - 23 July 2001 :  10:59:18  Show Profile
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  Show Profile  Send cevans an ICQ Message
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
Go to Top of Page

SaiyanJin
Junior Member

115 Posts

Posted - 23 July 2001 :  21:22:52  Show Profile
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.

Go to Top of Page

andygenge
Starting Member

United Kingdom
30 Posts

Posted - 24 July 2001 :  08:01:41  Show Profile
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

Go to Top of Page

HuwR
Forum Admin

United Kingdom
20584 Posts

Posted - 24 July 2001 :  08:09:18  Show Profile  Visit HuwR's Homepage
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

Go to Top of Page

SaiyanJin
Junior Member

115 Posts

Posted - 25 July 2001 :  00:24:29  Show Profile
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.


Go to Top of Page

HuwR
Forum Admin

United Kingdom
20584 Posts

Posted - 25 July 2001 :  03:21:13  Show Profile  Visit HuwR's Homepage
you may need to do

objFSO.CopyFile strRootFolder & "login.asp", strRootFolder & userdirectory & "\", false


Go to Top of Page

SaiyanJin
Junior Member

115 Posts

Posted - 25 July 2001 :  07:03:51  Show Profile
I tried that as well. Forgot to mention it but I get the same error.

Go to Top of Page

HuwR
Forum Admin

United Kingdom
20584 Posts

Posted - 25 July 2001 :  07:21:59  Show Profile  Visit HuwR's Homepage
my first question would be, did it create the directory ?
and is it able to find the source file, check using fileExists

Go to Top of Page

SaiyanJin
Junior Member

115 Posts

Posted - 25 July 2001 :  07:44:28  Show Profile
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%>



Go to Top of Page

HuwR
Forum Admin

United Kingdom
20584 Posts

Posted - 25 July 2001 :  08:11:41  Show Profile  Visit HuwR's Homepage
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.

Go to Top of Page

SaiyanJin
Junior Member

115 Posts

Posted - 25 July 2001 :  08:16:15  Show Profile
<%'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
%>


Go to Top of Page

HuwR
Forum Admin

United Kingdom
20584 Posts

Posted - 25 July 2001 :  08:27:46  Show Profile  Visit HuwR's Homepage
You don't appear to be copying the file ?

Go to Top of Page

SaiyanJin
Junior Member

115 Posts

Posted - 25 July 2001 :  09:27:04  Show Profile
<%'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.

Go to Top of Page

HuwR
Forum Admin

United Kingdom
20584 Posts

Posted - 25 July 2001 :  09:53:04  Show Profile  Visit HuwR's Homepage
Ok, thanks.

Which file is it saying doesn't exist, the source or the destination file after copying ?

Go to Top of Page

SaiyanJin
Junior Member

115 Posts

Posted - 25 July 2001 :  10:24:05  Show Profile
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
Go to Top of Page
  Previous Topic Topic Next Topic  
 New Topic  Topic Locked
 Printer Friendly
Jump To:
Snitz Forums 2000 © 2000-2021 Snitz™ Communications Go To Top Of Page
This page was generated in 0.52 seconds. Powered By: Snitz Forums 2000 Version 3.4.07