Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Batch File

Posted on 2001-09-05
4
Medium Priority
?
347 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 200 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

Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article describes how to programmatically preset the "Pages per Sheet" option that's available with most printer drivers.   This setting lets you do "n-Up" printing, where two, four, or more pages are printed on each sheet of paper. If your …
With most software applications trying to cater to multiple user needs nowadays, the focus is to make them as configurable as possible. For e.g., when creating Silverlight applications which will connect to WCF services, the service end point usuall…
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…
In response to a need for security and privacy, and to continue fostering an environment members can turn to for support, solutions, and education, Experts Exchange has created anonymous question capabilities. This new feature is available to our Pr…

886 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