While reviewing my system recently I noticed that I had log files in my installation’s logging folder ([Install Directory]\SAP BusinessObjects\SAP BusinessObjects Enterprise XI 4.0\logging) going back almost two years. I thought it would be good to create a scheduled process to only retain the most recent (e.g. 180 days) log files.
While researching how to do this I came across a command that I had never used before, forfiles which “selects and executes a command on a file or set of files.” The documentation says this command is only available on for Windows 8, Windows Server 2008, Windows Server 2012, Windows Vista.
So I used the following command to clean up my logging directory.
forfiles /p “[Install Directory]\SAP BusinessObjects\SAP BusinessObjects Enterprise XI 4.0\logging” /m *.* /c “cmd /c del @file” /d -180
I then created this as a weekly scheduled task in Task Scheduler.
This did expose a rather interesting issue. I ran my scheduled task and it deleted some of the files I was expecting it to, but not all of them. As I soon discovered the path and filename of the files it did not delete was too long. I could not manually delete them, nor could I move them. I came across this forum post in regard to this issue. A lot of different approaches are mentioned including some disk utility applications. However, the most straightforward approach that worked for my situation and didn’t require any extra tools was given by “PD Duke”…
- Drill down into the folders to the folder that has the problem file(s) in it.
- Share the folder that contains the file.
- Map a network drive to the folder with the problem file(s).
- Open the mapped drive and delete the file(s) causing the problem.
- Disconnect the map drive.
- Remove the share.
I was not able to delete the files with my forfiles command, but I could delete the files manually from Windows Explorer. Perhaps with further investigation I could get it to work using forfiles.
Certainly, there are other options for deleting files of a certain age and for dealing with the issue of the path and filename being too long. I just wanted to share what I had learned in the hopes of providing a solution directly or sparking someone’s thinking to discover their own.
BTW, anyone know why these log files have long filenames like this?