Jump to content
Sign in to follow this  
sbrady

help moving files

Recommended Posts

sbrady

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.

Share this post


Link to post
Share on other sites
Jfish

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 by Jfish

Build your own poker game with AutoIt: pokerlogic.au3 | Learn To Program Using FREE Tools with AutoIt

Share this post


Link to post
Share on other sites
Melba23

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._______My UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Share this post


Link to post
Share on other sites
mikell

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

Share this post


Link to post
Share on other sites
sbrady

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

Share this post


Link to post
Share on other sites
mikell

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

Share this post


Link to post
Share on other sites
ZacUSNYR

I'd think one benefit of using FileListToArray you can track the files and display a more accurate progress bar.

Share this post


Link to post
Share on other sites
sbrady

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

Share this post


Link to post
Share on other sites
mikell

be aware I have dozens of more scripts to write.

shawn

 

Gasp ***

So very glad I could help :)

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
Sign in to follow this  

×