Solved

Batch File

Posted on 2001-09-05
4
325 Views
Last Modified: 2013-12-03
i need a batch file that I can use that deletes files in a specific directory according to their date.

For exampple i need to delete all files older that one month that end in txt.  I'll increase the points if anyone actually manages to do this in a simple dos type batch file.
0
Comment
Question by:leighmurray
4 Comments
 
LVL 8

Expert Comment

by:ViRoy
ID: 6459360
that would require building a batch file that can somehow determine specific sections of a dir
i dont even think its possible in batch

now qbasic could be used to do this
do a "dir /OD > file.txt"
then have a subroutine parse the info for the dates you are looking for.
0
 
LVL 1

Accepted Solution

by:
hide_in earned 100 total points
ID: 6459401
OK, if you want to delete all files (*.txt) in one folder,y
you can do as following:
//-----------------------------------
suppose the path is "c:\test"

WIN32_FIND_DATA FindFileData;
HANDLE hFind = NULL;
HANDLE hFile = NULL;

char szPath[MAX_PATH + 1] = "";
strncpy(szPath, "c:\\test\\*.txt", sizeof(szPath) - 1);
 
hFind = FindFirstFile(szPath, &FindFileData);
if (INVALID_HANDLE_VALUE  != hFind)
{
  while (true)
  {
     if ('\0' != *FindFileData.cFileName)
     {
        // then, you can get the file in the c:\test dir,
        // Add the code to get the file attribute,
       // and judge the time of it if older than you want
     }
     memset(&FindFileData, 0 , sizeof(FindFileData));
    if (TRUE != FindNextFile(hFind, &FindFileData))
       break;
  }
  FindClose(hFind);
}

can you understand ?
0
 
LVL 6

Expert Comment

by:Triskelion
ID: 6466186
Here are some utilities that can do what you want.

Not batch files, though.
Delete Enhanced
http://users.aol.com/pasacaca/delen/delen32.zip
http://users.aol.com/pasacaca/delen/delen16.zip
0

Featured Post

Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

Join & Write a Comment

This tutorial is about how to put some of your C++ program's functionality into a standard DLL, and how to make working with the EXE and the DLL simple and seamless.   We'll be using Microsoft Visual Studio 2008 and we will cut out the noise; that i…
Entering time in Microsoft Access can be difficult. An input mask often bothers users more than helping them and won't catch all typing errors. This article shows how to create a textbox for 24-hour time input with full validation politely catching …
This is Part 3 in a 3-part series on Experts Exchange to discuss error handling in VBA code written for Excel. Part 1 of this series discussed basic error handling code using VBA. http://www.experts-exchange.com/videos/1478/Excel-Error-Handlin…
This tutorial demonstrates a quick way of adding group price to multiple Magento products.

705 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

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now