Jump to content
Sign in to follow this  
quicksilver

Copy Files from a Folder to another step by step

Recommended Posts

I'm still not entirely sure what your on about, the below script will only allow a single file to be copied at a time, took out the 1 minute delay so as soon as the out folder is empty then the next file gets copied, you can change the number of allowed files in the out folder.. still not convinced this is what you want though!

#include <Process.au3>
#include <file.au3>
$ini_file = @ScriptDir&"\settings.ini"
$file = FileOpen($ini_file, 0)
$source = FileReadLine($file,1)
$destination = FileReadLine($file,2)
FileClose($file)

TrayTip("Started", "Folder: "&$source, 5, 1)
TraySetState()
TraySetToolTip("Copyfiles")

HotKeySet("{PAUSE}","IHopeImNotTheOnlyOneThatLaughsAtMyComicallyLongFunctionNamesImAnAss")
$tosearch = $source

while 1
    RecFileSearch($tosearch)
   ;sleep(60000) removed sleep and only allow set number of files to be copied before waiting
WEnd
    
Func RecFileSearch($current)
    Local $search = FileFindFirstFile($current & "\*.*")
    While 1
    Dim $file = FileFindNextFile($search)
    If @error Or StringLen($file)<1 Then ExitLoop
    If not StringInStr(FileGetAttrib($current & "\" & $file),"D") And ( $file <> "." Or $file <> ".." ) then 
        if Stringright ($file, 3) = "pdf" or Stringright ($file, 3) = "idx" or Stringright ($file, 3) = "rdy" then 
        ;######################## This section only allows a single file to be copied at once untill removed from the out path, you can change the number of allowed files below If size() > 1
            While 1
            If Size() < 1 then 
                FileCopy($current & "\" & $file, $destination & "\" & $File)
                ExitLoop
            Else 
                Sleep (1000)
            EndIf
            Wend
        ;########################
            Endif
    Endif
    If StringInStr(FileGetAttrib($current & "\" & $file),"D") And ( $file <> "." Or $file <> ".." ) Then 
        RecFileSearch($current & "\" & $file)
        Endif
    WEnd
    FileClose($search)
EndFunc
Func IHopeImNotTheOnlyOneThatLaughsAtMyComicallyLongFunctionNamesImAnAss()
    Exit
EndFunc

Func Size()
    $DirSize = DirGetSize( $destination , 1 )
    return $DirSize[1]
    EndFunc

Share this post


Link to post
Share on other sites

the script seems to work nice.. but i only want to copy all the files in One folder. not one file step to step... i want all the files in one folder... than the next you understand?

folders:

in\LP_2000_01\ files in it bla_n.txt bla_n.rdy bla_n.pdf bla_n.idx

in\LP_2000_02\ files in it bla_n.txt bla_n.rdy bla_n.pdf bla_n.idx

in\LP_2000_03\ files in it bla_n.txt bla_n.rdy bla_n.pdf bla_n.idx

in\LP_2000_04\ files in it bla_n.txt bla_n.rdy bla_n.pdf bla_n.idx

step 1 copy all files (*.pdf,*.idx,*.rdy) from LP_2000_01 to out

look into out if its empty.. when its empty go to the next folder LP_2000_02 and copy all files (*.pdf,*.idx,*.rdy) to out ...

look into out if its empty.. when its empty go to the next folder LP_2000_03 and copy all files (*.pdf,*.idx,*.rdy) to out ...

..

..

Edited by quicksilver

Share this post


Link to post
Share on other sites

Will do 1 directory at a time while "out" is empty

edited.. forgot to get rid of the sleep!

#include <Process.au3>
#include <file.au3>
$ini_file = @ScriptDir&"\settings.ini"
$file = FileOpen($ini_file, 0)
$source = FileReadLine($file,1)
$destination = FileReadLine($file,2)
FileClose($file)

TrayTip("Started", "Folder: "&$source, 5, 1)
TraySetState()
TraySetToolTip("Copyfiles")

HotKeySet("{PAUSE}","IHopeImNotTheOnlyOneThatLaughsAtMyComicallyLongFunctionNamesImAnAss")
$tosearch = $source

while 1
    RecFileSearch($tosearch)
;sleep(60000) ******Edit comment out this sleep
WEnd
    
Func RecFileSearch($current)
    Local $search = FileFindFirstFile($current & "\*.*")
    While 1
    Dim $file = FileFindNextFile($search)
    If @error Or StringLen($file)<1 Then ExitLoop
    If not StringInStr(FileGetAttrib($current & "\" & $file),"D") And ( $file <> "." Or $file <> ".." ) then 
        if Stringright ($file, 3) = "pdf" or Stringright ($file, 3) = "idx" or Stringright ($file, 3) = "rdy" then Filemove($current & "\" & $file, $destination & "\" & $File)
    Endif
    If StringInStr(FileGetAttrib($current & "\" & $file),"D") And ( $file <> "." Or $file <> ".." ) Then 
        While Size() > 1
            Sleep (1000)
            Wend
        RecFileSearch($current & "\" & $file)
        Endif
    WEnd
    FileClose($search)
EndFunc
Func IHopeImNotTheOnlyOneThatLaughsAtMyComicallyLongFunctionNamesImAnAss()
    Exit
EndFunc

Func Size()
    $DirSize = DirGetSize( $destination , 1 )
    return $DirSize[1]
    EndFunc
Edited by ChrisL

Share this post


Link to post
Share on other sites

Share this post


Link to post
Share on other sites

yes and whats the command to move the folder which has been copied into a third backup folder? where i can i add the line in the script?

#include <Process.au3>
#include <file.au3>
$ini_file = @ScriptDir&"\settings.ini"
$file = FileOpen($ini_file, 0)
$source = FileReadLine($file,1)
$destination = FileReadLine($file,2)
$backup = FileReadLine($file,3)
FileClose($file)

TrayTip("Started", "Folder: "&$source, 5, 1)
TraySetState()
TraySetToolTip("copy")

HotKeySet("{PAUSE}","IHopeImNotTheOnlyOneThatLaughsAtMyComicallyLongFunctionNamesImAnAss")
$tosearch = $source

while 1
    RecFileSearch($tosearch)
    sleep(60000)
WEnd
    
Func RecFileSearch($current)
    Local $search = FileFindFirstFile($current & "\*.*")
    While 1
    Dim $file = FileFindNextFile($search)
    If @error Or StringLen($file)<1 Then ExitLoop
    If not StringInStr(FileGetAttrib($current & "\" & $file),"D") And ( $file <> "." Or $file <> ".." ) then
        if Stringright ($file, 3) = "pdf" or Stringright ($file, 3) = "idx" or Stringright ($file, 3) = "rdy" then Filecopy($current & "\" & $file, $destination & "\" & $File)
    Endif
    If StringInStr(FileGetAttrib($current & "\" & $file),"D") And ( $file <> "." Or $file <> ".." ) Then
        While Size() > 1
            Sleep (1000)
            Wend
        RecFileSearch($current & "\" & $file)
        Endif

    WEnd
    DirMove($current, $backup& "\")
    FileClose($search)
EndFunc
Func IHopeImNotTheOnlyOneThatLaughsAtMyComicallyLongFunctionNamesImAnAss()
    Exit
EndFunc

Func Size()
    $DirSize = DirGetSize( $destination , 1 )
    return $DirSize[1]
    EndFunc

this doesnt work :P

Edited by quicksilver

Share this post


Link to post
Share on other sites

yes and whats the command to move the folder which has been copied into a third backup folder? where i can i add the line in the script?

Add backup Dir to line 3 of the ini file..

I haven't tried this properly though!!

#include <Process.au3>
#include <file.au3>
$ini_file = @ScriptDir&"\settings.ini"
$file = FileOpen($ini_file, 0)
$source = FileReadLine($file,1)
$destination = FileReadLine($file,2)
$BackupDir = FileReadLine($file,3)
FileClose($file)

TrayTip("Started", "Folder: "&$source, 5, 1)
TraySetState()
TraySetToolTip("Copyfiles")

HotKeySet("{PAUSE}","IHopeImNotTheOnlyOneThatLaughsAtMyComicallyLongFunctionNamesImAnAss")
$tosearch = $source
Dim $Working
while 1
    
    RecFileSearch($tosearch)
    DirMove ($tosearch & $Working, $backupDir & $Working)
    sleep(1000)
WEnd
    
Func RecFileSearch($current)
    Local $search = FileFindFirstFile($current & "\*.*")
    While 1
    Dim $file = FileFindNextFile($search)
    If @error Or StringLen($file)<1 Then ExitLoop
    If not StringInStr(FileGetAttrib($current & "\" & $file),"D") And ( $file <> "." Or $file <> ".." ) then 
        if Stringright ($file, 3) = "exe" or Stringright ($file, 3) = "idx" or Stringright ($file, 3) = "rdy" then Filecopy($current & "\" & $file, $destination & "\" & $File)
    Endif
    If StringInStr(FileGetAttrib($current & "\" & $file),"D") And ( $file <> "." Or $file <> ".." ) Then 
        While Size() > 1
            Sleep (1000)
        Wend
        $working = "\" & $File
        RecFileSearch($current & "\" & $file)
        
        Endif
    WEnd
    FileClose($search)
EndFunc
Func IHopeImNotTheOnlyOneThatLaughsAtMyComicallyLongFunctionNamesImAnAss()
    Exit
EndFunc

Func Size()
    $DirSize = DirGetSize( $destination , 1 )
    return $DirSize[1]
    EndFunc

Share this post


Link to post
Share on other sites

Any better?

#include <Process.au3>
#include <file.au3>
$ini_file = @ScriptDir&"\settings.ini"
$file = FileOpen($ini_file, 0)
$source = FileReadLine($file,1)
$destination = FileReadLine($file,2)
$BackupDir = FileReadLine($file,3)
FileClose($file)

TrayTip("Started", "Folder: "&$source, 5, 1)
TraySetState()
TraySetToolTip("Copyfiles")

HotKeySet("{PAUSE}","IHopeImNotTheOnlyOneThatLaughsAtMyComicallyLongFunctionNamesImAnAss")
$tosearch = $source

while 1
    
    RecFileSearch($tosearch)
    
    
    sleep(1000)
WEnd
    
Func RecFileSearch($current)
    Local $search = FileFindFirstFile($current & "\*.*")
    While 1
    Dim $file = FileFindNextFile($search)
    If @error Or StringLen($file)<1 Then ExitLoop
    If not StringInStr(FileGetAttrib($current & "\" & $file),"D") And ( $file <> "." Or $file <> ".." ) then 
       ;if Stringright ($file, 3) = "pdf" or Stringright ($file, 3) = "idx" or Stringright ($file, 3) = "rdy" then 
        Filecopy($current & "\" & $file, $destination & "\" & $File)
    Endif
    If StringInStr(FileGetAttrib($current & "\" & $file),"D") And ( $file <> "." Or $file <> ".." ) Then 
        While Size() > 1
            Sleep (1000)
        Wend
        $working = "\" & $File
    ;MsgBox (0,"Backup", $tosearch & $Working & " to " & $backupDir & $Working)
        
        RecFileSearch($current & "\" & $file)
        DirMove ($tosearch & $Working, $backupDir & $Working)
        
        Endif
    WEnd
    FileClose($search)
EndFunc
Func IHopeImNotTheOnlyOneThatLaughsAtMyComicallyLongFunctionNamesImAnAss()
    Exit
EndFunc

Func Size()
    $DirSize = DirGetSize( $destination , 1 )
    return $DirSize[1]
    EndFunc

Share this post


Link to post
Share on other sites

This is the finished Script:

The filter *.pdf,*,idx,*.rdy was disabled :P

#include <Process.au3>
#include <file.au3>
$ini_file = @ScriptDir&"\settings.ini"
$file = FileOpen($ini_file, 0)
$source = FileReadLine($file,1)
$destination = FileReadLine($file,2)
$BackupDir = FileReadLine($file,3)
FileClose($file)

TrayTip("Started", "Folder: "&$source, 5, 1)
TraySetState()
TraySetToolTip("Copyfiles")
HotKeySet("{PAUSE}","IHopeImNotTheOnlyOneThatLaughsAtMyComicallyLongFunctionNamesImAnAss")
$tosearch = $source
  
Func RecFileSearch($current)
    Local $search = FileFindFirstFile($current & "\*.*")
    While 1
    Dim $file = FileFindNextFile($search)
    If @error Or StringLen($file)<1 Then ExitLoop
    If not StringInStr(FileGetAttrib($current & "\" & $file),"D") And ( $file <> "." Or $file <> ".." ) then
        if Stringright ($file, 3) = "pdf" or Stringright ($file, 3) = "idx" or Stringright ($file, 3) = "rdy" then Filecopy($current & "\" & $file, $destination & "\" & $File)
    Endif
    If StringInStr(FileGetAttrib($current & "\" & $file),"D") And ( $file <> "." Or $file <> ".." ) Then
        While Size() > 1
            Sleep (1000)
        Wend
        $working = "\" & $File  
        RecFileSearch($current & "\" & $file)
        DirMove ($tosearch & $Working, $backupDir & $Working)
        
        Endif
    WEnd
    FileClose($search)
EndFunc
Func IHopeImNotTheOnlyOneThatLaughsAtMyComicallyLongFunctionNamesImAnAss()
    Exit
EndFunc

Func Size()
    $DirSize = DirGetSize( $destination , 1 )
    return $DirSize[1]
    EndFunc

while 1
    
    RecFileSearch($tosearch)
    sleep(1000)
WEnd

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  

×
×
  • Create New...