I need to write a .dll for a program that works with some files.
I need to code that every time someone starts the program, it should check in a folder for new files and if there are new ones, it should copy them automatically in the programs folder and restart the program. If there are none the program should just start normally.
My problem is that I dont know how to make the program identify new files since the last time the program was started/closed, because I dont want to monitor the folder the whole time the program is running, but only at the start of the program.
I thought about comparing the files in the 2 folders, but with houndreds of files it would be bad perfomance wise, wouldnt it ?
Besides that if someone knows how to automatically copy files and could give me an idea for it too, that would be great.
Iam very new to vb.net and only have limited experience with coding, so forgive me if I ask some easy questions.
Every idea and answer is much appreciated. Thank you!
UPDATE: Thank you very much guys for your ideas, gonna test some of these :)
You could try this approach.
I use this approach in backing-up my files into our server.
This will check for new files and newer-dated version of an existing file (if any) then overwrites it.
I used the
XCopy command in my
batch files is pretty much basic.
XCopy "C:\YourSourceFolder\*.*" "D:\YourDestinationFolder" /D /S /Y
*.*specifies that all the files inside your directory will be copied.
/Dmeans it copies only those files whose source time is newer than the destination time.
/Swill copy directories and sub directories except empty ones.
/Yoverwrites existing files without prompting
Source: MS-DOS XCopy Command
Now, running it through
VB.Net takes only a one line of code. You could put it in a
Timer_tick or any events you prefer.
Of course, the directory still varies on where did you saved your
Source: Run a batch file in VB.Net
In your case: You could use a
timer that executes this
batch file in an interval of your preference.