Cognos BI 8.1 and higher
How do I erase old transformer mdc cube files from a folder?
In many cases you create a new powerplay cube file every night with Cognos transformer. Then you get a lot of MDC files in a folder. But you want the old cube files to be erased.
In the creation process of the powercubes MDC file you add the date in the name as;
Create a batch file that contains below text,
Place the script file erasecube.cmd in the same folder as the mdc cube files.
Run the script as part of the cube build process.
The script will erase all MDC files that do not have today’s date in the name.
Rem checks today date and format it to the variable currentdate
rem List the cubes to be deleted
dir /B *.mdc | find /V "%currentdate%" > delete.list
rem Deleting the cubes
for /F %%j in (delete.list) do del /Q %%j
rem Deleting the list of used above
del /Q delete.list
Ensure you test the script before you use it in production.
You must change the line “set currentdate=%date:~3,4%%date:~8,2%%date:~11,2%”
to get it to work with your regional settings on the computer.
MS-DOS function date:~3,4 is 3 the position before first character to use, and 4 is the number of characters to use in the date string.
In a MS-DOS prompt on the Cognos server;
Check today’s format by type DATE /T in the prompt
You may see the date as 2010-03-26
Then you need to change the currentdate line to reflect this
Above may give that variable currentdate is “0-0326”.
You change the line to be like below to get the right format.
You can check by run above command in MS-DOS box
Then enter %currentdate% to see the value in the variable.
'20100326' is not recognized as an internal or external command,
Operable program or batch file.