copyleft Posted May 12, 2018 Posted May 12, 2018 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
mikell Posted May 12, 2018 Posted May 12, 2018 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 ?
copyleft Posted May 12, 2018 Author Posted May 12, 2018 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
mikell Posted May 12, 2018 Posted May 12, 2018 (edited) 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 #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 May 12, 2018 by mikell
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