FileSystemObject Delete 'Week Old' Files

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.

<%
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?

View Replies


ADVERTISEMENT

Filesystemobject Delete

why this code doesnt' work, it deletes the first file but not the second, the error I get states

Microsoft VBScript runtime error '800a01a8'
Object required: 'ojbFSO2'

Code:

Dim objFSO
Set objFSO = Server.CreateObject("Scripting.FileSystemObject")
objFSO.DeleteFile(Server.mapPath(img)), False
Set objFSO = Nothing
img = ""
if rs("ew") <> "" Then
img = "../../images/gallery/enlarge/" & rs("image")
Set objFSO2 = Server.CreateObject("Scripting.FileSystemObject")
ojbFSO2.Deletefile(Server.mapPath(img)), False
Set objFSO2 = Nothing
End If

View Replies View Related

Sorting Files Using FileSystemObject

Quick Question: Using the FileSystem Object in Classic ASP is there any way to read the files in a folder in the order they were created?

Dim ObjFSO, ObjFile, ObjFolder, x
Set ObjFSO = Server.CreateObject("Scripting.FileSystemObject")
Set ObjFolder = ObjFSO.GetFolder(Server.MapPath("../myfolder"))
x= 0

For Each ObjFile in ObjFolder.Files
Do while x <10
Response.write(ObjFile.Name & " - " & ObjFile.DateCreated)
x = x+1
Loop
Next

This script reads in the first 10 files found in the designated folder, but how can I be sure of getting the 10 most recent files? It seems that the default ordering is by file name.

The only method I have at the moment is to read in ALL the files attributes into Arrays and performing a Bubble Sort. This gets increasing inefficient as more files are added to the folder I am reading from.

Is there any methods in the FileSystem or Folder Object which will allow me to sort the files by DateCreated or Modified before selecting the first 10 files I find?

View Replies View Related

FileSystemObject To Read Text Files

Can I use FileSystemObjects to Read Text Files on my server rather than just on my local drive?

View Replies View Related

Using Filesystemobject To Combine Text Files?

I have several text files on my server and I would like to combine them into one text file by just appending each file to the end of the combo file. I know this should be possible, I just don't know how to approach it. Some combination of OpenTextFile and CreateTextFile?

View Replies View Related

Delete Files

Is it possible after i run my process i delete text files from server.
I run a process to read from text files after that i want to delete
these text files so that no one again run the process.I am using ASP.

View Replies View Related

Uplode And Delete Files

Could anybody show me an example of code to upload files from a local drive, and delete files from the website. of course the easiest way to do that is to use any FTP client.

View Replies View Related

How Can I Delete All Files On Server?

i want to delete all files from a dir off the server any suggestions?I know how to delete specific files but i dont know how to delete all files.

View Replies View Related

Delete Files Off The Server

Linux Server with Chillisoft ASP.

How would I get an ASP page to delete an image file, probably a .jpg off the server.

Basically, what I want to do, is that when the user deletes a product item from the database, it will also delete the corresponding image file from the images folder. So that the server space doesn't just fill up with redundant image files over time.

If it makes any difference the image files are uploaded using a PHP script, I've no idea how it works, but it does.

View Replies View Related

Delete Files In Server

I have a Product and that product contains some documents.The documents are uploaded to server and can be viewed in my asp application.

In admin module i have given option to edit or delete that product.In the event of edit just the records in the database get changed.But in the case of delete i have to do 2 things

1. Delete all the data related to that product.
2. Delete all the related documents for that product in the server.

So can anybody help me figure out how to delete a file using asp in ftp server.

View Replies View Related

Concerning Delete A Directory With Files

I understand how to delete files within a directory using the Scripting.FileSystemObject.
However, how can I delete a directory using ASP 2.0 on an older IIS 4.0 server? Do I need to:

1. Delete all the files within the directory.
2. Change the directory's permissions.
3. Delete the directory.

Am I able to delete a directory without changing the permissions? Can I delete a directory with files inside the directory or does the directory need to be empty?

View Replies View Related

Delete Files In Folder

I need to create a script that deletes all pdf files in a folder that are over 1 day old. I know I need to use the file system object and datediff but can't for the life of me work it out. I am a bit of a newb when it comes to more complicated asp .

Does anyone have a script that does this or know of a tutorial that will teach me how to do it?

View Replies View Related

Delete Files In Directory!

I am wanting to delete all files contained in a directory.
I won't have the name of the file...

Can i do this somehow??

View Replies View Related

Delete Temporary Files

Is it possible to delete internet temporary files using ASP code? And maybe specify the extension of the files to delete?

View Replies View Related

FSO Delete Files As Read From Recordset

I have client who has database full of crap. One field in the "property" table is imageurl. I have been able to successfully extract only the file name from the string, such as "2030323.jpg". All images are stored in a directory called "listings". What I am trying to do is to loop through the recordset, and read each imageurl.

If there is an image file in the "listings" directory, then delete the file. It appears that some fields contain imageurls that no longer exist in the listing directory. Here is the code I have so far, I almost had it, as it told me at one point the file didn't exist. Then I screwed up the code and this is where I am at: Code:

