Jump to content

Recommended Posts

Posted (edited)

I am attempting to create a login script that will delete any extra shortcut files inside the @StartMenuCommonDir with the exception of the 1 shortcut I want to be there. (I also want to make sure I don't delete the "Programs" folder but I'm sure I can get around that by only looking at *.lnk files.

Basically I'm trying to figure out how to create a loop to look at the name of each shortcut link inside the @STartMenuCommonDir and if it doesn't match X then delete the shortcut.

I've gotten as far as listing the files into an array using _FileListToArray but I'm iffy on the loop and how to read $var[$i] and delete if not matching X

Edited by kor
Posted

for your loop I would use

For $i=1 to UBound($var)-1

If $var[$i]<>X Then

FileDelete(@STartMenuCommonDir&"\"&$var[$i])

EndIf

Next

something like that and untested

010101000110100001101001011100110010000001101001011100110010000

001101101011110010010000001110011011010010110011100100001

My Android cat and mouse game
https://play.google.com/store/apps/details?id=com.KaosVisions.WhiskersNSqueek

We're gonna need another Timmy!

Posted (edited)

#include <File.au3>
#include <Array.au3>

$var = _FileListToArray(@StartMenuCommonDir)
_ArrayDisplay($var)

For $i = 1 to UBound($test) - 1
    If $var[$i] <> "testing.lnk" Or $var[$i] <> "Programs" Then
        FileDelete(@StartMenuCommonDir & "\" & $var[$i])
    EndIf
Next

It kinda works, as it deletes all the shortcuts, but it's also deleting my testing.lnk shortcut too.

Edited by kor
Posted

your "or" should be an "and" because if it is testing.lnk, then it doesn't match Programs and will still do the delete.

Your UBound($test) should be UBound($var) which is your filelist you want to check.

010101000110100001101001011100110010000001101001011100110010000

001101101011110010010000001110011011010010110011100100001

My Android cat and mouse game
https://play.google.com/store/apps/details?id=com.KaosVisions.WhiskersNSqueek

We're gonna need another Timmy!

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
×
×
  • Create New...