-
Jul 9th, 2018, 10:12 AM
#1
Thread Starter
New Member
Is anyone able to assist on why files/folders not deleting.
Hi
I have a script that is supposed to find folders that are over 30 days old but its not deleting the files/folders.
I think the issue is that the 7Z files are password protected and also when I click on them the specific 7z folder when clicking on it its not opening the folder but comes up with a window stating "7 ZIP SELF EXTRACTING ARCHIVE" and then asks me where to save to on PC and then when selected that it asks me for the password.
Is this the cause and has anyone any ideas how I can overcome that?
HTML Code:
RemoveOldFiles "S:\CCTV Downloads\Chiltern Downloads", 30, "exe"
RemoveOldFiles "\\crcl.local\ApplicationData\BTPCCTVDownloads", 30, "exe"
Sub RemoveOldFiles(strFolder, intAge, strExt)
' Create file system object
Set objFSO = WScript.CreateObject("Scripting.FileSystemObject")
' Access base folder
Set objFolder = objFSO.GetFolder(strFolder)
' Look at each subfolder in the base folder
For Each objSubFolder In objFolder.Subfolders
' Look at each file in this subfolder
For Each objFile In objSubFolder.Files
' See if the extension matches desired (or if we want all)
strFileExt = LCase(objFSO.GetExtensionName(objFile.Path))
If strExt = "" Or strFileExt = LCase(strExt) Then
' See if the create date is old enough to delete, if so delete it
intFileAge = DateDiff("d", objFile.DateCreated, Now)
If intFileAge > intAge Then
objFile.Delete
End If
End If
Next
' If folder is now empty, we purged its entire contents, so remove it
If objSubFolder.Files.Count = 0 And objSubFolder.Subfolders.Count = 0 Then
objSubFolder.Delete
End If
Next
End Sub
-
Jul 9th, 2018, 02:42 PM
#2
Re: Is anyone able to assist on why files/folders not deleting.
It looks like what you have is a 7 Zip self-extracting archive file. Those are .exe files that create folders and the file contents when run. You could run a script on the files and folders that would do what you want, but you would have to run the .exe files to create them first. If you are wanting to do this without extracting the files/folders, you may be out of luck.
-
Jul 9th, 2018, 03:24 PM
#3
Junior Member
Re: Is anyone able to assist on why files/folders not deleting.
So what you're saying is that I have to run the .exe file first to unzip and then delete the individual files afterwards.
Yes that fine as long as when I delete the files within the folder I can delete the zipped folder too.
The next issue I will think I will have is that all the zipped folders are password protected. Can I still do that without putting passwords in for every folder? as im trying to run a scheduled task every night.
If need be I can do 7zip folders that are NOT password protected.
Is there anyway I can add that to the script above?
-
Jul 9th, 2018, 03:57 PM
#4
Re: Is anyone able to assist on why files/folders not deleting.
A much simpler method would simply be to check the date on the .exe files. If it is more than 30 days old, just delete the .exe file.
1. In Windows Explorer / (My) Computer, display the folder containing the .exe files.
2. Sort the files by Date.
3. Highlight all of the files older than 30 days, and delete them. This will be faster than any script.
Last edited by jdc2000; Jul 9th, 2018 at 04:08 PM.
-
Jul 10th, 2018, 01:35 AM
#5
Thread Starter
New Member
Re: Is anyone able to assist on why files/folders not deleting.
I thought about that.
The only reason that I want to do it automated is there are people who will forget to do it and I cant havestuff in there over 30 days old.
Am I right in saying the only way to delete old files automatically is via a script as I think that possibly where im getting confused.
-
Jul 10th, 2018, 07:19 AM
#6
Re: Is anyone able to assist on why files/folders not deleting.
the zip files are a red herring... to the code, they are just files... the fact that they are psssword protected is irrelevant. there's no need to extract them or anything. If they fall in that 30 day age range, simply delete them.
The problem is your loop.
When you use GetFolders (or GetFiles) it returns an enumeration list, when you then delete , you cause an underlying change to that enumeration, which maybe why it's not always deleting everything. Instead, try putting the results of GetFolders and GetFiles into an array and then loop through the array... see if that helps.
-tg
-
Jul 10th, 2018, 07:52 AM
#7
Thread Starter
New Member
Re: Is anyone able to assist on why files/folders not deleting.
Thanks for that techgnome I sort of understand where your coming from and it possibly in this line?
' Access base folder
Set objFolder = objFSO.GetFolder(strFolder)
Sorry but I aint got a clue on how to change that.
Any ideas ?
Thanks
-
Jul 10th, 2018, 10:42 AM
#8
Re: Is anyone able to assist on why files/folders not deleting.
-
Jul 10th, 2018, 11:41 AM
#9
Re: Is anyone able to assist on why files/folders not deleting.
Sorry, I mis-read the lines, it's the .SubFolders line and the .Files line.
instead of
Code:
For Each objSubFolder In objFolder.Subfolders
use
Code:
FolderList = objFolder.SubFolders
For each objSubFolder in FolderList
that "should" work.
-tg
-
Jul 11th, 2018, 04:53 AM
#10
Thread Starter
New Member
Re: Is anyone able to assist on why files/folders not deleting.
Morning
Tried script and it doing nothing. Just one other thing I forgot to mention and donno if it makes any difference but the files im trying to delete are off a network.
Big Big apologies if it does and that I didnt mention first.
Ive been playing around with it using "C" drive this morning and Ive unzipped a 7z file and it shows the folder and the 7z application
I changed the script to "date modified" as I have nothing past date created apart from today.
If I save script as a .VBS it deletes the FOLDERS that are over the number of days specified but NOT the .EXE files and it also comes up with error shown below
LINE 24
CHAR 17
ERROR OBJECT DOSENT SUPPORT THIS PROPERTY OR METHOD : "objFile.Datemodified"
CODE 800A01B6
If I save as a .BAT file it does nothing.
Last edited by shreked; Jul 11th, 2018 at 05:04 AM.
Reason: duplicated accounts used wrong on in error
-
Jul 11th, 2018, 07:29 AM
#11
Thread Starter
New Member
Re: Is anyone able to assist on why files/folders not deleting.
Im no expert at this at all but ive been reading through the script again and noticed this section. Please excuse me for being thick but where it says
strFileExt = LCase
Open in new window
does that mean look for "LOWER CASE" as all my file names are in upper case or are only numbers .
See if the extension matches desired (or if we want all)
strFileExt = LCase(objFSO.GetExtensionName(objFile.Path))
If strExt = "" Or strFileExt = LCase(strExt) Then
-
Jul 11th, 2018, 09:31 AM
#12
Re: Is anyone able to assist on why files/folders not deleting.
no... it means make lower case ... so if it was "EXE" it makes it "exe" . so the comparison becomes "exe" = "exe" rather than "exe" = "EXE" or "exe" = "ExE" or.... you get the idea.
-tg
-
Jul 11th, 2018, 09:41 AM
#13
Thread Starter
New Member
Re: Is anyone able to assist on why files/folders not deleting.
Thanks for that.
Any idea on the error code shown in post above it ?
-
Jul 11th, 2018, 09:56 AM
#14
Re: Is anyone able to assist on why files/folders not deleting.
-
Jul 11th, 2018, 12:11 PM
#15
Re: Is anyone able to assist on why files/folders not deleting.
Also, it's VB code, so it's only going to run in a VB app or VBScript file... it's NOT commandline so it isn't going to work as a BAT file...
As for the error... it seems to haverun into an object (could be a file could be a folder) that doesn't have the DateModified property on it... *shrug* don't know why it wouldn't. But I also don't know what object it's run into. You'll need to add some error handling or some logging to track what has been processed in order to find out what might be causing the problem.
-tg
-
Jul 11th, 2018, 12:35 PM
#16
Junior Member
Re: Is anyone able to assist on why files/folders not deleting.
OK will do at least I know now it a .bat file sorry for being dumb
When you say it seems to have run into an object (could be a file could be a folder) that doesn't have the DateModified property on it.
does that mean that when you open the folder I have to have it showing "DATE MODIFIED" in the list .
At present I only have NAME /DATE CREATED / TYPE /SIZE
Last edited by tweacle; Jul 11th, 2018 at 12:42 PM.
-
Jul 12th, 2018, 11:10 AM
#17
Re: Is anyone able to assist on why files/folders not deleting.
The fields that you have Windows Explorer set to display should not affect the code, however, if you add the Date Modified, you may be able to see if any data is missing from that field for the item(s) in question.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|