SitePoint Sponsor

User Tag List

Results 1 to 8 of 8
  1. #1
    SitePoint Enthusiast Northern Star's Avatar
    Join Date
    Aug 2006
    Location
    Cheshire, UK
    Posts
    96
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Exclamation FileSystemObject Delete 'Week Old' Files

    Hi all,

    I know this is going to be blindingly simple but I've had one of those days where the more I search and try, the further away from finding the solution I am!

    What I'm trying to do is really simple, but the last part of it I can't seem to get right... hopefully someone will spot it straight away.

    Code:
    <% 
    
    	fPath = Server.MapPath(".") 
    	
    	qDate = DateAdd("d", -7, Now())
    	
    	Response.write qDate
    	
    	Set objFSO = Server.CreateObject("Scripting.FileSystemObject") 
    	
    	Set Folder = objFSO.GetFolder(fPath) 
    	
    	For Each i In Folder.Files   
    		If i.DateCreated <= qDate Then 
    		'objFSO.DeleteFile(i.Name)
    		Response.Write i.Name & "<br>"
    		End If
    	Next 
    	
    	
    	Set i = nothing 
    	Set Folder = nothing 
    	
    %>
    As you can see, I've got down to selecting all the week old files no problem, but when I come to execute the 'objFSO.DeleteFile(i.Name)' line - I either get file not found or nothing at all.

    Something to do with the ServerPath?

    Thanks for taking a look,

    Andy

  2. #2
    SitePoint Wizard
    Join Date
    Nov 2004
    Location
    Nelson BC
    Posts
    2,310
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    try
    'objFSO.DeleteFile(Folder.Path & "\" & i.Name)

  3. #3
    Original Gangster silver trophy Thing's Avatar
    Join Date
    Oct 2000
    Location
    Philadelphia, PA
    Posts
    4,708
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    Also make sure you have appropriate permissions to delete a file via FSO. Here is a good tutorial to help you set those up if you don't have them already:

    http://www.webwizguide.info/asp/faq/...ermissions.asp

  4. #4
    SitePoint Enthusiast Northern Star's Avatar
    Join Date
    Aug 2006
    Location
    Cheshire, UK
    Posts
    96
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Smile

    Quote Originally Posted by jimfraser
    try
    'objFSO.DeleteFile(Folder.Path & "\" & i.Name)
    Excellent. Thanks Jim... it worked perferctly.

    Turns out I didn't need to do anything about the file permissions, but thanks for the hint 'Thing'.

  5. #5
    SitePoint Wizard
    Join Date
    Nov 2004
    Location
    Nelson BC
    Posts
    2,310
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Oh, hehe, you can also do:
    i.Delete

    =)

  6. #6
    SitePoint Enthusiast Northern Star's Avatar
    Join Date
    Aug 2006
    Location
    Cheshire, UK
    Posts
    96
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hah, ah well... its working now anyway

  7. #7
    SitePoint Wizard siteguru's Avatar
    Join Date
    Oct 2002
    Location
    Scotland
    Posts
    3,631
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    Even with the delete line commented out?

    Ian Anderson
    www.siteguru.co.uk

  8. #8
    SitePoint Enthusiast Northern Star's Avatar
    Join Date
    Aug 2006
    Location
    Cheshire, UK
    Posts
    96
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    That would be worrying! No, I managed to work out the uncommenting myself! I'm a big boy now.
    "If it ain't broken, don't fix it!"
    ----
    Northern Star - Web design, stategy & development.


Bookmarks

Posting Permissions

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