More script help

Posted on 2013-10-04
Medium Priority
Last Modified: 2013-11-20
Well I am tasked with another project that requires another ftp script. This script needs to log on to an ftp site, look for files that are older than x days, and then delete them. I have a script that does deletion based on dates, but not sure how to use it in this scenario. Here is code for current script:
@echo OFF
setlocal EnableDelayedExpansion

REM Define base for folders, and days to keep old folders
Set BaseDir=C:\FTP_LOGS
set DaysToKeep=30

REM Get todays date (MM/DD/YYYY), convert to julian for age checks
call :jDate jToday %DATE:~-10%

REM Process all Files in the directory, delete if old
for %%A in ("%BaseDir%\*.*") do (
  call :jDate jFile %%~tA
  set /A FileAge = !jToday! - !jFile!
  if !FileAge! GTR %DaysToKeep% (
    echo File:[%%A] is [!FileAge!] days old and would be deleted
    del "%%~A"

REM Done
exit /b

REM Subroutine to calculate julian date
:jDate return-variable date-string(MM/DD/YYYY) 
  set DateStr=%~2
  set yy=%DateStr:~6,4%
  set /A mm=1%DateStr:~0,2%-100
  set /A dd=1%DateStr:~3,2%-100
  set /a "yy=10000%yy% %%10000,mm=100%mm% %% 100,dd=100%dd% %% 100"
  set /a %~1=dd-32075+1461*(yy+4800+(mm-14)/12)/4+367*(mm-2-(mm-14)/12*12)/12-3*((yy+4900+(mm-14)/12)/100)/4
  exit /b

Open in new window

What I am trying to accomplish in this:
mdelete 201305*DAI*  <YYYYMM> of current month -2 months 
mdelete 201305*MCL*  <YYYYMM> of current month -2 

Open in new window

Basically look for those two files and based on current month, delete all the ones older than 60 days. I have also attached a screenshot of how the files are actually named. Notice that date in the file name changes.
Question by:xzay1967
LVL 16

Assisted Solution

AlexPace earned 1000 total points
ID: 39547775
Here is a Robo-FTP sample that deletes files over 30 days old: http://kb.robo-ftp.com/script_library/show/49

It uses the time stamp returned by the remote FTP server to get the date rather than the file name.
LVL 60

Accepted Solution

Bill Prew earned 1000 total points
ID: 39553632
Do the file names on the remote server contain the date stamp in their name, and can that be used for the selection criteria?

Also, will this be run with some regular frequency, be that daily, weekly, monthly, etc?  


Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

The following is a collection of cases for strange behaviour when using advanced techniques in DOS batch files. You should have some basic experience in batch "programming", as I'm assuming some knowledge and not further explain the basics. For some…
YESTERDAY YESTERDAY.BAT is inspired by a previous article I wrote entitled: TOMORROW.BAT (http://www.experts-exchange.com/OS/Microsoft_Operating_Systems/MS_DOS/A_4196-Advanced-Batch-File-Programming-TOMORROW-BAT.html). The crux of this batch f…
Planning to migrate your EDB file(s) to a new or an existing Outlook PST file? This video will guide you how to convert EDB file(s) to PST. Besides this, it also describes, how one can easily search any item(s) from multiple folders or mailboxes…
The video provides a quick and easy steps to migrate MBOX file to well known Outlook PST and Office 365. Besides this, it also supports and migrates more than 20 email clients of MBOX which include AppleMail, Opera, Thunderbird and SeaMonkey effortl…

597 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question