copying files while maintaining dateModified

For questions and postings not covered by the other forums
ConvertFromOldNGs
Posts: 5321
Joined: Wed Aug 05, 2009 5:19 pm

copying files while maintaining dateModified

Postby ConvertFromOldNGs » Fri Aug 07, 2009 12:18 pm

by pillick >> Sun, 5 Jan 2003 21:31:08 GMT

Hi.

I have some raw data files which are identified by thier name and the date they were modified. I would like jade to automatically copy these files and store them in an organized way. Ive written the code to do this.

I copy the files by reading them as binary, then creating the destination file and writing to it. the problem with this is that the new file does not have the same datemodified as the original file. Which means they cannot be identified properly later if someone moves them around.

How do you copy a file and still have the same date modified?

ConvertFromOldNGs
Posts: 5321
Joined: Wed Aug 05, 2009 5:19 pm

Re: copying files while maintaining dateModified

Postby ConvertFromOldNGs » Fri Aug 07, 2009 12:18 pm

by allistar >> Sun, 5 Jan 2003 21:54:05 GMT

Hi there,
We have systems that do exactly that, by using a little bit of C++ trickery:

Here is a function in C that retrieves the modified time of a file:

extern "C" __declspec(dllexport)
void getFileModifiedTime(char *fileName, int *highBits, int *lowBits)
{
*highBits = 0;
*lowBits = 0;

HANDLE hFile = CreateFile(fileName, GENERIC_READ,
FILE_SHARE_READ, NULL, OPEN_EXISTING,
FILE_ATTRIBUTE_NORMAL, NULL);
if (hFile == INVALID_HANDLE_VALUE)
return;
FILETIME creation, lastAccess, lastWrite;
GetFileTime(hFile, &creation, &lastAccess, &lastWrite);
*highBits = lastWrite.dwHighDateTime;
*lowBits = lastWrite.dwLowDateTime;
CloseHandle(hFile);
}

Using that you should be able to easily create a similar function that sets the modified time instead of retrieves it. It is not hard to make that into an external function that you call from Jade (if you are
unsure how to do that I can give you some pointers).

You will have to temporarilty store the time in Jade a two integers, represented by "highBits" and "lowBits" in the above code.

Hopefully this helps,
Allistar.

------------------------------------------------------------------
Allistar Melville
Software Developer
Auckland, NEW ZEALAND

Greentree International,
Developer of Greentree Financial Software. ------------------------------------------------------------------

ConvertFromOldNGs
Posts: 5321
Joined: Wed Aug 05, 2009 5:19 pm

Re: copying files while maintaining dateModified

Postby ConvertFromOldNGs » Fri Aug 07, 2009 12:18 pm

by cnwdad1 >> Sun, 5 Jan 2003 22:08:18 GMT

Rather than copying the file, why not use the File::rename method ? It's probably quicker than doing the copying yourself, it works across disk drives, and it preserves the file's timestamp. For example:

vars
theFile : File;
fileName : String;begin

create theFile transient;

if theFile.cnEcSetOpenName(true, false) then
fileName := theFile.cnEcUnqualName();
theFile.rename("d:\temp\" & fileName);
endif;
epilog
delete theFile;
end;

regards,
darrell.

ConvertFromOldNGs
Posts: 5321
Joined: Wed Aug 05, 2009 5:19 pm

Re: copying files while maintaining dateModified

Postby ConvertFromOldNGs » Fri Aug 07, 2009 12:18 pm

by pillick >> Sun, 5 Jan 2003 22:32:41 GMT

I dont want to copy the file - I dont want to move it.

ConvertFromOldNGs
Posts: 5321
Joined: Wed Aug 05, 2009 5:19 pm

Re: copying files while maintaining dateModified

Postby ConvertFromOldNGs » Fri Aug 07, 2009 12:18 pm

by cnwdad1 >> Sun, 5 Jan 2003 22:45:53 GMT

The File::rename method will, effectively, move the file.

regards,
darrell.

ConvertFromOldNGs
Posts: 5321
Joined: Wed Aug 05, 2009 5:19 pm

Re: copying files while maintaining dateModified

Postby ConvertFromOldNGs » Fri Aug 07, 2009 12:18 pm

by allistar >> Sun, 5 Jan 2003 22:45:54 GMT

Hi pillick,
If you want to I can send you a dll that gets and sets the modified time of a file. Just let me know what you want the dll called, it'll
only take me 5 minutes to bash out.

Regards,
Allistar.

------------------------------------------------------------------
Allistar Melville
Software Developer
Auckland, NEW ZEALAND

Greentree International,
Developer of Greentree Financial Software. ------------------------------------------------------------------

ConvertFromOldNGs
Posts: 5321
Joined: Wed Aug 05, 2009 5:19 pm

Re: copying files while maintaining dateModified

Postby ConvertFromOldNGs » Fri Aug 07, 2009 12:18 pm

by pillick >> Sun, 5 Jan 2003 23:28:02 GMT

that would be really cool, but you will need to show me how to use it as well. My email addy is dnk2@waikato.ac.nz.

Thanks!

ConvertFromOldNGs
Posts: 5321
Joined: Wed Aug 05, 2009 5:19 pm

Re: copying files while maintaining dateModified

Postby ConvertFromOldNGs » Fri Aug 07, 2009 12:19 pm

by allistar >> Mon, 6 Jan 2003 0:33:37 GMT
that would be really cool, but you will need to show me how to use it as well. My email addy is dnk2@waikato.ac.nz.

Done.
Thanks

No problem.

------------------------------------------------------------------
Allistar Melville
Software Developer
Auckland, NEW ZEALAND

Greentree International,
Developer of Greentree Financial Software. ------------------------------------------------------------------

ConvertFromOldNGs
Posts: 5321
Joined: Wed Aug 05, 2009 5:19 pm

Re: copying files while maintaining dateModified

Postby ConvertFromOldNGs » Fri Aug 07, 2009 12:19 pm

by cnwrwm1 >> Sun, 5 Jan 2003 23:18:53 GMT

If you have CardSchema, then there is a method on the File class ::cnSetLastModified which will allow you to change the timestamp. Note that this uses an external method in karma.dll, and is therefore not suitable for modifying files on the thin client workstation.

Richard Mitchell
JADE Software Corp


Return to “General Discussion”

Who is online

Users browsing this forum: No registered users and 13 guests