Jump to content

Recommended Posts

Posted (edited)

If I am trying to move 50 files that have a 2 digit number in front with a similar filename and extension, (##file.txt) but I do not want to move all the *.txt from the folder.

The common denominator would be the filenames themselves e.g. ##file.*

Is this possible?

This is what I have so far.

FileMove("C:\client\11file.txt", "Z:\client\",8)
; this would move the 11file.txt to the destination and create it if it did not exist.

MsgBox(4096,"File Transfer Completed", "Files Moved.",15)
; what command would I use to get the Msgbox or some other message to tell me how many files total were moved?
Exit

Thanks in advance.

Edited by schilbiz
Posted (edited)

Try ??file.txt if they are all .txt files, or ??file.* if not. If you want counts from individual files you'll have to do the copy from a loop:

#include <file.au3>

Dim $sSrc = "C:\Client\", $sPatt = "??Test.txt", $sDest = "Z:\Client\" 
$avFiles = _FileListToArray($sSrc, $sPatt, 1) ; 1 = Files only

Dim $Good = 0, $Bad = 0
For $n = 1 To $avFiles[0]
    If FileCopy($sSrc & $avFiles[$n], $sDest, 1 + 8) Then ; 1 = Overwrite, 8 = create path
        $Good += 1
    Else
        $Bad += 1
    EndIf
Next
MsgBox(64, "Results", $avFiles[0] & " files in " & $sSrc & " matched pattern: " & $sPatt & @CRLF & _
        "Successfully copied to " & $sDest & ": " & $Good & @CRLF & _
        "Failed to copy: " & $Bad)

<_<

P.S. Oops, of course you can change the FileCopy to FileMove...

Edited by PsaltyDS
Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law
Posted (edited)

Try ??file.txt if they are all .txt files, or ??file.* if not. If you want counts from individual files you'll have to do the copy from a loop:

#include <file.au3>

Dim $sSrc = "C:\Client\", $sPatt = "??Test.txt", $sDest = "Z:\Client\" 
$avFiles = _FileListToArray($sSrc, $sPatt, 1) ; 1 = Files only

Dim $Good = 0, $Bad = 0
For $n = 1 To $avFiles[0]
    If FileCopy($sSrc & $avFiles[$n], $sDest, 1 + 8) Then ; 1 = Overwrite, 8 = create path
        $Good += 1
    Else
        $Bad += 1
    EndIf
Next
MsgBox(64, "Results", $avFiles[0] & " files in " & $sSrc & " matched pattern: " & $sPatt & @CRLF & _
        "Successfully copied to " & $sDest & ": " & $Good & @CRLF & _
        "Failed to copy: " & $Bad)

<_<

P.S. Oops, of course you can change the FileCopy to FileMove...

I did just that, before you edited your message and it works great, Thank you.

#include <file.au3>

Dim $sSrc = "C:\Client\", $sPatt = "??file.txt", $sDest = "Z:\Client\" 
$avFiles = _FileListToArray($sSrc, $sPatt, 1); 1 = Files only

Dim $Good = 0, $Bad = 0
For $n = 1 To $avFiles[0]
    If Filemove($sSrc & $avFiles[$n], $sDest, 1 + 8) Then; 1 = Overwrite, 8 = create path
        $Good += 1
    Else
        $Bad += 1
    EndIf
Next
MsgBox(64, "Results", $avFiles[0] & " files in " & $sSrc & " matched pattern: " & $sPatt & @CRLF & _
        "Successfully moved to " & $sDest & ": " & $Good & @CRLF & _
        "Failed to Move: " & $Bad)
Edited by schilbiz

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.
×
×
  • Create New...