Jump to content

Copy Files from a Folder to another step by step


Recommended Posts

Hi i wanted to Create a Tool that copy From a Folder like c:\temp to c:\backup where are many other Folders.. in this folders are txt files.. and i want to go into the first folder .. open the folder.. copy all the txt files into c:\backup.. the files in c:\backup get automaticly deleted.. now i had to check if the Folder c:\backup is empty.. is the folder c:\backup is empty i had to copy all the Files of the Next folder of c:\temp into c:\backup.

again simply:

in c:\temp are folders link c:\temp\12, c:\temp\13, c:\temp\2f2w, c:\temp\tger4 goto c:\temp\12 copy *.txt to c:\backup ... watch into c:\backup every 1 minute if its empty.. if not .. wait.. if its empty goto c:\temp\13 and copy *.txt to c:\backup.....

Can Anyone help me?!?

Edited by quicksilver
Link to comment
Share on other sites

I'm happy to help, however, I'm not quite following you on what you want.

Several questions:

1. is the data you are backing up staying on the same drive?

2. If I'm understanding you, you want to copy it, then delete it right away????

do you have any code that you tried doing this?

Link to comment
Share on other sites

No the files are not on the Same drive. Is this important? it is a network drive .. mapped to a local drive.

Yes Copy and than delete the folder.

No because i dont know how to list the folders and get the contents of it.

I'm happy to help, however, I'm not quite following you on what you want.

Several questions:

1. is the data you are backing up staying on the same drive?

2. If I'm understanding you, you want to copy it, then delete it right away????

do you have any code that you tried doing this?

Link to comment
Share on other sites

Nobody can help me :P ?

It seems to be a bit unclear wht you want

I understand there is a folder with textfiles and subfolders

you want to copy all the textfiles per subfolder to a folder wich deletes them

and wait until the delete folder is empty

the weird thing is you copy them to that folder so nothing happens.

you copy files wich are deleted again so at the end nothing has changed.

maybe you mean moving the files?

But why don't just delete them instantly

Link to comment
Share on other sites

Nobody can help me :P ?

untested, but it should work, moves files to backup then sleeps 60 seconds. because it may take a few seconds to execute the function, you may end up with a slightly longer time between backups. pause key stops execution.

HotKeySet("{PAUSE}","IHopeImNotTheOnlyOneThatLaughsAtMyComicallyLongFunctionNamesImAnAss")
$tosearch = "C:\temp"
while 1
    RecFileSearch($tosearch)
    sleep(60000)
