wsc77320 Posted March 29, 2018 Share Posted March 29, 2018 This may have been addressed in another post but could not find an answer so I will ask again. I am working on a script that will delete all sub files from multiple sub folders. There may be a better way of doping it but I will post what I have. The issue used file List to array to list all the files in the c:\Users folder. Then Used switch to go delete files in folders that do not match any I want to exclude. What I have found is that either _FileListToArray or Switch does not see the difference in folder names with a space. Meaning A folder named Default has nothing deleted but then a folder called default users also has nothing deleted even though it does not meet a case statement. I believe the space is the issue. I tested that by creating several folders with same first word but different second word and duplicated the mistake. So a folder called "Skippy" has files deleted but "Skippy New" does not because of the space. Is there anyway to adjust for the spaces in the folder names? #Include <File.au3> #Include <Array.au3> Global $CurrentUser $CurrentUser=@UserName $FileList=_FileListToArray("C:\TestUsers", "*", 2) If @Error=1 Then MsgBox (0,"","No Files\Folders Found.") Exit EndIf $Output = _ArrayDisplay($FileList,"$FileList") For $i = 1 To $FileList[0] Switch $FileList[$i] Case "Administrator" MsgBox(0, "Accounts", "Administrator Account Found") Case "All Users" MsgBox(0, "Accounts", "All Users Account Found") Case "XXXXAdmin" MsgBox(0, "Accounts", "XXXXAdmin Account Found") Case "XXXX_Admin" MsgBox(0, "Accounts", "XXXX_Admin Account Found") Case "XXXx_A~1" MsgBox(0, "Accounts", "XXXX_A~1 Account Found") Case "Public" MsgBox(0, "Accounts", "Public Account Found") Case "Default" MsgBox(0, "Accounts", "Default Account Found") Case "LocalService" MsgBox(0, "Accounts", "LocalService Account Found") Case "NetworkService" MsgBox(0, "Accounts", "NetworkService Account Found") Case @UserName MsgBox(0, "Accounts", @UserName & " Account Found") Case Else Run(@ComSpec & " /c " & "del C:\TestUsers\" & $FileList[$i] & "\AppData\*.* /S /Q >>C:\_Installation\Results.txt", @SystemDir) EndSwitch Next Link to comment Share on other sites More sharing options...
wsc77320 Posted March 29, 2018 Author Share Posted March 29, 2018 Actually as I think about it _FileListToArray is not the issue, when I run the script it outputs the list of folders and lists the folders with spaces just find. So this is somewhere in the passing of the array name to the switch statement I believe. But I do not know how to correct this. Link to comment Share on other sites More sharing options...
TheXman Posted March 29, 2018 Share Posted March 29, 2018 Although I haven't tested it, your problem is most likely the run() function. File paths that contain spaces need to be in quotes. So for example, when your script encounters "Default User", the command line that is generated is: c:\windows\system32\cmd.exe /c del C:\TestUsers\Default User\AppData\*.* /S /Q >>C:\_Installation\Results.txt when it should be: c:\windows\system32\cmd.exe /c del "C:\TestUsers\Default User\AppData\*.*" /S /Q >>C:\_Installation\Results.txt So one solution would be to change the line to: Run(@ComSpec & " /c " & "del ""C:\TestUsers\" & $FileList[$i] & "\AppData\*.*"" /S /Q >>C:\_Installation\Results.txt", @SystemDir) CryptoNG UDF: Cryptography API: Next Gen jq UDF: Powerful and Flexible JSON Processor | jqPlayground: An Interactive JSON Processor Xml2Json UDF: Transform XML to JSON | HttpApi UDF: HTTP Server API | Roku Remote: Example Script About Me How To Ask Good Questions On Technical And Scientific Forums (Detailed) | How to Ask Good Technical Questions (Brief) "Any fool can know. The point is to understand." -Albert Einstein "If you think you're a big fish, it's probably because you only swim in small ponds." ~TheXman Link to comment Share on other sites More sharing options...
wsc77320 Posted March 29, 2018 Author Share Posted March 29, 2018 Wow...and it was that simple. I figured it was in the Run() statement and spaces but just could not see it. Thanks that made it work like a charm. 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