checking if file exist or is duplicate ?

Just starting out? Need help? Post your questions and find answers here.
BackupUser
PureBasic Guru
PureBasic Guru
Posts: 16777133
Joined: Tue Apr 22, 2003 7:42 pm

Post by BackupUser »

Restored from previous forum. Originally posted by Ralf.

everyday i receive a file in directory P:\comein\
in this directory there are 5 files from the last 5 days.
i want to copy 1 of them and check whether i already got
this file. if i got it i don't want to copy it.
If i didn't have it i want to copy it to C:\COMEIN and C:\SAVE.
All this i do manually. How can i make a programm in PUREBASIC which
does this for me ?
BackupUser
PureBasic Guru
PureBasic Guru
Posts: 16777133
Joined: Tue Apr 22, 2003 7:42 pm

Post by BackupUser »

Restored from previous forum. Originally posted by Inner.

create a CRC list of all the files in storage, and then check the new file(s) CRC agist the ones in the list.
BackupUser
PureBasic Guru
PureBasic Guru
Posts: 16777133
Joined: Tue Apr 22, 2003 7:42 pm

Post by BackupUser »

Restored from previous forum. Originally posted by Ralf.

i hoped that someone could give me some lines of coding,
because i am still a beginner.
BackupUser
PureBasic Guru
PureBasic Guru
Posts: 16777133
Joined: Tue Apr 22, 2003 7:42 pm

Post by BackupUser »

Restored from previous forum. Originally posted by Kale.

BTW what is a CRC list anyway?

--Kale

In love with PureBasic! :)
BackupUser
PureBasic Guru
PureBasic Guru
Posts: 16777133
Joined: Tue Apr 22, 2003 7:42 pm

Post by BackupUser »

Restored from previous forum. Originally posted by freak.

CRC is a checksum for some data, wich is calculated including every byte of the data (or file). So if you only change one byte of the data, the checksum will be different. This is very good, to check if the data is correct, or was changed.

PureBasic has a CRC32Fingerprint Function (Cipher Lib) to get that checksum (long Value) for a data buffer.

However, i would not use that one here, as you would have to open every File, read them to Memory, and then use the function. This isn't good especially for big files.

In Rings's FastFile Lib, there is a Function to calculate this Checksum directly from the file:

checksum.l = FASTFILECRC32(Filename.s)

But I think Ralph doesn't need any CRC here, checking the filenames should be ok as i understand that:

So here is what you do:

Use a txt file to store the names of the files you allready have in (this can be empty at first, if you have no files)

At start of your program, open that file, and read every line into an Array of Strings.

Then, use Examinedirectoy() on the Folder where the new files are, and get all files using NextDirectoryEntry() and Directoryentryname() in a Loop.

In that loop, everytime there is a file, loop through the String array, to check if that Filename allready exists there, if it does, ignore it (then you don't want to copy it)

It it doesn't exist, do your copy operations with CopyFile() after that, add the Filename to the String Array, so the prog knows that you allready have it.

At the end of the prog, delete the Text file, and create a new one. Loop through the Array of Strings, and write every Filename to the new txt file (WriteStringN() ) So you have the newly copied files written to the txt file.

Well, that's it, on the next start of the prog, it knows which files it allready has copied.

Hope you get the idea, i am to lazy to write the code myself (it is also better learing for you, if you try yourself)

Timo
BackupUser
PureBasic Guru
PureBasic Guru
Posts: 16777133
Joined: Tue Apr 22, 2003 7:42 pm

Post by BackupUser »

Restored from previous forum. Originally posted by Ralf.

it gives me an idea, but i think i am not able to do that.
But thanks anyway.
BackupUser
PureBasic Guru
PureBasic Guru
Posts: 16777133
Joined: Tue Apr 22, 2003 7:42 pm

Post by BackupUser »

Restored from previous forum. Originally posted by TerryHough.
Originally posted by Ralf
All this i do manually. How can i make a programm in PUREBASIC which
does this for me ?
Timo has an elegant solution as usual... :) if you want to do it
with PureBasic.

However, writing a program may be completely unnecessary. Don't overlook the DOS BATCH commands available if you are using Win9x or ME.

