myspacee Posted September 2, 2008 Posted September 2, 2008 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.
mc83 Posted September 2, 2008 Posted September 2, 2008 hiwell... you can get a list of files in a directory by using _FileListToArray() and then you can go through all of the files and check their size with FileGetSize()hope this helps
myspacee Posted September 2, 2008 Author Posted September 2, 2008 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.
PsaltyDS Posted September 2, 2008 Posted September 2, 2008 i think different approach :list files in source directoryif not exist in destination -> copyelse exist in dest. directory read kb sizeif > copyif < nextanyone 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() Thenelse exist in dest. directory read kb size ===> Else, FileGetSize()if > copy ===> FileCopy()if < next ===> For/Next loop with array, or While/WEnd, or Do/UntilGive 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
myspacee Posted September 3, 2008 Author Posted September 3, 2008 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.
PsaltyDS Posted September 3, 2008 Posted September 3, 2008 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(). 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
myspacee Posted September 3, 2008 Author Posted September 3, 2008 Done ! --------------------> Compile in /console mode : Aut2exe.exe /in allign.au3 /out allign.exe /console /unicode expandcollapse popup#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.
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