Jump to content

Spaces in names


Recommended Posts

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

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

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)

 

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