Jump to content

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     


Link to post
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 post
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     


Link to post
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)          


Edited by mikell
Link to post
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
  • Recently Browsing   0 members

    No registered users viewing this page.

  • Similar Content

    • By bluebug
      Hi, guys!
      I'm new with using Autoit.
      Is possible do an automation to an application desktop java using Autoit?
    • By morion84
      Hi, when I call a MsgBox function I can use a "$MB_SERVICE_NOTIFICATION" flag so it will be displayed "on the current active desktop, even if there is no user logged on to the computer.". That works just great. Is there a way to do the same to Autoit GUI Form so it will be visible on desktop even if running from system account and user is not logged?
    • By KaFu
      ICU - Icon Configuration Utility

      Current Version: v6 (2018-Sep-16)
      Restore your desktop when the icons get "rearranged".
      Melba23 and I found we were working on very similar ideas to restore the Desktop icons to their normal place if they became "rearranged" (
      ). Vista seems to like this doing on occasion just for fun - but we all know some apps and games which change the display resolution or move icons around. This annoys "tidy" people who like their desktops arranged "just so" - I am particularly thinking of this desktop when I say that!
      We combined efforts and here is the result of our labors.
      Operation is easy - press "Save" to store a particular configuration and "Restore" to reset the icons to the saved positions in the selected configuration file. "Delete" allows you to remove unwanted configuration files from the list. There is a command line option so that the restoration can be run via HotKeys if required (that is why the script warns that it should be compiled for full functionality). You can decide what to do with any icons that have been added since you last saved the configuration file - the default is to put them in the top-left corner, but you can also banish them way off-screen or, more sensibly, specify a location for them.
      A new feature as of ICU v3.4 is the optional Desktop Contextmenu Integration (DCI) for Win7 (Win7 only because Microsoft implemented an easy way to do this through the registry as of this release).
      Version 3.3 should fix the empty save file bug
      Version 3.4 Win7: Admin rights no longer needed for DCI
      Version 5.0 Win8 compatibility for DCI
      The source and executable can be downloaded from my site: http://www.funk.eu
      Kudos to Ascend4nt, Melba23, Prog@ndy, & Valik for parts of the code.
      Please let me know if you found some piece of code in the source for which I forgot to mention a credit.
      Enjoy, let me know what you think of ICU and with Best Regards
    • By MFrancisca
      Hello everyone,
      I'm trying to make a script that renames a file. I'm using FileMove but I'm really confused.
      The name change is on the EXTENSION, not on the file name itself. I need to change it from ".exe_" to "exe".
      FileMove is returning a 0 value and the file is clearly not renamed. Here is the relevant code.
      For $index = 1 to (UBound($file_array) - 1) $new_file_name = StringTrimRight($file_array[$index], 1) FileMove($dir & "\" & $file_array[$index], $dir & "\" & $new_file_name) Next  some context notes: 
      $file_array is the output of _FileListtoArray, and it has the correct values.  $dir is known, and the script is detecting it without problem I've checked that the script is finding the correct files, and that TrimRight is working. All variables have the correct values. I've checked the file attributes, the are set to "A". Are those the correct attributes? I've tried setting the flag of FileMove to 1, 8 and 9 with the same results This was working fine 2 weeks ago when I did the last run,  and I've made no changes.  (I don't know why the syntax highlighting is messed, quotes are paired correctly) 
      I know that the help file says that FileMove will not succeed if the destination already exist... my question is, does FileMove count extensions? 
      Thank you!  
    • By 232showtime
      hi im stuck with this I want to transfer the correct file in the existing folder
      #include <File.au3> #include <AutoItConstants.au3> #include <Array.au3> $Read = "C:\New folder (3)" $FLFiles1 = _FileListToArrayRec($Read, "*.xlsx", $FLTAR_FILES, $FLTAR_NORECUR, $FLTAR_SORT, $FLTAR_NOPATH) _ArrayDisplay($FLFiles1) For $i = 0 To UBound($FLFiles1) - 1 $STR = StringTrimRight($FLFiles1[$i], 5) ConsoleWrite($STR & @CRLF) $dirS = DirGetSize($Read & "\" & $STR) If $dirS = -1 Then MsgBox(16, $STR, $dirS) Else FileMove($Read, $Read & "\" & $STR & "\" & $STR & ".xlsx") EndIf next I have 3 folders under "C:\New folder (3)" and I have 5 excel files:
      C:\New folder (3)\1
      C:\New folder (3)\3
      C:\New folder (3)\5
      excel files:
      1.xlsx (value of column A are all 1)
      2.xlsx (value of column A are all 2)
      3.xlsx (value of column A are all 3)
      4.xlsx (value of column A are all 4)
      5.xlsx (value of column A are all 5)
       I run the above script and those excel file 1, 3, 5 was transfered in the 1, 3, and 5 folders but the value of transfered file in Column A are  different and file no. 4 and 5 still remains in the folder "C:\New folder (3)".... ???
      whats wrong with the script???
  • Create New...