sbrady Posted November 11, 2013 Posted November 11, 2013 is there a way I can move all files from the desktop to a certain folder, where all files needed to be moved have the same 1st word in their name. for example: EGR123 American Schools EM v1.mxf EGR123 American Schools EMF v1.mxf EGR123 American Schools v1.omf I would need all files whose name starts with EGR123 to be moved. thanks for any help.
Jfish Posted November 11, 2013 Posted November 11, 2013 (edited) Something like this should work (untested): #include<Array.au3> #include <File.au3> $myfiles=_FileListToArray(@DesktopDir) ;_ArrayDisplay($myfiles); to see all your files un-comment to use for $a=1 to UBound($myfiles)-1 FileMove($myfiles[$a],['PATH'&"\PREFIX_FILENAME") next The above will move all files. I did not read your original post carefully enough. You want to make sure the name contains "EGR123" then do this: #include<Array.au3> #include <File.au3> $myfiles=_FileListToArray(@DesktopDir) _ArrayDisplay($myfiles) for $a=1 to UBound($myfiles) if StringInStr($myfiles[$a],"EGR123") <>0 then FileMove($myfiles[$a],['PATH'&"\PREFIX_FILENAME") EndIf next Edited November 11, 2013 by Jfish Build your own poker game with AutoIt: pokerlogic.au3 | Learn To Program Using FREE Tools with AutoIt
Moderators Melba23 Posted November 11, 2013 Moderators Posted November 11, 2013 Jfish,Just use the filter in _FileListToArray to only return those files beginning with "EGR123" in the first place - much more efficient. M23 Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind Open spoiler to see my UDFs: Spoiler ArrayMultiColSort ---- Sort arrays on multiple columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area
mikell Posted November 11, 2013 Posted November 11, 2013 (edited) May I suggest FileMove(@DesktopDir & "\" & $myfiles[$a], .... ) as _FileListToArray() doesn't return the full path But the best way is this one-liner FileMove(@DesktopDir & "\EGR123*", @DesktopDir & "\folder\*") as FileMove allows wildcards much much more efficient Edited November 11, 2013 by mikell
sbrady Posted November 11, 2013 Author Posted November 11, 2013 thanks mike, I plugged in a variable and am getting this error: Array variable has incorrect number of subscripts or subscript dimension range exceeded.: here is my code: #include<Array.au3> #include <File.au3> $myfiles =_FileListToArray(@DesktopDir ) local $news_project_full_name = InputBox(8192, "Paste in Project Name", "EGR123 Schools EM v1") Local $news_name_no_EM_v1 = StringTrimRight($news_project_full_name, 6) ;"EGR123 Schools" Local $news_name_NPR = $news_name_no_EM_v1 & " NPR" local $news_project_code = StringLeft ( $news_project_full_name, 6 ) ;EGR123 for $a=1 to UBound($myfiles) if StringInStr($myfiles[$a],$news_project_code) then FileMove(@DesktopDir & $news_project_code & "*", $path_to_incoming) EndIf next
mikell Posted November 11, 2013 Posted November 11, 2013 (edited) Hum I don't know how you want to manage your folders but you can forget _FileListToArray() and simply do it like this (be very careful with managing the backslashes in paths) $prefix = "EGR123" $source_folder = @DesktopDir & "\" ; the paths are examples $dest_folder = @DesktopDir & "\folder\" FileMove($source_folder & $prefix & "*", $dest_folder & "*") Edited November 11, 2013 by mikell
ZacUSNYR Posted November 11, 2013 Posted November 11, 2013 I'd think one benefit of using FileListToArray you can track the files and display a more accurate progress bar.
sbrady Posted November 11, 2013 Author Posted November 11, 2013 mike that last one worked. Thanks so much. You have no idea what a help you have been. I am an audio editor and we make folders all day long for each project and put the needed audio and video files in the new folder. This script that I'll make an exe will make things 1 click easy. thanks again. be aware I have dozens of more scripts to write. shawn
mikell Posted November 11, 2013 Posted November 11, 2013 be aware I have dozens of more scripts to write.shawn Gasp *** So very glad I could help
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