Diana (Cda) Posted August 26, 2011 Share Posted August 26, 2011 (edited) 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. Edited August 26, 2011 by Diana (Cda) Link to comment Share on other sites More sharing options...
guinness Posted August 26, 2011 Share Posted August 26, 2011 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 parsing • AutoIt Search • AutoIt3 Portable • AutoIt3WrapperToPragma • AutoItWinGetTitle()/AutoItWinSetTitle() • Coding • DirToHTML5 • FileInstallr • FileReadLastChars() • GeoIP database • GUI - Only Close Button • GUI Examples • GUICtrlDeleteImage() • GUICtrlGetBkColor() • GUICtrlGetStyle() • GUIEvents • GUIGetBkColor() • Int_Parse() & Int_TryParse() • IsISBN() • LockFile() • Mapping CtrlIDs • OOP in AutoIt • ParseHeadersToSciTE() • PasswordValid • PasteBin • Posts Per Day • PreExpand • Protect Globals • Queue() • Resource Update • ResourcesEx • SciTE Jump • Settings INI • SHELLHOOK • Shunting-Yard • Signature Creator • Stack() • Stopwatch() • StringAddLF()/StringStripLF() • StringEOLToCRLF() • VSCROLL • WM_COPYDATA • More Examples... Updated: 22/04/2018 Link to comment Share on other sites More sharing options...
Tonnie Posted August 31, 2011 Share Posted August 31, 2011 (edited) 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 August 31, 2011 by Tonnie Link to comment Share on other sites More sharing options...
Diana (Cda) Posted September 25, 2011 Author Share Posted September 25, 2011 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...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 More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now