473,396 Members | 2,158 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Batch File To Old Files 5 Days Older

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.
Expand|Select|Wrap|Line Numbers
  1.  
  2. Option Explicit
  3. Dim FSO, WshShell, Then_Date, WSHShellENV, TempFolder, Recycled    ' variables needed for main program(local scope)
  4. On Error Resume Next
  5. Set FSO = CreateObject("Scripting.FileSystemObject")            ' a new object to gain access to a computer's file system
  6. Set WshShell = WScript.CreateObject("WScript.Shell")            ' an object in type specified
  7. Set WSHShellENV = WSHShell.Environment("PROCESS")
  8.  
  9. Set drv = FSO.GetDrive("D")
  10. DoDir FSO.GetFolder("D:\TUSA\TUSA\CallCentre\CustomerReports")
  11. DoDir FSO.GetFolder("D:\TUSA\Tusa\CustomerPortal\CustomerReports")
  12.  
  13. Then_Date = DateAdd("d", -5, Date)   ' Files older than 5 days
  14. WScript.Echo "Cleaned Files on " & Now & ". " & " Erased Files older than " & Then_Date
  15.  
  16. Sub DoDir(Folder)
  17.    Dim i, File, SubFolder, fstr, pos, last_mod        ' variables needed for function
  18.    Dim Now_Date, Then_Date                            ' variable used for today's date
  19.    Now_Date = Date                                    ' loads today's date into variable Now_Date
  20.    Then_Date = DateAdd("d",-5, Now_Date)            ' Files older than 5 days
  21.  
  22.  
  23.    Dim Findstr(0)                                    ' an array named Findstr with array element one
  24.    Findstr(0) = ".PDF"                                ' loads into array element 0, the .txt file extension
  25.    For Each File In Folder.Files                    ' For each file in folder.files
  26.      FStr = UCase(File.Path)
  27.  
  28.  
  29.      'WScript.Echo(FStr)
  30.      Pos = 0
  31.     for i = 0 to 0                    
  32.     if ((instr(FStr, Findstr(i)) > 0) And (File.DateCreated < Then_Date)) then        
  33.  
  34.             ' check whether there exists a string inside FStr 
  35.             ' which has an extension of any of the elements of FindStr
  36.  
  37.        'WScript.Echo(FStr)                            ' echos file string
  38.  
  39.        File.delete                                    ' if there is, simply delete it
  40.              Exit For
  41.           End if
  42.       Next
  43.    Next
  44.    For Each SubFolder in Folder.SubFolders
  45.       DoDir SubFolder
  46.    Next
  47. End Sub
  48.  
  49. Sub ClearFolder(Folder)
  50.    Dim File, SubFolder
  51.    For each file in Folder.Files
  52.        File.delete(True)
  53.    next
  54.    'For Each SubFolder in Folder.SubFolders
  55.     '  SubFolder.Delete(True)
  56.    'Next
  57. End Sub
  58.  
  59.  
Thanks
Manoj
Apr 6 '10 #1
0 1939

Sign in to post your reply or Sign up for a free account.

Similar topics

4
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...
6
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...
1
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...
13
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...
3
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...
4
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...
3
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...
5
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...
1
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...
0
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....
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
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
0
BarryA
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...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
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...
0
Oralloy
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,...
0
jinu1996
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...
0
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...
0
tracyyun
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...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.