# 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

##### Share on other sites

I want that the script copy the files to c:\backup.. if the backup folder is empty copy the contents of the next folder into c:\backup .. and again.. and again.

##### 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?

##### 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?

##### Share on other sites

Nobody can help me ?

##### Share on other sites

Nobody can help me ?

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

##### Share on other sites

Nobody can help me ?

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

##### Share on other sites

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

#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 #### Share this post ##### Link to post ##### Share on other sites Hm thank you for your help .. But i think it doesnt work i have tested it but nothing happend #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...

##### Share on other sites

I've tested it again and nothing happend

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

c:\in

c:\out

but nothing happend )

##### Share on other sites

I've tested it again and nothing happend

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 #### Share this post ##### Link to post ##### Share on other sites hm dont know... im stupid :/ ? nothing happend.. i dont understand it... did you test it? #### Share this post ##### Link to post ##### 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

##### Share on other sites

ok now it works But it creates a folder .. but i only want to copy the files from the folder... all files with the end *.pdf, *.idx and *.rdy

Edited by quicksilver

##### 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 #### Share this post ##### Link to post ##### 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

##### Share on other sites

Hm ok thanks. Nice Script. But I,ve got 4 folders .. and he copy 3 of the 4 folders.. but he had to wait after the first

##### Share on other sites

can you explain that a bit better..

4 sub folders?

Wait after what?

##### 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?

## Create an account

Register a new account