Rav1 Posted June 22, 2014 Posted June 22, 2014 (edited) Hey gang - I'm very noobish with Autoit and I need some help, please. I trying to write a script that will delete all the folders in c:users that have folder names that contain numbers. So user foldes with numbers (IE c:usersSamGue123) will be deleted but users folders without numbers (ie c:usersAdministrator) will be spared. This script is what I have so far but it's not working as expected....help. #include <File.au3> #include <Array.au3> #include <RecFileListToArray.au3> ; External UDF $sString = '123456789' $FileList = _RecFileListToArray("C:\test", "*", 2, 1, 0, 2, "", "") If @error = 1 Then MsgBox(0, "", "No FilesFolders Found.") Exit EndIf _ArrayDisplay($FileList, "Folders", Default, 8) Do $fLoop = True For $i = 1 To $FileList[0] If (StringInStr($FileList[$i],stringmid($sString,$i,1)))Then If DirRemove($FileList[$i],1) Then ConsoleWrite("Dir removed: " & $FileList[$i] & @CRLF) Else ConsoleWrite("Could not remove dir: " & $FileList[$i] & @CRLF) $fLoop = False EndIf Else EndIf Next Until $fLoop = False MsgBox(0, "Results", "Done") Edited June 22, 2014 by Rav1
orbs Posted June 22, 2014 Posted June 22, 2014 you are using $i to index the folders list, and also to index the character in the numeric string. you need two indices in nested loops for this task. also, for better readability, i'd put the checking for digits into a separate function or a RegExp. Signature - my forum contributions: Spoiler UDF: LFN - support for long file names (over 260 characters) InputImpose - impose valid characters in an input control TimeConvert - convert UTC to/from local time and/or reformat the string representation AMF - accept multiple files from Windows Explorer context menu DateDuration - literal description of the difference between given dates WinPose - simultaneous fluent move and resize Apps: Touch - set the "modified" timestamp of a file to current time Show For Files - tray menu to show/hide files extensions, hidden & system files, and selection checkboxes SPDiff - Single-Pane Text Diff Magic Math - a math puzzle Demos: Title Bar Menu - click the window title to pop-up a menu
Solution Exit Posted June 22, 2014 Solution Posted June 22, 2014 (edited) #include <File.au3> #include <Array.au3> ;~ build test data DirCreate("C:\test\MyUser12345") DirCreate("C:\test\MyUser67890") DirCreate("C:\test\MyUserABC") DirCreate("C:\test\MyUserXYZ") ;~ working code $aFiles = _FileListToArray("C:\test","*",0,1) If @error Then Exit MsgBox(0, "", "No FilesFolders Found.") _ArrayDisplay($aFiles, "Folders", Default, 8) For $i = 1 To $aFiles[0] StringSplit($aFiles[$i], "0123456789") If @error Then ContinueLoop ConsoleWrite("Dir " & $aFiles[$i] & (DirRemove($aFiles[$i], 1) ? "" : "NOT") & " removed. " & @CRLF) Next MsgBox(0, "Results", "Done") ;~ remove testdata DirRemove("C:\test", 1) Edited June 22, 2014 by Exit App: Au3toCmd UDF: _SingleScript()
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