View Replies View Related

Multiple Delete Of Files With FSO Error

I try to do a multiple delete of files through FileSystemObject, but after deleting the first file, ASP gives me a "Permission denied" error. Below you see my code:

Set fso = CreateObject("Scripting.FileSystemObject")
For Each Item in Request.Form("filename")
delFile = path2 & "files" & Item
fso.DeleteFile delFile
Next

View Replies View Related

Deleting Files From Server... ObjFso Delete

I'm trying to delete files from the server and its not working. Can any one help please?
It says the file doesn't exist... where as the file exists...

I did a response.write for my delFile to make sure its there but it doesn't see the file... Code:

View Replies View Related

First Day Of Week

I need the formula to return me the first day of the current week.. I've searched for 2 hours online and haven't come up with a classic asp example.

For instance - when the formula is run today, it should return 6/5/2006.. when it is run this thursday, it will be the same.

I have this working in T-SQL right now, it looks like this: DATEADD(day, 1-DATEPART(dw, GETDATE()), DATEADD(day, DATEDIFF(day, 0, GETDATE()), 0))

Perhaps this could get converted to asp >?

View Replies View Related

Day Of Week

I know there is a function that shows: <% = date %>, which gives: 2/17/2006, is there any way to show the day of year? Example: Today is 2/17/06, but the 48th day of the year. Is there any call to get the 48th day?

View Replies View Related

Getting Day Of Week

Is there a built in ASP function for getting the day of the week? Ultimately I'm trying to come up with the output:

Thursday, September 23, 2004.

View Replies View Related

First Day Of Week

Need to print "Week of (first day of week)" First day being Monday.

ie:
week = Request.querystring("mydate")
response.write "Week of" & week

If week = 5/6/2004 (which is Thursday) it should output "Week of Monday, May 03, 2004"
How can I do this?

View Replies View Related

Get Date From Week.

Currently i'm working on a application and i have no idea how to get the date for it. This is the scenario.

User will key in this code. For example 07W04. This mean is fourth week of 2007. So now i need to find out the date from the given code. I think of since 1 week is 7 days therefore fourth week should be 7 X 4 so the date will be 28. But then that is for the first month. The others i need to think for the 30 and 31.

So is there any solution for this? I think this is not an easy way. So hope some helps from you all or any function for this.

View Replies View Related

Get Week Number

Does anybody know how I can get the week number. The week number we are currently on is 28 and I need to be able to reitrieve this number so that i can manipulate for loops to advance that number to 33 and 38.

View Replies View Related

End Dates For A Week

If I know the week number and the year, how can I calc the beginning and
ending dates of the week?

For background I'm going to do some grouping by week but don't just want
to call the weeks Week 25, Week 26, Week 27, etc.

View Replies View Related

Week Calculations

I'm looking for a function that returns a date range for a specified week number of the year I'm not able to find functions like this anywhere.

View Replies View Related

Work Week

I need to provide a pulldown with work weeks displayed.Is there any easy way to do this?

I would like to go 6 months from the current date and show a week as Oct. 11- 15.Which is Monday to Friday.

View Replies View Related

Week Number

I am trying to figure out a way to get the week number of the current week. I know this is relatively easy using the calendar year (starting from January to now). However, I want to do it so I start in October on the first monday of the month, so today's date would be the 10th week.

View Replies View Related

New Record Every Week

Is it possible (how) to display a new record every week (or day) from a recordset?

View Replies View Related

Records From Last Week

I'm trying to create a page that displays records from an SQL database for any records that were created in the last week. I'm stuck on syntax.

I know I have to do something with the date field along the lines of SELECT * FROM table WHERE theDate <= "& now() -7 & " ... or something like that, but I don't know how to format now() or date() for anything other than their defaults.

View Replies View Related

Week From Month

If I would like to get the week number for month, let's say today is July 25, 2005, which is the fourth weeks for July, how can I use base on the date I have and convert to get the week number in ASP.

View Replies View Related

Convert The Week To Date

Can anyone please tell me is there any method to convert the week to the date?? For example If the week is 6 then we can get the date where the date is between '2/1/2004'
and '2/7/2004'

View Replies View Related

Display A Different Txt File Every Week

I've made up a set of simple tide table files in notepad showing high and low tides. Each file is for 1 week (7 days) from Sunday to Sunday.

At present I change the text file manually every Sunday...Erm, ok, most of the time anyway.

How can I call a different text file on a weekly basis, using ASP, from the directory which the .txt files are all stored in. (The site is an asp driven site)

The existing files are each named by the starting Sunday date.....18_04_04.txt. (UK date format, sorry), but it'd be no effort to number them sequentially if neccesary.

View Replies View Related

Messages For The Current Week

I have a db with the fields Day, Month, Year and Message. How can I select all of the messages for the current week starting with sunday and return the results as a list.

View Replies View Related







Copyrights 2005-15 www.BigResource.com, All rights reserved