Jump to content

copy only BIGGER files


myspacee
 Share

Recommended Posts

Hello to all,

i've a problem.

2 directory contain same files.

But destination directory has broken files that i must overwrite.

is possible to script this task ?

maybe with parameters :

allignbigger \\192.168\1.10\mypdf\*.pdf \\192.168.1.20\mypdf\*.pdf

thank you for any help,

m.

Link to comment
Share on other sites

i think different approach :

list files in source directory

if not exist in destination -> copy

else exist in dest. directory read kb size

if > copy

if < next

anyone can help ?

m.

Help with what? You've got a plan that can work:

list files in source directory ===> _FileListToArray() or FileFindFirstFile()/FileFindNextFile()

if not exist in destination -> copy ===> If FileExists() Then

else exist in dest. directory read kb size ===> Else, FileGetSize()

if > copy ===> FileCopy()

if < next ===> For/Next loop with array, or While/WEnd, or Do/Until

Give it a shot, and if you get stuck post what you've got and you'll get more help with it.

;)

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

Almost done,

thank you PsaltyDS to tell script it by myself,

post code after clean code.

A question, this script is thinked to be used in DOS console,

to avoid operator do manual allignments of a large number of directoryes.

Is possible to have any output in DOS console ?

(search in forum but found nothing usefull)

thank you again for all,

(and sorry for bad english)

m.

Link to comment
Share on other sites

Almost done,

thank you PsaltyDS to tell script it by myself,

post code after clean code.

A question, this script is thinked to be used in DOS console,

to avoid operator do manual allignments of a large number of directoryes.

Is possible to have any output in DOS console ?

(search in forum but found nothing usefull)

thank you again for all,

(and sorry for bad english)

m.

Glad you are making it work. ;)

By default AutoIt scripts are compiled as window applications. ConsoleWrite() does not write to the CMD.exe console from a window app.

You can compile your script as a console application by one of several methods. See "Compiling Scripts" in the help file.

A script compiled for console mode will write to the CMD shell console with ConsoleWrite().

:D

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

Done !

--------------------> Compile in /console mode :

Aut2exe.exe /in allign.au3 /out allign.exe /console /unicode

#include <file.au3>
#include <array.au3>
Dim $sourcedir, $destdir
Dim $szDrive, $szDir, $szFName, $szExt

;//////////////////////////////////////////////////////////////////
;//        checks before start
;//////////////////////////////////////////////////////////////////
If $CmdLine[0] <> 2 Then 
    ConsoleWrite("Right syntax : " & @ScriptName & " \sourcedir\*.xyz \destdir\" & @CRLF)
    exit
ElseIf $CmdLine[0] = 2 Then
    
;//////////////////////////////////////////////////////////////////
;//        VARIABLES
;//////////////////////////////////////////////////////////////////
    ; Shows the filenames of all files in the current directory.
    $search_source_file = FileFindFirstFile($CmdLine[1])  
    $sourcedir = $CmdLine[1]
    $destdir = $CmdLine[2]
    
;//////////////////////////////////////////////////////////////////
;//        CONTROLS 
;//////////////////////////////////////////////////////////////////
; Check if the search was successful
    If $search_source_file = -1 Then
    ;MsgBox(0, "Error", "No files/directories matched the search pattern")
        ConsoleWrite("No files/directories matched the search pattern" & @CRLF)
        Exit
    EndIf

    if stringleft(Stringright($sourcedir,4),1) <> "." Then
        ConsoleWrite("Right syntax : " & @ScriptName & " \sourcedir\*.xyz \destdir\" & @CRLF)
        exit
    EndIf

;ADJUST BAD USER DEST ENTRY
    if Stringright($destdir,1) <> "\" Then
        $destdir = $destdir & "\"
    EndIf

;//////////////////////////////////////////////////////////////////
;//       SPLIT PATH FOR EASY USE
;//////////////////////////////////////////////////////////////////
    $split_source_Path = _PathSplit($sourcedir, $szDrive, $szDir, $szFName, $szExt)
    $split_dest_Path = _PathSplit($destdir, $szDrive, $szDir, $szFName, $szExt)

;//////////////////////////////////////////////////////////////////
;//       MAIN
;//////////////////////////////////////////////////////////////////
    While 1
        $file = FileFindNextFile($search_source_file) 
        If @error Then ExitLoop
        
    ;//////////////////////////////////////////////////////////////////
    ;// IF FILE EXIST CHECK DIM AND COPY IF BIGGER
    ;//////////////////////////////////////////////////////////////////
        If FileExists($split_dest_Path[1] & $split_dest_Path[2] & $file) Then
            $size_source = FileGetSize($split_source_Path[1] & $split_source_Path[2] & $file)
            $size_dest = FileGetSize($split_dest_Path[1] & $split_dest_Path[2] & $file)
            
            if $size_source > $size_dest then 
                FileCopy($split_source_Path[1] & $split_source_Path[2] & $file, $split_dest_Path[1] & $split_dest_Path[2] & $file, 9)
                ConsoleWrite("Found smaller file -> Copy " & $split_source_Path[1] & $split_source_Path[2] & $file & " to " & $split_dest_Path[1] & $split_dest_Path[2] & $file & @CRLF)
            EndIf
            
    ;//////////////////////////////////////////////////////////////////
    ;// ELSE IF NON EXIST COPY TO DEST
    ;//////////////////////////////////////////////////////////////////
        Else

            FileCopy($split_source_Path[1] & $split_source_Path[2] & $file, $split_dest_Path[1] & $split_dest_Path[2] & $file, 9)
            ConsoleWrite("Not found on Dest  -> Copy " & $split_source_Path[1] & $split_source_Path[2] & $file & " to " & $split_dest_Path[1] & $split_dest_Path[2] & $file & @CRLF)
        EndIf
        
    WEnd

; Close the search handle
    FileClose($search_source_file)
    
EndIf

ConsoleWrite("W Autoit !" & @CRLF)

Thank you all for all goodness,

m.

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...