Jump to content

Help with filemove


Ravel
 Share

Recommended Posts

I trying to set up a simple filemove script that will allow me to move all files of a certain extention to from multiple destinations, and consolidate them in one destination i.e. a folder. example

e:\(multiple files and folders) move the extention .txt(out of those folders in the E: drive) to a new folder named Text files. (either still on the E: drive or deposited elsewhere F: H: etc.)
I have searched the forums, and most scripts that I have found are way to advanced for me. I have no problem moving folders in the top directory, but I want it to search the subdirectories too; and move them accordingly. Any help would be appreciated. Thanks.

Edited by Ravel
Link to comment
Share on other sites

There is a RecursiveFileSearch.au3 by WeaponX, I don't think it's included with the standard install or not yet, use that function to do the recursive search of all directories.

Kerros===============================================================How to learn scripting: Figure out enough to be dangerous, then ask for assistance.

Link to comment
Share on other sites

Ugly but easy:

#include <Process.au3>
$SOURCE = FileSelectFolder("SOURCE","")
If @error Then Exit
$EXT = InputBox("EXTENSION","TYPE HERE THE FILES EXTENSION","TXT")
$DEST = FileSelectFolder("DESTINATION","",1)
If @error Then Exit
_RunDOS('xcopy "' & $SOURCE & '\*.' & $EXT & '" "' & $DEST & '" /E /-Y')
_RunDOS('del "' & $SOURCE & '\*.' & $EXT & ' /F /S /Q"')

When the words fail... music speaks.

Link to comment
Share on other sites

Ugly but easy:

#include <Process.au3>
$SOURCE = FileSelectFolder("SOURCE","")
If @error Then Exit
$EXT = InputBox("EXTENSION","TYPE HERE THE FILES EXTENSION","TXT")
$DEST = FileSelectFolder("DESTINATION","",1)
If @error Then Exit
_RunDOS('xcopy "' & $SOURCE & '\*.' & $EXT & '" "' & $DEST & '" /E /-Y')
_RunDOS('del "' & $SOURCE & '\*.' & $EXT & ' /F /S /Q"')
K let me give that a try
Link to comment
Share on other sites

Ugly but easy:

#include <Process.au3>
$SOURCE = FileSelectFolder("SOURCE","")
If @error Then Exit
$EXT = InputBox("EXTENSION","TYPE HERE THE FILES EXTENSION","TXT")
$DEST = FileSelectFolder("DESTINATION","",1)
If @error Then Exit
_RunDOS('xcopy "' & $SOURCE & '\*.' & $EXT & '" "' & $DEST & '" /E /-Y')
_RunDOS('del "' & $SOURCE & '\*.' & $EXT & ' /F /S /Q"')
Hmm maybe I am missing something, but when I chose my source and destination entered the extension, but nothing happened. No files were moved. I dont think it ran the dos portion of the script.
Link to comment
Share on other sites

Hmm maybe I am missing something, but when I chose my source and destination entered the extension, but nothing happened. No files were moved. I dont think it ran the dos portion of the script.

