Page 1 of 2

ExamineObject()

Posted: Sun Mar 10, 2013 6:12 pm
by Coder
Hi,

Am I correct in saying that now to get all the file info from a file you should use ExamineObject()?

Cheers,
Coder

Re: ExamineObject()

Posted: Sun Mar 10, 2013 10:58 pm
by abalaban
Coder wrote:Hi,
Am I correct in saying that now to get all the file info from a file you should use ExamineObject()?
Indeed you are right!

Re: ExamineObject()

Posted: Sun Mar 10, 2013 11:02 pm
by tonyw
You'll find it a hell of a lot easier than the old way. Faster, too.

Re: ExamineObject()

Posted: Sun Mar 10, 2013 11:23 pm
by Coder
@abalaban/Tony

Thanks. I read the dos library autodoc and did notice some changes including the ExamineObject(). I have not seen any examples around on the net using the ExamineObject().

Cheers,
Coder

Re: ExamineObject()

Posted: Mon Mar 11, 2013 11:03 am
by abalaban
Simplified example from my CompareDirs tool :

Code: Select all

	int32 success= FALSE;
	APTR context = IDOS->ObtainDirContextTags( EX_StringNameInput, dirname,
                                        EX_DoCurrentDir,TRUE, /* for recursive lock */
                                        EX_DataFields,(EXF_NAME|EXF_LINK|EXF_TYPE|EXF_SIZE|EXF_DATE),
                                        TAG_END);
	if (context)
	{
		struct ExamineData *dat;

		while ((dat = IDOS->ExamineDir(context)))
		{
			if ( EXD_IS_DIRECTORY(dat))
			{
				IDOS->PrintF("%s is a directory\n", dat->Name);
			}
			else
			{		
				int64 fileSize = dat->FileSize;
				if ( EXD_IS_LINK(dat) )
				{ // it's a link try to resolve it
					struct ExamineData * linkedobj=
									IDOS->ExamineObjectTags(EX_StringNameInput,dat->Link,TAG_END);
					if (linkedobj)
					{
						fileSize = linkedobj->FileSize;
						IDOS->PrintF("%s is a link to %s whose size is %lld\n", dat->Name, linkedobj->Name, fileSize);

						IDOS->FreeDosObject(DOS_EXAMINEDATA, linkedobj);
						linkedobj = NULL;
					}
				}
				else
				{
					IDOS->PrintF("%s is a file whose size is %lld\n", dat->Name, fileSize);					
				}
			}
		}

		if ( ERROR_NO_MORE_ENTRIES == IoErr())
		{
			success = TRUE; /* normal exit */
		}
		else
		{
			UI->error( _T(MSG_ERR_EXAMINING_DIR) ); /* failure - why ? */
		}

	}
	else
	{
		UI->error( _T(MSG_ERR_OBTAINING_DIR_CONTEXT) ); /* failure - why ? */
	}

	IDOS->ReleaseDirContext(context); /* NULL safe */
You have examples of both ExamineObject (to resolve the link) and ExamineDir, ask if you want more. I'll probably create an article in the wiki about this.

Re: ExamineObject()

Posted: Mon Mar 11, 2013 12:33 pm
by cha05e90
abalaban wrote:I'll probably create an article in the wiki about this.
Pretty, pretty please! :P

Re: ExamineObject()

Posted: Mon Mar 11, 2013 6:48 pm
by Coder
@abalaban

Thanks for the example! That will get me started.

Cheers,
Coder

Re: ExamineObject()

Posted: Mon Mar 11, 2013 11:18 pm
by colinw
[...]
int64 fileSize = dat->FileSize;
if ( EXD_IS_LINK(dat) && 0 == fileSize)
{ // it's a link try to resolve it
[...]

Please avoid making assumptions like this, the filesize has no bearing on whether something is
a linked object or not.
Please distribute only example code provided in the latest autodoc file; dos.doc et al.

I believe the latest SDK files will be publicly distributed shortly.

Re: ExamineObject()

Posted: Tue Mar 12, 2013 8:29 am
by tboeckel
Coder wrote:I have not seen any examples around on the net using the ExamineObject().
Then you didn't look carefully enough. YAM is using ExamineObject() from the very first day since this function started to exist.

Re: ExamineObject()

Posted: Tue Mar 12, 2013 8:56 am
by abalaban
colinw wrote:[...]
int64 fileSize = dat->FileSize;
if ( EXD_IS_LINK(dat) && 0 == fileSize)
{ // it's a link try to resolve it
[...]

Please avoid making assumptions like this, the filesize has no bearing on whether something is
a linked object or not.
Please distribute only example code provided in the latest autodoc file; dos.doc et al.

I believe the latest SDK files will be publicly distributed shortly.
Yes Colin, you are right, it was a short example I extracted from an existing code and in this code I had to resolve the link only when the fileSize was 0. The fact it has null size does not imply anything on the fact the file is a link or not of course.

Source code modified to prevent bad assumptions.