For example, let's assume the file that you receive always has an filename extension of .STF and arrives in P:\COMEIN.

Put these example lines in a batch file, and then let the Windows Scheduler run it on a schedule. Be sure to set the .PIF file to
allow it to run minimized and Exit on end.

IF EXIST P:\COMEIN\*.STF COPY P:\COMEIN\*.STF C:\COMEIN\.
IF EXIST P:\COMEIN\*.STF MOVE P:\COMEIN\*.STF C:\SAVE\.
Rem Now, do something with the received file with a Win program
Rem running maximized, in the foreground, and wait till it
Rem finishes before exiting this batch file.
START DOSTUFF /M /R /W
Rem Optionally, tell the user I finished.
Rem ECHO I did the stuff...
Rem PAUSE

After the batch file runs, all of the STF files will have been
copied where you need them and removed from P:\COMEIN.

Of course, this will only work if the files have unique names otherwise new files will overlay old files.

That can be avoided by including the /-Y switch on each line, and files will not be overlaid without your permission. This makes it less automatic though.

Look at the COPY, MOVE, and XCOPY batch command Helps for more info.
E.g. XCOPY /? from your MSDOS prompt.

There are several variations of this idea that I have used quite successfully.

Hope this helps,
Terry
BackupUser
PureBasic Guru
PureBasic Guru
Posts: 16777133
Joined: Tue Apr 22, 2003 7:42 pm

Post by BackupUser »

Restored from previous forum. Originally posted by Ralf.

yes i konw that but there are always five files in P:\COMEIN´.
There are call like B100016JJJJMMDD.nnn where JJJJ means year (2003) than MM = month DD = Day and nnn is the following number = 001 for the first of the day 002 is the second. so the latest five files are in this directory. I only need to copy the latest one to C:\WORKWITH
and i could copy all to C:\SAVE (which is not a Problem). But from C:\WORKWITH the file will be transfered to an automatic process.
i could use an dir command within QBASIC (SHELL "DIR P:\COMEIN/*.*/b/i/-p/O:D > files.tmp"). This will put a listing of all files in P:\COMEIN to files.tmp sorted by date. So i could cut
the first four lines and use the last line as a parameter, but how ?
in files.tmp
BackupUser
PureBasic Guru
PureBasic Guru
Posts: 16777133
Joined: Tue Apr 22, 2003 7:42 pm

Post by BackupUser »

Restored from previous forum. Originally posted by Ralf.

by the way the problem is i only have rights to read and copy from P:\COMEIN but i don't have the right to delete or modify in P:\COMEIN.
OTHERWISE it wouldn't be a problem.
BackupUser
PureBasic Guru
PureBasic Guru
Posts: 16777133
Joined: Tue Apr 22, 2003 7:42 pm

Post by BackupUser »

Restored from previous forum. Originally posted by freak.

Hum, I don't really know where the problem is now. You anoly need commands from 2 libs: FileSystem and File.
I allready explained which command to use when, i cab'T explain it any easier. Otherwise i could also write that code for you, whch his not what i want to do.

Just saying 'i am not able to do that, please write some code for me' is not the right way to go here.
Think a bit for yourself, read the Manual, (and as you are german, you can also read the PB Book Andre wrote: http://www.purebasic.de/files/handbuch.pdf), try to understand it, and do it for yourself. IF you have any specific question(s) feel free to ask them, but i won't write some compleete code for you. (unless you pay me some $ )

Timo
BackupUser
PureBasic Guru
PureBasic Guru
Posts: 16777133
Joined: Tue Apr 22, 2003 7:42 pm

Post by BackupUser »

Restored from previous forum. Originally posted by TerryHough.
Originally posted by Ralf
I could use an dir command within QBASIC (SHELL "DIR P:\COMEIN/*.*/b/i/-p/O:D > files.tmp"). This will put a listing of all files in P:\COMEIN to files.tmp sorted by date. So i could cut
the first four lines and use the last line as a parameter, but how ?
in files.tmp
How about
DIR P:\COMEIN\*.* /b /-od > FILES.TMP
which would put the list in FILES.TMP with the first line being the most recent file you have received. Then have your automatic process open FILES.TMP and read the first line to determine which file to work with.
Post Reply