UDF tutorial

Started by mawi2k, July 21, 2015, 03:38:56 PM

Previous topic - Next topic

mawi2k

I'm fairly new to programming controls and so I have been walking through the tutorials. This one has me stumped:
http://techsupt.winbatch.com/webcgi/webbatch.exe?techsupt/nftechsupt.web+Tutorials+A~Quick~Course~on~UDFs.txt

Neither Example 6 or Example 5 do what the tutorial says they will. Specifically, they are supposed to give the number of total files located on my C: drive. Instead, they give the file count for the directory where I saved them. Obviously, if I really needed to know C:, then, I'd simply run the file from the root of C: - BUT that fails with the following error:

"Error: C:\Example6UDF.wbt
3353 Struct Error: Nesting of structures is too complex

On line 80 of C:\Example6UDF.wbt
In Routine "getdirsize"

'total=total+GetDirSize[thisdir]'"

WinBatch version 32 2009b
WIL version 6.09bib
Windows 7 64bit


Anyone know what's up with that? By the way, the line 'quoted' actually has (parentheses), not [braces]

....IFICantBYTE

Looking at the example, I seem to think there is an error in it...
Try changing the following line in the UDF from:

;Change to directory to inspect
DirChange(origdir)


To:

;Change to directory to inspect
DirChange(dir)
Regards,
....IFICantBYTE

Nothing sucks more than that moment during an argument when you realize you're wrong. :)

td

The tutorial has been around for a long time.  It looks like someone forgot to check their work way back when and no one ever noticed until now.  The article has been updated.
"No one who sees a peregrine falcon fly can ever forget the beauty and thrill of that flight."
  - Dr. Tom Cade

mawi2k

I'm thoroughly impressed with the response time on that. Wow.

And thank you!

(yeah, I'm that weird guy who really does learn by a walk through the exercises)

mawi2k

Still not working all the way through.
It starts fine but crashes somewhere along the way.
Attaching a RTF with screenshots. This time the error reads:

---
Error: C:\ExampleUDF5.wbt
1031: DirChange: Dir not found/changed

On line 11 of C:\ExampleUDF5.wbt
In Routine "getdirsize"

'DirChange(dir)'

---
In spite of my lack of know-how here, I'm going to try to debug it a little and let you know what I find.

td

The error has to do with folder permissions and symbolic links. You really can't use the script to get the size of every directory on a modern Windows system.  It is possible to work around all the various access limitations and nested symbolic link problems but it would then have to much plumbing to be a good example.

I would recommend just running the script against a non-system sub directory tree to see how it works. 
"No one who sees a peregrine falcon fly can ever forget the beauty and thrill of that flight."
  - Dr. Tom Cade

stanl

Tony,

Just curious. Can the CLR help out here?

td

Would still have the same permission and symbolic link issues to overcome.  It can be done in straight WIL with less effort than either CLR or COM.  The point is that it is just an example of using UDF's to implement recursion and not about finding the size of all the files on a system.   Basically, just don't drop the root of the system drive or other important system directories as your starting point and the example usually works just fine.

If this was an actual task instead of just  an example, there are much easing ways to get it done.
"No one who sees a peregrine falcon fly can ever forget the beauty and thrill of that flight."
  - Dr. Tom Cade

mawi2k

True. I can think of a few other ways to get that data when I need it. But as I can't see the example in the tutorial actually function (unless I try it on an old Win98 system maybe), the inoperability of the exercise and example are a little frustrating.
See, I'm not a noob to computers and support issues, especially with regard to permission issues. So the issues make sense.
But I am just starting to dig into coding. So I have no idea how to correct the code, or how to make it work for some other directory. I know this is old code and probably not worth updating further. Maybe a note/disclaimer on the page to the effect that it will work in some directories but not others.
I much appreciate your thoughts so far, though.