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.
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
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?
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?
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.
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.
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.
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.
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?
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?
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:
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
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?
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.
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.
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.
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.
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.
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'
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.
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.