473,610 Members | 2,096 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Batch File To Old Files 5 Days Older

34 New Member
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 1946

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

Similar topics

4
11872
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 older. I was able to figure out how to delete them if they are 5 days older then current date but the weekends and holiday, etc. leave some undeleted. Any help will be greatly appreciated, ShyGuy
6
11211
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 programs and executing registry entries. The majority of my buttons work however, I have come upon a problem. I need a few of the buttons to run DOS batch files, the batch files in turn run program installers (specifically windows update runtime .exe...
1
3167
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 programs and executing registry entries. The majority of my buttons work however, I have come upon a problem. I need a few of the buttons to run DOS batch files, the batch files in turn run program installers (specifically windows update runtime .exe...
13
4296
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 that this is suppossed to end up as a component for others to use, and therefore I do NOT have access to their global.cs::Session_End() how do I cleanup files that were uploaded -- but obviously left stranded when the users aborted/gave up writting...
3
1567
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 certain date. How do I compare the file (date created) to system date? Something like this doesn't work: if System.IO.File.GetCreationTime(path to my file) = date.Now then copy ....
4
2641
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 interested to understand how to create a script to perform my purpose and since this function is useful, what the hey! I am rather new to batch files but would appreciate any help. TIA My process thus far has been the following: I edited the...
3
12532
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 more knowledgable individuals take a look at it and tell me why? Thanx, Beagle Here it is: :: --------DELOLD.BAT---------- @ECHO OFF
5
2220
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 user successfully downloads it, as otherwise my server would eventually get clogged up with all these zip files. Any help/suggestions? Thanks
1
2758
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 perspective, shadows, rounded corners, ... and more in minutes instead of hours or days if you do it manually. Phatch allows you to use EXIF and IPTC tags for renaming and data stamping. Phatch also supports a console version to batch photos on web...
0
1477
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. Heres my problem. I work in the IT department at a local bank and we are in the process of deploying new PCs for some of the employees with older work stations. I just finished staging about a dozen of them and in the next month or so we will...
0
8097
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8559
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8238
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8411
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7036
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6071
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5526
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
1
1692
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
1410
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.