Jump to content

Delete one or the other but never if both exist


 Share

Recommended Posts

We have files numbered files that are paired but with different extensions. For example: TMS_WS1.ACT & TMS_WS1.TMS / TMS_WS2.ACT & TMS_WS2.TMS.

On occasion, the program will hiccup and only one of the paired files will exist. This causes our backups to fail. What I would like is for a script to see if one of the files is missing, if one is missing, then it will delete the other file. It can never delete both files. In addition to that, I would like to create a log of the file that was deleted. TMS_WS1.ACT & TMS_WS1.TMS may not always be there (should only appear when the user is logged into the program).

Below is my script, but as you can see it is a little flawed. If TMS_WS1.* doesn't exist it will try and delete both the .ACT and .TMS file (even though both are already gone). When I implement the logging function, it will log "deleted" files even though they were not there from the start.

When this script runs ideally there will be zero TMS_WS1.* files. I just want to prevent a log being created for a deleted file that wasn't there. If that is understandable :rolleyes:.

Thanks for your help,

-mjg

Link to comment
Share on other sites

Perhaps this would work better?

For $node = 200 To 1 Step -1
    If Not (FileExists("TMS_WS" &aÈ    ÌÍÛÙH   [È ][ÝËPÕ   ][ÝÊH[[Q^ÝÊ ][ÝÕT×ÕÔÉ][ÝÈ   [²b33c¶æöFRfײgV÷C²åDÕ2gV÷C²FVà bfÆTW7G2gV÷CµDÕ5õu2gVÐìµÀìÀÌØí¹½µÀìÅÕ½Ðì¹
PÅÕ½Ðì¤Q¡¸¥±±Ñ ÅÕ½ÐíQ5M}]LÅÕt; & $node & ".ACT")
        If FileExists("TMS_WS&quÝÈ    [È ÌÍÛÙH   [È ][ÝËTÉ][ÝÊH[[Q[]J  ][ÝÕT×ÕÔÉ]÷C²fײb33c¶æöFRfײgV÷C²åDÕ2gV÷C² VæD`¤æW

Link to comment
Share on other sites

That worked very well, but now I'm have another issue. I've tried to add the "logging" feature, but am having some issues.

Here is my code:

#include <Date.au3>
$date = _NowDate()
$UserFile = FileOpen    ][ÝÞÌLÝØXÝ    ][ÝËJBÜ  ÌÍÛÙHHÈHÝLBYÝfÆTW7G2gV÷CµDÕ5õu2gV÷C²fײb33c¶æöFRfײgV÷C²ä5BgV÷C²æ¥±á¥ÍÑÌ ÅÕ½ÐíQ5M}]LÅÕ½ÐìµÀìÀÌØí¹½µÀìÅÕ½Ðì¹Q5LÅÕ½Ð줤Q¡n
        If FileExists("TMS_WS" & $node & ".AC   ][ÝÊH[[Q[]J   ][ÝÕT×ÕÔÉ][ÝÈ   [È ÌÍÛÙH   [È ][ÝËPBgV÷C² fÆUw&FTÆæRb33cµW6W$fÆRÂgV÷CµW6W#¢gV÷C²fײW6W$æµÀìÅÕ½Ðì±ÑQ5M}]LÅÕ½ÐìµÀìÀÌØí¹½µÀìÅÕ½Ðì¹
P½¸Ñ¡s " & $date & " date.")
            FileClose($User[JBBY[Q^ÝÊ ][ÝÕT×ÕÔÉ][ÝÈ   [È ÌÍÛÙH   [È ][ݲåDÕ2gV÷C²FVâfÆTFVÆWFRgV÷CµDÕ5õu2gV÷C²fײb33c¶æöFRfײgV÷ì¹Q5LÅÕ½Ðì¤($$%¥±]É¥Ñ1¥¹ ÀÌØíUÍÉ¥±°ÅÕ½ÐíUÍÈèÅÕ½ÐìµÀìUÍrName & " deleted TMS_WS" & $node & ".TMS oÈ  ][ÝÈ  [È ÌÍÙ]H    [È ][ÝÈ]K][ÝÊBBBQ[PÛÜÙJ ÌÍW6W$fÆR¢VæD`¤æW@

Now the issue that I'm having is when it writes to the log file, the node always appears to be 122. Also it is only writing one entry even though it goes about deleting several files. Any thoughts on how I could make this work correctly?

Thanks again!,

-mjg

Link to comment
Share on other sites

There are some EndIf statements missing. The only reason I didn't include them the first time, was because it was only one action being performed if the statement was true, so I left it on the "If" line. Let me know if this works better:

Link to comment
Share on other sites

Ok, that worked very well with the correct node; however, it is only writing one entry (even though several files are being deleted). I can run the script once and it will record the deleted file, re-run it and it will record that it deleted another file; however, if it deletes two or more in one running it only logs one deletion. Any idea how to make it log for each deletion?

Thanks so much for your help thus far,

Link to comment
Share on other sites

Oh! I'm sorry. It's probably because of the FileClose command. Let's try moving it:

#include <Date.au3>
$date = _NowDate()
$UserFile = FileOpen    ][ÝÞÌLÝØXÝ    ][ÝËJBÜ  ÌÍÛÙHHÈHÝLBYÝfÆTW7G2gV÷CµDÕ5õu2gV÷C²fײb33c¶æöFRfײgV÷C²ä5BgV÷C²æ¥±á¥ÍÑÌ ÅÕ½ÐíQ5M}]LÅÕ½ÐìµÀìÀÌØí¹½µÀìÅÕ½Ðì¹Q5LÅÕ½Ð줤Q¡n
        If FileExists("TMS_WS" & $node & ".AC   ][ÝÊH[[Q[]J   ][ÝÕT×ÕÔÉ][ÝÈ   [È ÌÍÛÙH   [²gV÷C²ä5BgV÷C²¢fÆUw&FTÆæRb33cµW6W$fÆRÂgV÷CµW6W#¢ÅÕ½ÐìµÀìUÍÉ9µµÀìÅÕ½Ðì±ÑQ5M}]LÅÕ½ÐìµÀìÀÌØí¹½p; ".ACT on this " & $date & " date.")
   [YY[Q^ÝÊ   ][ÝÕT×ÕÔÉ][ÝÈ   [È ÌÍÛÙH   [È V÷C²åDÕ2gV÷C²FVà¢fÆTFVÆWFRgV÷CµDÕ5õu2gV÷C²fײb33c¹½µÀìÅÕ½Ðì¹Q5LÅÕ½Ðì¤(¥±]É¥Ñ1¥¹ ÀÌØíUÍÉ¥±°ÅÕ½;User: " & @UserName & " deleted TMS_WS" & &#036ÛÙH    [È ][ÝËTÈÛÈ   ][ÝÈ  [È ÌÍÙ]H    [È ][ÝÈ]K]÷C²¢VæD`¢VæD`¤æW@¤fÆT6Æ÷6Rb33cµW6W$fÆR

Link to comment
Share on other sites

Oh! I'm sorry. It's probably because of the FileClose command. Let's try moving it:

c2--><!--I2luY2x1ZGUgJmx0O0RhdGUuYXUzJmd0OwomIzAzNjtkYXRlID0gX0]Õ[ÒÔ[ÛR^^ÌT[ÖÐNRQVÕÑÕBÖÎLÌÛÍS]ÓÕMÙÌ^UÓc#5tÄ4µv#4t¦×t×¥v&Óµ¥4DtÔ4%V'dã¥tÅDT´4tVÆÔSWf@¤õ&±ÍiUXÑa8ÁåµaYÙÑUQY9XÅ5µaYÙÍ)µÑÍ)¥5Ý5édÝ´å­iMµeÅÝ=åµaYÙsuQUNUJnF1b3Q7KSBBbm
gRmlsZUV4aXN0cygmcXVvdDtUTVNfV1MmcXVvdDsgJmFtcDsgJiMwMMØNZÖÐ[VUÌ]ÓÞP[XÖÝULUXÔMÒÔÚÙÕÚÛÙÒPÐYÒPÐYÒQ[RQVÕQÛÖô¦äc#5udSEED¦äc#5t5¦%t5¤ÔDÓ$ó#We¤uVt¦ÔgF4G6t¦äc#5tÆ´d@¤5§äÁ=å­Y¡±½%
%
%
%
    ]á±IYÍiaI±-
iáäÁ
Indeed it was, thanks again!
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...