Solved

Batch File

Posted on 2001-09-05
4
327 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
SQL Server Express 2014 Master / Slave database replication 4 392
Example of WebAPI 7 32
Explain Unit of Work pattern 2 55
Why is "packages element is not declared"? 2 124
This article describes how to add a user-defined command button to the Windows 7 Explorer toolbar.  In the previous article (http://www.experts-exchange.com/A_2172.html), we saw how to put the Delete button back there where it belongs.  "Delete" is …
What my article will show is if you ever had to do processing to a listbox without being able to just select all the items in it. My software Visual Studio 2008 crystal report v11 My issue was I wanted to add crystal report to a form and show…
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 is a video describing the growing solar energy use in Utah. This is a topic that greatly interests me and so I decided to produce a video about it.

914 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

16 Experts available now in Live!

Get 1:1 Help Now