Jump to content

Win7 difficult to delete files, this might help ...


Diana (Cda)
 Share

Recommended Posts

Although I'm sure there are many better ways to do this, in an office computer where we can't install things like the freeware app Unlocker, deleting a file via DOS in Windows 7 is an option when nothing else worked for me.

I've found again and again that Win7 holds onto files way more than WinXP does and WinXP is already very bad. At home, though, I just run the file/folder through Unlocker and 99 out of 100 times, the file/folder is released and you can then delete (or rename, etc.).

But I'm not sure Unlocker even works in Win7 and I can't install it anyway.

Hunting around yesterday I found and tested doing this vis a DOS command box and it worked every time. However, I got tired of all the navigating in DOS I had to do. So I went hunting around for how to automate with AI. And here's what I came up with:

;$dir = FileOpenDialog("Select Folder to open Command Prompt in...", @ScriptDir, "All (*)")
;Run("cmd.exe", $dir)


#Region --- CodeWizard generated code Start ---
;InputBox features: Title=Yes, Prompt=Yes, Default Text=No, Width=500, Height=125
If Not IsDeclared("sInputBoxAnswer") Then Local $sInputBoxAnswer
$sInputBoxAnswer = InputBox("FOLDER ...","Path ...",""," ","500","125","-1","-1")
Select
    Case @Error = 0 ;OK - The string returned is valid
        Run("cmd.exe", $sInputBoxAnswer)
    Case @Error = 1 ;The Cancel button was pushed
        Exit     ; finished
    Case @Error = 3 ;The InputBox failed to open
        MsgBox(262160,"","The input box failed to open.     " & @CRLF & "Please try again.")
EndSelect
#EndRegion --- CodeWizard generated code End ---

The commented out part is where I got the base DOS code to use.

This is just to bring the cmd box up with the folder you are in already navigated to. I have an AI script that is in sendto folder that allows me to get a file's/folder's complete path via context into sendto, then I just dump the path into the inputbox.

But once that's done, I still have to type:

DEL filename.ext

Perhaps someone knows how to delete the file directly in AI, I couldn't figure out how to get the full path to the actual file itself and then get the CMD box to be completely automated. But I think I personally would like to keep that part manual.

Anyway, my very humble second contribution ever of some AutoIt code <g>.

Cheers. :mellow:

Edited by Diana (Cda)
Link to comment
Share on other sites

But I'm not sure Unlocker even works in Win7 and I can't install it anyway.

It works on both x32 & x64.

UDF List:

 
_AdapterConnections()_AlwaysRun()_AppMon()_AppMonEx()_ArrayFilter/_ArrayReduce_BinaryBin()_CheckMsgBox()_CmdLineRaw()_ContextMenu()_ConvertLHWebColor()/_ConvertSHWebColor()_DesktopDimensions()_DisplayPassword()_DotNet_Load()/_DotNet_Unload()_Fibonacci()_FileCompare()_FileCompareContents()_FileNameByHandle()_FilePrefix/SRE()_FindInFile()_GetBackgroundColor()/_SetBackgroundColor()_GetConrolID()_GetCtrlClass()_GetDirectoryFormat()_GetDriveMediaType()_GetFilename()/_GetFilenameExt()_GetHardwareID()_GetIP()_GetIP_Country()_GetOSLanguage()_GetSavedSource()_GetStringSize()_GetSystemPaths()_GetURLImage()_GIFImage()_GoogleWeather()_GUICtrlCreateGroup()_GUICtrlListBox_CreateArray()_GUICtrlListView_CreateArray()_GUICtrlListView_SaveCSV()_GUICtrlListView_SaveHTML()_GUICtrlListView_SaveTxt()_GUICtrlListView_SaveXML()_GUICtrlMenu_Recent()_GUICtrlMenu_SetItemImage()_GUICtrlTreeView_CreateArray()_GUIDisable()_GUIImageList_SetIconFromHandle()_GUIRegisterMsg()_GUISetIcon()_Icon_Clear()/_Icon_Set()_IdleTime()_InetGet()_InetGetGUI()_InetGetProgress()_IPDetails()_IsFileOlder()_IsGUID()_IsHex()_IsPalindrome()_IsRegKey()_IsStringRegExp()_IsSystemDrive()_IsUPX()_IsValidType()_IsWebColor()_Language()_Log()_MicrosoftInternetConnectivity()_MSDNDataType()_PathFull/GetRelative/Split()_PathSplitEx()_PrintFromArray()_ProgressSetMarquee()_ReDim()_RockPaperScissors()/_RockPaperScissorsLizardSpock()_ScrollingCredits_SelfDelete()_SelfRename()_SelfUpdate()_SendTo()_ShellAll()_ShellFile()_ShellFolder()_SingletonHWID()_SingletonPID()_Startup()_StringCompact()_StringIsValid()_StringRegExpMetaCharacters()_StringReplaceWholeWord()_StringStripChars()_Temperature()_TrialPeriod()_UKToUSDate()/_USToUKDate()_WinAPI_Create_CTL_CODE()_WinAPI_CreateGUID()_WMIDateStringToDate()/_DateToWMIDateString()Au3 script parsingAutoIt SearchAutoIt3 PortableAutoIt3WrapperToPragmaAutoItWinGetTitle()/AutoItWinSetTitle()CodingDirToHTML5FileInstallrFileReadLastChars()GeoIP databaseGUI - Only Close ButtonGUI ExamplesGUICtrlDeleteImage()GUICtrlGetBkColor()GUICtrlGetStyle()GUIEventsGUIGetBkColor()Int_Parse() & Int_TryParse()IsISBN()LockFile()Mapping CtrlIDsOOP in AutoItParseHeadersToSciTE()PasswordValidPasteBinPosts Per DayPreExpandProtect GlobalsQueue()Resource UpdateResourcesExSciTE JumpSettings INISHELLHOOKShunting-YardSignature CreatorStack()Stopwatch()StringAddLF()/StringStripLF()StringEOLToCRLF()VSCROLLWM_COPYDATAMore Examples...