Yes, it`s MS-DOS, first time copy the files and then delete the source.

When the words fail... music speaks.

Link to comment
Share on other sites

Recursive File search

There are several recursive functions within that topic, choose the one that works well for you.

I checked out those posts. The issue is though I am not familiar enough with the autoit code to even understand how to implement those examples with what I want to do. For example:

#cs ----------------------------------------------------------------------------
     AutoIt Version: 3.2.10.0
     Author: WeaponX
     Updated: 2/21/08
     Script Function: Recursive file search
     
     2/21/08 - Added pattern for folder matching, flag for return type
     1/24/08 - Recursion is now optional

Parameters:

RFSstartdir: Path to starting folder

RFSFilepattern: RegEx pattern to match
     "\.(mp3)" - Find all mp3 files - case sensitive (by default)
     "(?i)\.(mp3)" - Find all mp3 files - case insensitive
     "(?-i)\.(mp3|txt)" - Find all mp3 and txt files - case sensitive

RFSFolderpattern:
     "(Music|Movies)" - Only match folders named Music or Movies - case sensitive (by default)
     "(?i)(Music|Movies)" - Only match folders named Music or Movies - case insensitive
     "(?!(Music|Movies)\b)\b.+" - Match folders NOT named Music or Movies - case sensitive (by default)

RFSFlag: Specifies what is returned in the array
     0 - Files and folders
     1 - Files only
     2 - Folders only

RFSrecurse: TRUE = Recursive, FALSE = Non-recursive

RFSdepth: Internal use only

#ce ----------------------------------------------------------------------------
Func RecursiveFileSearch($RFSstartDir, $RFSFilepattern = ".", $RFSFolderpattern = ".", $RFSFlag = 0, $RFSrecurse = true, $RFSdepth = 0)
     
 ;Ensure starting folder has a trailing slash
     If StringRight($RFSstartDir, 1) <> "\" Then $RFSstartDir &= "\"

     If $RFSdepth = 0 Then
     ;Get count of all files in subfolders for initial array definition
         $RFSfilecount = DirGetSize($RFSstartDir, 1)
         
     ;File count + folder count (will be resized when the function returns)
         Global $RFSarray[$RFSfilecount[1] + $RFSfilecount[2] + 1]
     EndIf
     
     $RFSsearch = FileFindFirstFile($RFSstartDir & "*.*")
     If @error Then Return

 ;Search through all files and folders in directory
     While 1
         $RFSnext = FileFindNextFile($RFSsearch)
         If @error Then ExitLoop
         
     ;If folder and recurse flag is set and regex matches
         If StringInStr(FileGetAttrib($RFSstartDir & $RFSnext), "D") Then
             
             If $RFSrecurse AND StringRegExp($RFSnext, $RFSFolderpattern, 0) Then
                 RecursiveFileSearch($RFSstartDir & $RFSnext, $RFSFilepattern, $RFSFolderpattern, $RFSFlag, $RFSrecurse, $RFSdepth + 1)
                 If $RFSFlag <> 1 Then
                 ;Append folder name to array
                     $RFSarray[$RFSarray[0] + 1] = $RFSstartDir & $RFSnext
                     $RFSarray[0] += 1
                 EndIf
             EndIf
         ElseIf StringRegExp($RFSnext, $RFSFilepattern, 0) AND $RFSFlag <> 2 Then
         ;Append file name to array
             $RFSarray[$RFSarray[0] + 1] = $RFSstartDir & $RFSnext
             $RFSarray[0] += 1
         EndIf
     WEnd
     FileClose($RFSsearch)

     If $RFSdepth = 0 Then
         Redim $RFSarray[$RFSarray[0] + 1]
         Return $RFSarray
     EndIf
EndFunc;==>RecursiveFileSearch

I took this one which was labeled #1 for speed reasons, and tried to use it, but Um to say the least I'm lost. I dont understand what I am looking at. Its like a foreign language to me.

Edited by Ravel
Link to comment
Share on other sites

Using that RecursiveFileSearch you would search for AutoIt script files by doing something like this...

#include <array.au3>
$Path = @ScriptDir
$Array = RecursiveFileSearch($path, "\.(au3)", true)
_ArrayDisplay($Array)

Just place this code in the same file as the RecursiveFileSearch function and it should give you an array of all the script files in that directory.

Kerros===============================================================How to learn scripting: Figure out enough to be dangerous, then ask for assistance.

Link to comment
Share on other sites

Using that RecursiveFileSearch you would search for AutoIt script files by doing something like this...

#include <array.au3>
$Path = @ScriptDir
$Array = RecursiveFileSearch($path, "\.(au3)", true)
_ArrayDisplay($Array)

Just place this code in the same file as the RecursiveFileSearch function and it should give you an array of all the script files in that directory.

Thanks I will test that out a little later
Link to comment
Share on other sites

Using that RecursiveFileSearch you would search for AutoIt script files by doing something like this...

#include <array.au3>
$Path = @ScriptDir
$Array = RecursiveFileSearch($path, "\.(au3)", true)
_ArrayDisplay($Array)

Just place this code in the same file as the RecursiveFileSearch function and it should give you an array of all the script files in that directory.

You are referring to this set up right?

#include <array.au3>
$Path = @ScriptDir
$Array = RecursiveFileSearch($path, "\.(au3)", true)
_ArrayDisplay($Array)






#cs ----------------------------------------------------------------------------
     AutoIt Version: 3.2.10.0
     Author: WeaponX
     Updated: 2/21/08
     Script Function: Recursive file search
     
     2/21/08 - Added pattern for folder matching, flag for return type
     1/24/08 - Recursion is now optional

Parameters:

RFSstartdir: Path to starting folder

RFSFilepattern: RegEx pattern to match
     "\.(mp3)" - Find all mp3 files - case sensitive (by default)
     "(?i)\.(mp3)" - Find all mp3 files - case insensitive
     "(?-i)\.(mp3|txt)" - Find all mp3 and txt files - case sensitive

RFSFolderpattern:
     "(Music|Movies)" - Only match folders named Music or Movies - case sensitive (by default)
     "(?i)(Music|Movies)" - Only match folders named Music or Movies - case insensitive
     "(?!(Music|Movies)\b)\b.+" - Match folders NOT named Music or Movies - case sensitive (by default)

RFSFlag: Specifies what is returned in the array
     0 - Files and folders
     1 - Files only
     2 - Folders only

RFSrecurse: TRUE = Recursive, FALSE = Non-recursive

RFSdepth: Internal use only

#ce ----------------------------------------------------------------------------
Func RecursiveFileSearch($RFSstartDir, $RFSFilepattern = ".", $RFSFolderpattern = ".", $RFSFlag = 0, $RFSrecurse = true, $RFSdepth = 0)
     
;Ensure starting folder has a trailing slash
     If StringRight($RFSstartDir, 1) <> "\" Then $RFSstartDir &= "\"

     If $RFSdepth = 0 Then
    ;Get count of all files in subfolders for initial array definition
         $RFSfilecount = DirGetSize($RFSstartDir, 1)
         
    ;File count + folder count (will be resized when the function returns)
         Global $RFSarray[$RFSfilecount[1] + $RFSfilecount[2] + 1]
     EndIf
     
     $RFSsearch = FileFindFirstFile($RFSstartDir & "*.*")
     If @error Then Return

;Search through all files and folders in directory
     While 1
         $RFSnext = FileFindNextFile($RFSsearch)
         If @error Then ExitLoop
         
    ;If folder and recurse flag is set and regex matches
         If StringInStr(FileGetAttrib($RFSstartDir & $RFSnext), "D") Then
             
             If $RFSrecurse AND StringRegExp($RFSnext, $RFSFolderpattern, 0) Then
                 RecursiveFileSearch($RFSstartDir & $RFSnext, $RFSFilepattern, $RFSFolderpattern, $RFSFlag, $RFSrecurse, $RFSdepth + 1)
                 If $RFSFlag <> 1 Then
                ;Append folder name to array
                     $RFSarray[$RFSarray[0] + 1] = $RFSstartDir & $RFSnext
                     $RFSarray[0] += 1
                 EndIf
             EndIf
         ElseIf StringRegExp($RFSnext, $RFSFilepattern, 0) AND $RFSFlag <> 2 Then
        ;Append file name to array
             $RFSarray[$RFSarray[0] + 1] = $RFSstartDir & $RFSnext
             $RFSarray[0] += 1
         EndIf
     WEnd
     FileClose($RFSsearch)

     If $RFSdepth = 0 Then
         Redim $RFSarray[$RFSarray[0] + 1]
         Return $RFSarray
     EndIf
EndFunc;==>RecursiveFileSearch
Link to comment
Share on other sites

Yeah, that exact script returned all the .au3 files in my script directory.

yea ok I just tried that script. However, it doesn't do what I am looking for. It only returns the scripts that are in the same directory that I am in. I want it to return the all the files that are located on the d: drive regardless of what directories that they are in.

Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...