Jump to content

Copy with LOG when new file detected


Recommended Posts

Hello all,

I'm very new to AutoIt and programming/Skripting, please be gentle to me.

For the life of me I cannot find a way for any of my attempts to work, I'm sorry.

 

I'm trying to do the following:

When someone copies a file to "H:\TestCopyOut", it should be recognized that there is a new file and it should be copied to "L:\TestCopyIn" and create a log file in folder "H:\TestCopyOut\LOG" with Date, Time, file name and success/fail.

 

I hope one of you really clever people out there can help me with this please.

I thank you in advance.

Link to comment
Share on other sites

just a note on While...WEnd, it can be a little confusing at first.

in this case we just need to use it to make the script loop over and over, the While checks if the expression is true, and if it is then it proceeds with the script encased in it.

simplest way is to...

While(1)



WEnd

"1" will always be true so the script inside the While...WEnd will repeat over and over. you will need to leave the script running at all times to watch for the file to exist.

If @error Then
    MsgBox(262192, "", @ComputerName & " slaps " & @UserName & " around a bit with a large trout!")
EndIf

"Yeah yeah yeah patience, how long will that take?"  -Ed Gruberman

REAL search results  |  SciTE4AutoIt3 Editor Full Version

Link to comment
Share on other sites

16 minutes ago, alienclone said:

Hi, thanks for the fast reply. I've found all of those already and looked at it but I have no idea how to use all of those, and I know even less how to use those together. Sorry, like I said, I am completely new to this.

Link to comment
Share on other sites

we were all noobs at one point, this is the place to learn.

im on my way to bed at the moment, but you read those help files i linked to, and search using the link in my signature and come up with something that looks like a script and post it here then others will follow with help debugging YOUR SCRIPT.

or you can wait for other members here who like doing other people's homework for them, you may get lucky and not have to learn a thing.

If @error Then
    MsgBox(262192, "", @ComputerName & " slaps " & @UserName & " around a bit with a large trout!")
EndIf

"Yeah yeah yeah patience, how long will that take?"  -Ed Gruberman

REAL search results  |  SciTE4AutoIt3 Editor Full Version

Link to comment
Share on other sites

If @error Then
    MsgBox(262192, "", @ComputerName & " slaps " & @UserName & " around a bit with a large trout!")
EndIf

"Yeah yeah yeah patience, how long will that take?"  -Ed Gruberman

REAL search results  |  SciTE4AutoIt3 Editor Full Version

Link to comment
Share on other sites

so if you use the functions listed you should...

while 

do

sleep

until

fileexists

then

filecopy

filewritelog

wend

If @error Then
    MsgBox(262192, "", @ComputerName & " slaps " & @UserName & " around a bit with a large trout!")
EndIf

"Yeah yeah yeah patience, how long will that take?"  -Ed Gruberman

REAL search results  |  SciTE4AutoIt3 Editor Full Version

Link to comment
Share on other sites

I've managed this so far, it copies the files from "H:\" to "L:\" when I execute the program, but I cannot figure out who or what to do with the rest of the stuff 😞

 

Local $hSearch = FileFindFirstFile("H:\TestCopyOut\*.*")
While 1
   $sFileName = FileFindNextFile($hSearch)
   If @error Then ExitLoop
   If not FileExists("L:\TestCopyIn\" & $sFileName) Then FileCopy("H:\TestCopyOut\" & $sFileName, "C:\TestCopyIn\")
WEnd
FileClose($hSearch)

Link to comment
Share on other sites

22 hours ago, alienclone said:

we were all noobs at one point, this is the place to learn.

im on my way to bed at the moment, but you read those help files i linked to, and search using the link in my signature and come up with something that looks like a script and post it here then others will follow with help debugging YOUR SCRIPT.

or you can wait for other members here who like doing other people's homework for them, you may get lucky and not have to learn a thing.

I've managed this so far, it copies the files from "H:\" to "L:\" when I execute the program, but I cannot figure out who or what to do with the rest of the stuff 😞

 

Local $hSearch = FileFindFirstFile("H:\TestCopyOut\*.*")
While 1
   $sFileName = FileFindNextFile($hSearch)
   If @error Then ExitLoop
   If not FileExists("L:\TestCopyIn\" & $sFileName) Then FileCopy("H:\TestCopyOut\" & $sFileName, "C:\TestCopyIn\")
WEnd
FileClose($hSearch)

Link to comment
Share on other sites

for your log you just need to expand your IF a little bit.

https://www.autoitscript.com/autoit3/docs/libfunctions/_Now.htm

if not fileexists then

filecopy

filewritelog $filename date

endif

 

 

 

If @error Then
    MsgBox(262192, "", @ComputerName & " slaps " & @UserName & " around a bit with a large trout!")
EndIf

"Yeah yeah yeah patience, how long will that take?"  -Ed Gruberman

REAL search results  |  SciTE4AutoIt3 Editor Full Version

Link to comment
Share on other sites

 

4 hours ago, FrancescoDiMuro said:

@ProgrammingNoob

Don't even say that!

What problem are you facing now?

Post your script so we can help you :)

The script is still the same, I cannot figure out how to get it to chech the folder for when a new file come into the folder and I don't get the log file to work

 

This is what I have so far

Local $hSearch = FileFindFirstFile("H:\TestCopyOut\*.*")
While 1
   $sFileName = FileFindNextFile($hSearch)
   If @error Then ExitLoop
   If not FileExists("L:\TestCopyIn\" & $sFileName) Then FileCopy("H:\TestCopyOut\" & $sFileName, "C:\TestCopyIn\")
WEnd
FileClose($hSearch)

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