Hi,
I need a batch file to delete all PDF files in a folder and it's subfolders. I will be giving the folder path and number of old days to delete as static values..
Please it's very urgent. Also I have a VBScript file which works fine for the same. -
-
Option Explicit
-
Dim FSO, WshShell, Then_Date, WSHShellENV, TempFolder, Recycled ' variables needed for main program(local scope)
-
On Error Resume Next
-
Set FSO = CreateObject("Scripting.FileSystemObject") ' a new object to gain access to a computer's file system
-
Set WshShell = WScript.CreateObject("WScript.Shell") ' an object in type specified
-
Set WSHShellENV = WSHShell.Environment("PROCESS")
-
-
Set drv = FSO.GetDrive("D")
-
DoDir FSO.GetFolder("D:\TUSA\TUSA\CallCentre\CustomerReports")
-
DoDir FSO.GetFolder("D:\TUSA\Tusa\CustomerPortal\CustomerReports")
-
-
Then_Date = DateAdd("d", -5, Date) ' Files older than 5 days
-
WScript.Echo "Cleaned Files on " & Now & ". " & " Erased Files older than " & Then_Date
-
-
Sub DoDir(Folder)
-
Dim i, File, SubFolder, fstr, pos, last_mod ' variables needed for function
-
Dim Now_Date, Then_Date ' variable used for today's date
-
Now_Date = Date ' loads today's date into variable Now_Date
-
Then_Date = DateAdd("d",-5, Now_Date) ' Files older than 5 days
-
-
-
Dim Findstr(0) ' an array named Findstr with array element one
-
Findstr(0) = ".PDF" ' loads into array element 0, the .txt file extension
-
For Each File In Folder.Files ' For each file in folder.files
-
FStr = UCase(File.Path)
-
-
-
'WScript.Echo(FStr)
-
Pos = 0
-
for i = 0 to 0
-
if ((instr(FStr, Findstr(i)) > 0) And (File.DateCreated < Then_Date)) then
-
-
' check whether there exists a string inside FStr
-
' which has an extension of any of the elements of FindStr
-
-
'WScript.Echo(FStr) ' echos file string
-
-
File.delete ' if there is, simply delete it
-
Exit For
-
End if
-
Next
-
Next
-
For Each SubFolder in Folder.SubFolders
-
DoDir SubFolder
-
Next
-
End Sub
-
-
Sub ClearFolder(Folder)
-
Dim File, SubFolder
-
For each file in Folder.Files
-
File.delete(True)
-
next
-
'For Each SubFolder in Folder.SubFolders
-
' SubFolder.Delete(True)
-
'Next
-
End Sub
-
-
Thanks
Manoj
0 1939 Sign in to post your reply or Sign up for a free account.
Similar topics
by: Shyguy |
last post by:
I have a database that backs up critical tables to a database, named
Backup with the date, daily. I can't figure out how to delete these
databases programmatically, say when they are 5 days old or...
|
by: Charles Neitzel |
last post by:
I'm trying to write a windows application in C# (Using Microsoft Visual C#
2005 Express) that is nothing more than a simple UI with buttons on it. The
buttons do various things like running...
|
by: Charles |
last post by:
I'm trying to write a windows application in C# (Using Microsoft Visual
C#
2005 Express) that is nothing more than a simple UI with buttons on it.
The
buttons do various things like running...
|
by: Sky Sigal |
last post by:
I have created an IHttpHandler that waits for uploads as attachments for a
webmail interface, and saves it to a directory that is defined in
config.xml.
My question is the following:
assuming...
|
by: Martin Ho |
last post by:
Can someone help me with this please? I wasn't very clear in my old
post.
I have a program to copy files from one location to another, now I
want to copy only those files which were created on...
|
by: |
last post by:
Hello,
I am attempting to convert multiple .wav files to the .flac format via a batch script. I know that this can be done with numerous software implementations automatically for me; however, i am...
|
by: Beagle |
last post by:
I have a batch file that I am using to delete older files in a directory. It runs great from Windows 2000 computers. However, I now need it to run from Windows XP and it won't. Will one of you much...
|
by: techusky |
last post by:
I made a script that successfully creates a .zip file of all the files
in a directory on my web server, but now what I haven't figured out
how to do is how to have it automatically deleted when the...
|
by: SPE - Stani's Python Editor |
last post by:
Phatch is a simple to use cross-platform GUI Photo Batch Processor
Phatch handles all popular image formats and can duplicate (sub)folder
hierarchies. It can batch resize, rotate, apply...
|
by: =?Utf-8?B?UnVzdHlfUm9zZXI=?= |
last post by:
Hi everyone,
I'm having some issues figuring out how to complete certain tasks
with a batch file, whether it be not knowing the right syntax or if it can
even be accomplished with a batch file....
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: emmanuelkatto |
last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud.
Please let me know.
Thanks!
Emmanuel
|
by: BarryA |
last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
by: Hystou |
last post by:
There are some requirements for setting up RAID:
1. The motherboard and BIOS support RAID configuration.
2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers,...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
| |