Jump to content

Search and delete all but


dufran3
 Share

Recommended Posts

I am trying to do something here...I am kind of new but have some idea of how this language works. I am attempting to search the start menu folder of the current user, and delete all but. This is where I am having trouble. I need ot be able to search a specific directory, and have it return all contents of the directory, including files and sub directories. And delete all but certain ones.

$start = @StartMenuDir

SearchKill($start)

Func SearchKill($searchkill)

If ($searchkill) <> "Accessories or Startup" And FileAttrib == Directory Then

DirRemove($searchkill)

If ($searchkill) <> "Accessories or Startup" and FileAttrib == File Then

FileRemove($searchkill)

Of course I have functions created for DirRemove and FileRemove....but the syntax of the rest of it isn't correct, anyone help me with this please?

Edited by dufran3
Link to comment
Share on other sites

  • Moderators

:P

Why would you want to access someone start menu folder and delete stuff?

Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.

Link to comment
Share on other sites

:P

Why would you want to access someone start menu folder and delete stuff?

I am deploying 30 - 40 new computers for a project at work, have scripts setup to install and customize some things, and this is one of the customization that I need to do for each computer.

Link to comment
Share on other sites

  • Moderators

I am deploying 30 - 40 new computers for a project at work, have scripts setup to install and customize some things, and this is one of the customization that I need to do for each computer.

Show the functions you are using for "FileRemove". I'm aware of FileDelete but not FileRemove.

Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.

Link to comment
Share on other sites

FileRemove is just a custom funtion I created that checks if the file exists before running the FileDelete Function that is built in. That, however, isn't relevant to my question...any one have any advice?

Edited by dufran3
Link to comment
Share on other sites

I haven't tested this, for obvious reasons

#include <Constants.au3>
#Include <Array.au3>

$foo = Run(@ComSpec & " /c dir *.* /s /b", @UserProfileDir&"\Start Menu", @SW_HIDE, $STDOUT_CHILD)
$output = ""
While 1
    $output &= StdoutRead($foo)
    If @error Then ExitLoop
Wend
$aDir = stringsplit(StringStripWS($output,3),@crlf,1)

for $i = $aDir[0] to 1 step -1 ; go through them backwards
    $file = $aDir[$i]
    $attribs = FileGetAttrib ($file)
    if not stringinstr($file,"Accessories" and not stringinstr($file,"Startup") and stringinstr($attribs,"D") Then
        ;DirRemove($file) ; Really? That seems a little dangerous.
    EndIf
    if not stringinstr($file,"Accessories" and not stringinstr($file,"Startup") and not stringinstr($attribs,"D") Then
        ;FileDelete($file) ; I'm glad you're not running this on my box
    EndIf
    
next

[font="Fixedsys"][list][*]All of my AutoIt Example Scripts[*]http://saneasylum.com[/list][/font]

Link to comment
Share on other sites

I haven't tested this, for obvious reasons

#include <Constants.au3>
#Include <Array.au3>

$foo = Run(@ComSpec & " /c dir *.* /s /b", @UserProfileDir&"\Start Menu", @SW_HIDE, $STDOUT_CHILD)
$output = ""
While 1
    $output &= StdoutRead($foo)
    If @error Then ExitLoop
Wend
$aDir = stringsplit(StringStripWS($output,3),@crlf,1)

for $i = $aDir[0] to 1 step -1 ; go through them backwards
    $file = $aDir[$i]
    $attribs = FileGetAttrib ($file)
    if not stringinstr($file,"Accessories" and not stringinstr($file,"Startup") and stringinstr($attribs,"D") Then
        ;DirRemove($file) ; Really? That seems a little dangerous.
    EndIf
    if not stringinstr($file,"Accessories" and not stringinstr($file,"Startup") and not stringinstr($attribs,"D") Then
        ;FileDelete($file) ; I'm glad you're not running this on my box
    EndIf
    
next

Thanks a bunch, a couple of things... you missed the ) after "Accessories", I added that in.

Getting errors for $STDOUT_CHILD, saying that it is an undeclared variable

H:**********\searchdir.au3(4,98) : WARNING: $STDOUT_CHILD: possibly used before declaration.

$foo = Run(@ComSpec & " /c dir *.* /s /b", @UserProfileDir&"\Start Menu", @SW_HIDE, $STDOUT_CHILD)

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^

H:**********\searchdir.au3(4,98) : ERROR: Run() [built-in]called with wrong number of args.

$foo = Run(@ComSpec & " /c dir *.* /s /b", @UserProfileDir&"\Start Menu", @SW_HIDE, $STDOUT_CHILD)

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^

H:**********\searchdir.au3(4,98) : ERROR: $STDOUT_CHILD: undeclared global variable.

$foo = Run(@ComSpec & " /c dir *.* /s /b", @UserProfileDir&"\Start Menu", @SW_HIDE, $STDOUT_CHILD)

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^

H:**********\searchdir.au3 - 2 error(s), 1 warning(s)

I really appreciate your help!!!

ARGG!!! Sorry, I didn't find that variable in the constants.au3 file because i had an older version of AutoIT3, i updated and it added the variable to the file!!!! THANKS!!!

Edited by dufran3
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...