Jump to content

Deleting folders


Recommended Posts

Hi all,

I have a very small problem. I am trying to write a script which would delete old symantec virus updates folders in the path C:\Program Files\Common Files\Symantec Shared\VirusDefs.Already existing old definition files will have some dll files. By this reason if I use dircopy it is not deleting the files.For my badluck the first folder itself is having some dll files and it is not deleting any of the old folders.Now my requirement is if it is not able to delete one folder it should move to another folder and delete that.Can anyone help me out please.......

Thanks

Link to comment
Share on other sites

Problem with removing that folders i think related with suspicios operation in this case your operation is suspicious.That is reason for unsuccess.

BTW can you delete old definition folders manually from that folder? Is it done with success?

[size="5"] [/size]
Link to comment
Share on other sites

chaitu my question in my last post only for know do you have required high privilegies to delete this folder.

Only reason for ask from you about:

BTW can you delete old definition folders manually from that folder? Is it done with success?

If you can manually delete it this means yes you can remove that folder(s) with script too.

If manual deletion too still unsuccessfull this means this folders protected by AV or access denied and this folder will be deleted by Symantec AV Program.

Try this way if you have required rights for this operation you can delete .

If not you need execute this script in Safe mode.

#RequireAdmin
;C:\Program Files\Common Files\Symantec Shared\VirusDefs
$folder="data"  ;<===specify name of folder which will be deleted.
$path="%programfiles%\Common Files\Symantec Shared\VirusDefs\"
RunWait("cmd.exe /c " & "rmdir /Q /S " & """" & $path & $folder & """",@ScriptDir,@SW_HIDE)
[size="5"] [/size]
Link to comment
Share on other sites

First of all please excuse me for my hard reply to you. I tried with the script you gave me. Even that is also not working. I ll tell u my requirement exactly. I have 4--5 folders in the path C:\Program Files\Common Files\Symantec Shared\VirusDefs. when I use dirremove to delete old symantec virus definitions, there are some dll files in one of the folders and they are used by symantec now. so dirremove is not able to delete that particular folder.And the folder which has the dll files(which are currently used by symantec) is the first folder and so all the other folders are not getting deleted.Now my concern is if first folder is not deleted, then it should leave that folder and move to next folder and try deleting that.Can this be possible? One more thing to add, all the folder names will start with year then date and month(20102204.022 like this).So if I use 2* something like this, that also will not work. Please help me out.

Thanks

Link to comment
Share on other sites

Here is something to learn from. It will DirRemove() each folder in the path set in the UDF and allows for folder name exclusion in the Switch statement.

#RequireAdmin

If _DirRemove_SymantecVirusDefs() Then
    ; notify of success
    MsgBox(0x40000, @ScriptName, 'VirusDefs completed successfully')
Else
    ; returns error 1. path not found 2. invalid handle to find files/folders.
    MsgBox(0x40000, @ScriptName, '@error = ' & @error)
EndIf

Func _DirRemove_SymantecVirusDefs()
    Local $path_virusdefs, $path_virusdefs, $handle_find, $file_found
    ; path to location of VirusDefs
    $path_virusdefs = @CommonFilesDir & '\Symantec Shared\VirusDefs'
    ; return if path is invalid
    If Not FileExists($path_virusdefs) Then
        Return SetError(1, 0, '')
    EndIf
    $handle_find = FileFindFirstFile($path_virusdefs & '\*')
    ; return if handle is invalid
    If $handle_find = -1 Then
        Return SetError(2, 0, '')
    EndIf
    While 1
        $file_found = FileFindNextFile($handle_find)
        If @error Then ExitLoop
        ; add folder name exclusions here if needed
        Switch $file_found
            Case 'folder1', 'folder2' ; example folder names
                ContinueLoop
        EndSwitch
        ; build a fullpath to the folder for removal
        $file_found = $path_virusdefs & '\' & $file_found
        ; check if $file_found is a folder
        If StringInStr(FileGetAttrib($file_found), 'D') Then
            ; remove next line and uncomment DirRemove() line when satisfied testing
            MsgBox(0x40000, 'DirRemove Test', '$file_found = ' & $file_found)
            ;DirRemove($file_found, 1)
        EndIf
    WEnd
    FileClose($handle_find)
    Return True
EndFunc

The DirRemove() line is commented for safe testing to be carried out first. Remove Msgbox() line and uncomment DirRemove() line when happy. :idea:

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...