Jump to content

Cleanup User Desktop


Recommended Posts

I am trying to create a script to clean up users' desktops by moving all desktop folders and files (except the two hidden "desktop.ini" files and a MyDesktop.lnk shortcut) to a different folder. The script below will move files but not folders. The other issue with the script is that it doesn't seem to execute from a location other than the user's desktop. I would appreciate any suggestions.

#include <File.au3>
MsgBox(64, "Desktop", "Cleaning up Desktop. This box will close in 4 seconds.", 4)
$Files = _FileListToArray(@DesktopDir,"*",1)                                                               
For $Index = 1 To $Files[0]                             
    If StringRight($Files[$Index],4) <> ".ini, MyDesktop.lnk" Then     
        FileMove($Files[$Index],'F:\HOME\Desktop')     
    EndIf
Next

 

Link to comment
Share on other sites

28 minutes ago, copyleft said:

The script below will move files but not folders

because you use the $FLTA_FILES (1) option in _FileListToArray
Have a look at DirMove too...

 

29 minutes ago, copyleft said:

it doesn't seem to execute from a location other than the user's desktop.

because in _FileListToArray you didn't put the last option $bReturnPath to "true" so you can get full paths

 

33 minutes ago, copyleft said:

If StringRight($Files[$Index],4) <> ".ini, MyDesktop.lnk" Then

Seriously, this works:blink:

 

Link to comment
Share on other sites

still lost.

I'm not getting the " $FLTA_FILES " placement and is the "DirMove" command in addition to FileMove?

#include <File.au3>

MsgBox(64, "Desktop", "Cleaning up Desktop. This box will close in 4 seconds.", 4)
$Files = _FileListToArray(@DesktopDir,"*", TRUE, 0)     
                                                       
For $Index = 1 To $Files[0]                             
    If StringRight($Files[$Index],4) <> "MyDesktop.lnk" & ".ini" Then     
        FileMove($Files[$Index],'F:\1HOME\Desktop')          
        DirMove($Files[$Index],'F:\1HOME\Desktop')
    EndIf
Next

 

Link to comment
Share on other sites

Hmm. You might read very carefully the concerned pages in the helpfile, particularly the sample scripts, the func parameters, and so on

Untested - I want to keep my desktop :idiot:

#include <File.au3>

; get BOTH files and folders, without full path
$stuff = _FileListToArray(@DesktopDir,"*", $FLTA_FILESFOLDERS, False)     
                                                       
; destination folder
$dest = "F:\1HOME\Desktop"
If not FileExists($dest) Then DirCreate($dest)

; then go
For $i = 1 To $stuff[0]    
   If StringInStr(FileGetAttrib(@DesktopDir & "\" & $stuff[$i]), "D") Then   ; it's a folder 
        DirMove(@DesktopDir & "\" & $stuff[$i], $dest & "\" & $stuff[$i], $FC_NOOVERWRITE)
   Else    ; it's a file
         If StringRight($stuff[$i], 4) <> ".ini" AND $stuff[$i] <> "MyDesktop.lnk" Then     
              FileMove(@DesktopDir & "\" & $stuff[$i], $dest & "\" & $stuff[$i], $FC_NOOVERWRITE)          
         EndIf
   EndIf
Next

 

Edited by mikell
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

×
×
  • Create New...