Find Name And Remove Oldest

Find Name And Remove Oldest
Hello,

I need a program that i can run on a Windows 2003 machine.

Best would be a .exe file – but .php will work also.

I need a script that can to do this:

1. scan this folder

C:\FTP-Root\C.SWARM\

2. Look for all files with the extenstion *.id – that might exists within that folder.

3. All the *id files has a first name of %year%-%month%-%hour%-%minute%-%second%-DMDS.id

example names below (three clients):

2010-02-21-14-35-01-DMDS.id
2010-03-21-14-36-01-DMDS.id
2010-04-21-15-35-01-DMDS.id

4. I then need the script to look inside each and every one of the *id file(s) thas is found.

within each id file i have a client name such as:

DMDS-XLS-0001
DMDS-HLS-0001
DMDS-FLX-0005

The above is an example name of three clients (computers).

They all have the above name strucutre – but the names are very radom the three letters in the middle and the number.

I want the script to look if the same client name exists within one or more *.id file(s).

It should only be one *id file with one client name. There should never be several *id files with the same clients name.

5. if the script does not detect that an client name exists in more than one *id file – the script can exit nicely.

6. If the script does detect that a client name does exist in more than one *id file – the script should first:

* create this text file: c:\DMDS\Cleanup\duplicate-client-name-exists.mvg

* create this file: C:\cDMDS\Cleanup\files-to-remove.bat

Within the files-to-remove.bat i want then name of *id file that should be remove: %year%-%month%-%hour%-%minute%-%second%-DMDS.id

The “files-to-remove.bat” should hold the name of the oldest id file that is a duplicate.

7. so i want to find duplicate files (that has the same client name twice) – and i want to keep the newest of the id files and only remove the oldest.

then i want the oldest name inside that .bat file so i can remove it.

8. I also need the script to output debug information to a log file somewhere so i can see what its doing.

i plan to schedule this script to run each 10th minute.

Thanks for help,

Best regards,
Johan

Leave a Reply

Your email address will not be published. Required fields are marked *