Page 1 of 1 1
Topic Options
#208131 - 2013-12-06 01:01 PM Desktop folder tool
kelp7 Offline
Starting to like KiXtart

Registered: 2002-08-12
Posts: 124
Loc: UK
Hi,

I'd like to write a short script which enumerates all the user folders within the (dependant on O.S.) "c:\documents and settings" or "c:\users" folder and then find out how many items exist within the Desktop sub-folder of each user's folder.

Is there an easy way to enumerate all the folders (not files) that exist in a location and put the results in an array perhaps? Then I'd need to go through the array and enumerate files (not folders) for each element.

Thanks!

(the reason for this is sometimes we have to wipe and rebuild a PC and there have been perhaps 20 - 30 people that may have logged onto that PC. To preserve their desktop items we have to manually back those Desktop folders up. Instead of having to manually go through and check which people are actually storing anything on their Desktop, it'd be nice to have a tool that does this and shows the number of entries on screen of each Desktop folder)


Edited by kelp7 (2013-12-06 01:05 PM)

Top
#208132 - 2013-12-06 02:44 PM Re: Desktop folder tool [Re: kelp7]
Mart Moderator Offline
KiX Supporter
*****

Registered: 2002-03-27
Posts: 4673
Loc: The Netherlands
Have a look at the DirPlus() UDF. It can enumerate items (folders or files or both) in a folder and puts the results into an array. Sound exactly like what you need.
_________________________
Mart

- Chuck Norris once sold ebay to ebay on ebay.

Top
#208133 - 2013-12-06 03:48 PM Re: Desktop folder tool [Re: Mart]
kelp7 Offline
Starting to like KiXtart

Registered: 2002-08-12
Posts: 124
Loc: UK
That's great! Thanks!
Top
#208134 - 2013-12-08 05:23 AM Re: Desktop folder tool [Re: kelp7]
Lonkero Administrator Offline
KiX Master Guru
*****

Registered: 2001-06-05
Posts: 22346
Loc: OK
roaming profiles, anyone?
_________________________
!

download KiXnet

Top
#208138 - 2013-12-09 09:37 AM Re: Desktop folder tool [Re: Lonkero]
kelp7 Offline
Starting to like KiXtart

Registered: 2002-08-12
Posts: 124
Loc: UK
Good God, no thanks.
Top
#208143 - 2013-12-09 04:28 PM Re: Desktop folder tool [Re: Mart]
kelp7 Offline
Starting to like KiXtart

Registered: 2002-08-12
Posts: 124
Loc: UK
 Originally Posted By: Mart
Have a look at the DirPlus() UDF. It can enumerate items (folders or files or both) in a folder and puts the results into an array. Sound exactly like what you need.


The interesting thing with DirPlus() is when I display the number of files found in the console window (calculated by using the UBOUND() function), I seem to get a lot of results that are -1 and I seem to get a result of zero if there is only a single file in, for instance, the Desktop folder.

Any ideas?


Edited by kelp7 (2013-12-09 04:29 PM)

Top
#208144 - 2013-12-09 04:31 PM Re: Desktop folder tool [Re: kelp7]
kelp7 Offline
Starting to like KiXtart

Registered: 2002-08-12
Posts: 124
Loc: UK
Actually, I presume this is because the array is counted from zero upwards, so the first element is zero. I guess when outputting the actual figures to the screen I just need to plus 1 onto the amount.
Top
#208146 - 2013-12-09 04:47 PM Re: Desktop folder tool [Re: kelp7]
Glenn Barnas Administrator Offline
KiX Supporter
*****

Registered: 2003-01-28
Posts: 4403
Loc: New Jersey
I use
 Code:
1 + UBound($aData) + ' elements in the array' ?
when debugging my code. Eliminates the whole "-1 is empty, 0 is 1" issue.. \:\)

Glenn
_________________________
Actually I am a Rocket Scientist! \:D

Top
#208147 - 2013-12-09 04:49 PM Re: Desktop folder tool [Re: Glenn Barnas]
Glenn Barnas Administrator Offline
KiX Supporter
*****

Registered: 2003-01-28
Posts: 4403
Loc: New Jersey
Oh - also..

When working with arrays and especially functions that return arrays, always check for the array being not empty:
 Code:
$aData = SomeFunction()
If $aData < 0
  'No data!' ?
Else
  ; work the array contents
EndIf


Glenn
_________________________
Actually I am a Rocket Scientist! \:D

Top
#208148 - 2013-12-09 05:38 PM Re: Desktop folder tool [Re: Glenn Barnas]
kelp7 Offline
Starting to like KiXtart

Registered: 2002-08-12
Posts: 124
Loc: UK
Thanks Glenn I shall try that as I am still getting spurious results! Further testing needed I think.
Top
Page 1 of 1 1


Moderator:  Jochen, Allen, Radimus, Glenn Barnas, ShaneEP, Ruud van Velsen, Arend_, Mart 
Hop to:
Shout Box

Who's Online
1 registered (Henriques) and 2516 anonymous users online.
Newest Members
fgarcia, Viginette, ManuvdWielNL, Sir_Barrington, batdk82
17889 Registered Users

Generated in 0.097 seconds in which 0.061 seconds were spent on a total of 13 queries. Zlib compression enabled.

Search the board with:
superb Board Search
or try with google:
Google
Web kixtart.org