Jump to content

Recommended Posts

copyleft

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

 

Share this post


Link to post
Share on other sites
mikell
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:

 

Share this post


Link to post
Share on other sites
copyleft

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

 

Share this post


Link to post
Share on other sites
mikell
Posted (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 :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

Share this post


Link to post
Share on other sites
copyleft

@mikell Many thanks.

Share this post


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

  • Similar Content

    • KaFu
      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
    • MFrancisca
      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!  
    • 232showtime
      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:
      folders:
      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???
       
       
    • XinYoung
      By XinYoung
      Hello again,
      I'm trying to use the FileMove function to rename a bunch of text files.
      Some of the files have "_1" at the end of their name, for example, "File123_1.txt". I want to remove the "_1" so it would become "File123.txt".
      What I currently have...
              FileMove($sSource & "\*_1.txt", $sDestination & "\*.txt")
      But since I'm using a wildcard, it doesn't appear to be working. I think it's just replacing .txt with .txt. Am I going about this the wrong way? How can I use wildcards and still accomplish this?
      Any help is greatly appreciated ^__^
    • elsemieni
      By elsemieni
      Hey hello.
      I came here with maybe too specific questions about uncommon things, but as people says, I don't lose anything trying to asking here 
      There's long time that I have a little "experimental" idea: Use windows desktop and it icon system like old videogame consoles (where "sprites" are used to draw things on screen, can be manipulated/animated to make interesting things happen). Some of that inspiration came from another experiments from demoscene.
      Researching the possibilities of doing something like that (maybe not so intense) I found that the Windows Desktop uses a GuiListView to show and arrange icons (and of course, AutoIt provides UDF's for that  ). So, I'm used that UDF to create dummy icons (not putting files on Desktop, just modifiying the "GUI layer" of desktop for put non-working icons), setting custom values like coordinates, name and Icon (from a list of loaded icons in the GuiListView).  As you can see in next image works well in Windows XP... even in Windows 95 (that's not the case from Windows Vista to 10, but I already posted another question here about that... anyways, for now I'm working that with a isolated XP machine... sigh).

      Another video doing an animation with that:
      How I make that custom icons? Here:
      $hWnd = ControlGetHandle("Program Manager", "", "[CLASS:SysListView32; INSTANCE:1]") $newItem = _GUICtrlListView_AddItem ( $hWnd, "TEST", 32 ) ; with an icon of index 32 _GUICtrlListView_SetItemPosition ( $hWnd, $newItem, 300, 300 ) ; set some example property. Put in X=300 Y=300 Okay, so the next phase was changing the icons with custom ones. And here starts the issues. As AutoIT help says, icons from GuiListView came from a loaded GUIImageList, which, seeing past images I conclude that it's already preloaded with some sort of most used icons (something like an icon cache?). But If I modify it (or create another GUIImageList and then put into the GuiListView) the icons became corrupted and replaced with blank ones. (can be reverted deleting IconCache.db, just like when windows shows wrong icons in desktop).
      How I change icons? Here
      $hImage = _GUIImageList_Create(48, 48, 5) ; create an image list for 48x48 icons $newIcon = _GUIImageList_AddIcon($imageList, @SystemDir & "\shell32.dll", 110) ; just adding a new icon in the image list _GUICtrlListView_SetImageList($hWnd, $hImage, 0) ; $hwnd is the desktop hwnd Another option as workaround for setting icons was getting the desktop GUIImageList, and modifiyng it directly. I otbtain a GUIImageList handle, but ... without any images inside! (That's strange beacuse, when I set desktop item icons without altering the GUIImageList, it applies correctly). And finally if I try to add new ones, it returns -1 with @error setted.
      How I'm trying to get  desktop GUIImageList? Here.
      $imageList = _GUICtrlListView_GetImageList ( $hWnd, 0 ) MsgBox(0,_GUIImageList_GetImageCount ( $imageList ), $imageList) ; getting image count and GUIImageList handle $newIcon = _GUIImageList_AddIcon($imageList, @SystemDir & "\shell32.dll", 110) ; adding icons without success So, what is the question? There's something wrong I'm doing while trying to set the new icon set on desktop? Or desktop icons work in different way than the rest of the GuiListView's? Or there's something really stupid that I can't saw before that corrupts the icons? 
      Also... if there's not known solution for that, do you have some idea for doing a workaround for that? Or another crazy idea? (Maybe putting real files instead dummy icons could be a solution ... a very slow one). Or even maybe (maybe not, I sure about that xD) do you want to help with this "experiment".
      Thanks in advance, have a good day  
×