Updated: 22/04/2018

Link to comment
Share on other sites

Hello Diana,

From my very limited experience with AutoIt, I would change the code as follows:

;$dir = FileOpenDialog("Select Folder to open Command Prompt in...", @ScriptDir, "All (*)")
;Run("cmd.exe", $dir)

#Region --- CodeWizard generated code Start ---
;InputBox features: Title=Yes, Prompt=Yes, Default Text=No, Width=500, Height=125
If Not IsDeclared("sInputBoxAnswer") Then Local $sInputBoxAnswer
$sInputBoxAnswer = FileOpenDialog("Please select file to delete...","","All (*.*)")
Select
    Case @Error = 0 ;OK - The string returned is valid
        Run("cmd.exe")
WinWait("","",1)
Send("del "&$sInputBoxAnswer)
    Case @Error = 1 ;The Cancel button was pushed
        Exit    ; finished
    Case @Error = 3 ;The InputBox failed to open
        MsgBox(262160,"","The input box failed to open.     " & @CRLF & "Please try again.")
EndSelect
#EndRegion --- CodeWizard generated code End ---

Just press enter to delete the file...

Edited by Tonnie
Link to comment
Share on other sites

  • 4 weeks later...

Hello Diana,

From my very limited experience with AutoIt, I would change the code as follows:

;$dir = FileOpenDialog(&quot;Select Folder to open Command Prompt in...&quot;, @ScriptDir, &quot;All (*)&quot;)
;Run(&quot;cmd.exe&quot;, $dir)

#Region --- CodeWizard generated code Start ---
;InputBox features: Title=Yes, Prompt=Yes, Default Text=No, Width=500, Height=125
If Not IsDeclared(&quot;sInputBoxAnswer&quot;) Then Local $sInputBoxAnswer
$sInputBoxAnswer = FileOpenDialog(&quot;Please select file to delete...&quot;,&quot;&quot;,&quot;All (*.*)&quot;)
Select
    Case @Error = 0 ;OK - The string returned is valid
        Run(&quot;cmd.exe&quot;)
WinWait(&quot;&quot;,&quot;&quot;,1)
Send(&quot;del &quot;&amp;$sInputBoxAnswer)
    Case @Error = 1 ;The Cancel button was pushed
        Exit    ; finished
    Case @Error = 3 ;The InputBox failed to open
        MsgBox(262160,&quot;&quot;,&quot;The input box failed to open.  &quot; &amp; @CRLF &amp; &quot;Please try again.&quot;)
EndSelect
#EndRegion --- CodeWizard generated code End ---

Just press enter to delete the file...

That's great for many uses, good to provide it to others, thanks.

Win7 seems to have trouble with run and with the added complication of the UNC paths I have to deal with at work, this just never worked. I tried, myself, before coming up with my initial script above. M$ seems to go backwards at an equal pace as it goes forward. Win7 doesn't let go of files even after a reboot and since we can't install anything like the great freeware app I use at home called "Unlocker" (though XP is nowhere near as bad as Win7 for not letting go!!) so DOS way has been only successful way of deleting locked files that we have to delete. It's amazing how folders fill up if you can't delete items!

Thanks and cheers.

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