WEnd
Func RecFileSearch($current)
    Local $search = FileFindFirstFile($current & "\*.txt")
    While 1
    Dim $file = FileFindNextFile($search)
    If @error Or StringLen($file)<1 Then ExitLoop
    FileMove($file,"c:\backup\")
    If StringInStr(FileGetAttrib($current & "\" & $file),"D") And ( $file <> "." Or $file <> ".." ) Then RecFileSearch($current & "\" & $file)
    WEnd
    FileClose($search)
EndFunc
Func IHopeImNotTheOnlyOneThatLaughsAtMyComicallyLongFunctionNamesImAnAss()
    Exit
EndFunc
Link to comment
Share on other sites

Hm thank you for your help .. But i think it doesnt work :P i have tested it but nothing happend :lmao:

#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)
WEnd
Func RecFileSearch($current)
    Local $search = FileFindFirstFile($current & "\*.txt")
    While 1
    Dim $file = FileFindNextFile($search)
    If @error Or StringLen($file)<1 Then ExitLoop
    FileMove($file,$destination)
    If StringInStr(FileGetAttrib($current & "\" & $file),"D") And ( $file <> "." Or $file <> ".." ) Then RecFileSearch($current & "\" & $file)
    WEnd
    FileClose($search)
EndFunc
Func IHopeImNotTheOnlyOneThatLaughsAtMyComicallyLongFunctionNamesImAnAss()
    Exit
EndFunc

to MrSpacely

I want that the tool move all the files from folder a to folder b. But Only subfolder to subfolder.. not all files at the same time.. First all files in folder 1.. than wait until the backup folder is empty.. than folder 2.. wait until empty.. than folder 3... ... ...

Edited by quicksilver
Link to comment
Share on other sites

Hm thank you for your help .. But i think it doesnt work :P i have tested it but nothing happend :lmao:

#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)
WEnd
Func RecFileSearch($current)
    Local $search = FileFindFirstFile($current & "\*.txt")
    While 1
    Dim $file = FileFindNextFile($search)
    If @error Or StringLen($file)<1 Then ExitLoop
    FileMove($file,$destination)
    If StringInStr(FileGetAttrib($current & "\" & $file),"D") And ( $file <> "." Or $file <> ".." ) Then RecFileSearch($current & "\" & $file)
    WEnd
    FileClose($search)
EndFunc
Func IHopeImNotTheOnlyOneThatLaughsAtMyComicallyLongFunctionNamesImAnAss()
    Exit
EndFunc

to MrSpacely

I want that the tool move all the files from folder a to folder b. But Only subfolder to subfolder.. not all files at the same time.. First all files in folder 1.. than wait until the backup folder is empty.. than folder 2.. wait until empty.. than folder 3... ... ...

if you're reading source and destination folders from a list as it appears by your code, then my approach is inefficient to say the least, but it should still work. if your folder names in the file have trailing backslashes, remove them, or remove the backslashes that my script adds. then it should work...
Link to comment
Share on other sites

  • 3 weeks later...

I've tested it again :P and nothing happend :lmao:

i've copied the script and created a ini with this text:

c:\in

c:\out

but nothing happend :()

try this...

#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)
WEnd
Func RecFileSearch($current)
    Local $search = FileFindFirstFile($current & "\*.txt")
    While 1
    Dim $file = FileFindNextFile($search)
    If @error Or StringLen($file)<1 Then ExitLoop
    If StringInStr(FileGetAttrib($current & "\" & $file),"D") And ( $file <> "." Or $file <> ".." ) Then RecFileSearch($current & "\" & $file)
    FileMove($file,$destination)
    WEnd
    FileClose($search)
EndFunc
Func IHopeImNotTheOnlyOneThatLaughsAtMyComicallyLongFunctionNamesImAnAss()
    Exit
EndFunc

***edit*** forgot to /code

Edited by cameronsdad
Link to comment
Share on other sites

Make sure you have the ini file with the source path as the first line and the destination path as the second line. No trailing backslashes!!

#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)
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 FileCopy($current & "\" & $file, $destination & StringTrimLeft ($Current, Stringlen ($Source)) & "\" & $File)
    If StringInStr(FileGetAttrib($current & "\" & $file),"D") And ( $file <> "." Or $file <> ".." ) Then 
        DirCreate ($destination & StringTrimLeft ($Current, Stringlen ($Source))& "\" & $File)
        RecFileSearch($current & "\" & $file)
        Endif
    WEnd
    FileClose($search)
EndFunc
Func IHopeImNotTheOnlyOneThatLaughsAtMyComicallyLongFunctionNamesImAnAss()
    Exit
EndFunc
Edited by ChrisL
Link to comment
Share on other sites

#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)
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 FileCopy($current & "\" & $file, $destination & "\" & $File)
    If StringInStr(FileGetAttrib($current & "\" & $file),"D") And ( $file <> "." Or $file <> ".." ) Then 
        RecFileSearch($current & "\" & $file)
        Endif
    WEnd
    FileClose($search)
EndFunc
Func IHopeImNotTheOnlyOneThatLaughsAtMyComicallyLongFunctionNamesImAnAss()
    Exit
EndFunc

Link to comment
Share on other sites

There is possible a better way of filtering the file types but this will work I think

#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)
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 
        RecFileSearch($current & "\" & $file)
        Endif
    WEnd
    FileClose($search)
EndFunc
Func IHopeImNotTheOnlyOneThatLaughsAtMyComicallyLongFunctionNamesImAnAss()
    Exit
EndFunc
Link to comment
Share on other sites

Ok

source folder "in"

Destination folder "out"

folder names are variable.. examples LP_2000_n

n is a wildcard from 1 to x

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

out is empty

now the script had to copy *.rdy, *.pdf, *.idx into the out folder from the first folder (LP_2000_01) if the out folder is empty.. after a time intervall the out is empty again.. no the script had to copy all the files from the second folder(LP_2000_02). When it is more easy we can move the folder which has ben copied here LP_2000_01 into a backup folder. Ok?

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