View previous topic :: View next topic |
Author |
Message |
Mac Professional Member
Joined: 08 Jul 2000 Posts: 1585 Location: Oklahoma USA
|
Posted: Wed Jan 02, 2002 11:51 am Post subject: Directory Info |
|
|
-- VDS3 AND VDS4 Compatible --
Here's a utility that shows directory info:
number of files, kbytes used, percentage, date.
It also shows some drive info below the list.
This is all VDS, no DOS commands.
Doubleclick on a directory to see its' subdirs.
This project was Henrik's idea.
NOTE: If a directory uses less than 0.01% of
the drive, the percentage will show "<0.01%"
______________________________________________________________________________________________________________________________________________________________________________________________________________________
Code: |
OPTION SCALE, 96
OPTION DECIMALSEP, "."
TITLE By Mac
DIALOG CREATE,Test prog,-1,0,600,300
DIALOG ADD,STYLE,NormText,Courier New,9
DIALOG ADD,Menu,&Drive/Directory,&Open,-,&Exit
DIALOG ADD,Menu,&Sort By,Directory,Files,Usage,Date
DIALOG ADD,LIST,L1,0,2,596,265,,DBLCLICK,NormText
DIALOG ADD,TEXT,T1,266,2,,,"No Drive Chosen..."
DIALOG ADD,STATUS,Stat
DIALOG ADD,PROGRESS,Progbar,285,398,200,12
DIALOG SHOW
rem -- Put horizontal slider on list --
%z = @sendmsg(@winexists(~L1),$0194,2000,0)
LIST CREATE, 1, SORTED
LIST CREATE, 2
LIST CREATE, 3
rem -- Default is to sort by directory --
%%sort = "directory"
:EVLOOP
DIALOG SET, Stat, Ready...
DIALOG CLEAR, Progbar
WAIT EVENT
goto @event()
:OpenMENU
%d = @dirdlg()
if %d
%%item = %d
goto LoadList
end
goto EVLOOP
:L1DBLCLICK
PARSE "%d", @item(L1)
if %d
%%item = %d
goto LoadList
end
goto EVLOOP
:DirectoryMENU
%%sort = "directory"
goto Sort
:FilesMENU
%%sort = "files"
goto Sort
:UsageMENU
%%sort = "percentage used"
goto Sort
:DateMENU
%%sort = "date"
goto Sort
:Sort
rem -- Restore %d if user changes sort order --
if %%item
%d = %%item
goto LoadList
end
goto EVLOOP
:LoadList
%%drivesize = @volinfo(@substr(%d,1,2), S)
%%free = @volinfo(@substr(%d,1,2), F)
%%used = @fsub(%%drivesize, %%free)
%%percent = @fdiv(%%used, %%drivesize)
%%percent = @format(@fmul(%%percent, 100), .2)
DIALOG SET, T1, Drive @substr(%d,1,2)" "@fdiv(%%drivesize, 1000) Megabytes" "@fdiv(%%free, 1000) Megabytes Free" "Drive is %%percent"% Full Sorted by "%%sort
DIALOG SET, Stat, Please Wait...
if @not(@equal(@substr(%d, @len(%d)), "\"))
%d = %d"\"
end
%s = @substr(%d, 1, @pred(@len(%d)))
LIST CLEAR, 1
LIST FILELIST, 1, %d*.*,D
LIST CLEAR, L1
LIST ASSIGN, L1, 1
if @greater(@count(L1), 0)
LIST SEEK, L1, 0
LIST INSERT, L1, @path(%s)
else
LIST ADD, L1, @path(%s)
LIST ADD, L1, %d
end
rem -- Get length of longest item --
%%longest = 0
%x = 0
REPEAT
if @greater(@len(@item(L1, %x)), %%longest)
%%longest = @len(@item(L1, %x))
end
%x = @succ(%x)
UNTIL @equal(%x, @count(L1))
rem -- Go thru list and get info for each dir (skip parent dir) --
%x = 1
REPEAT
PARSE "%d", @item(L1, %x)
if @not(@equal(@substr(%d, @len(%d)), "\"))
%d = %d"\"
end
%s = @substr(%d, 1, @pred(@len(%d)))
GOSUB GetInfo
%x = @succ(%x)
UNTIL @equal(%x, @count(L1))
rem -- Sort info using sorted list 1 --
if @equal(%%sort, "Directory")
rem -- Default --
goto EVLOOP
end
LIST CLEAR, 1
%%parent = @item(L1, 0)
%x = 1
REPEAT
rem -- Get dir, files, bytes, percent,and date --
PARSE "%a;%b;%c;%d;%e", @item(L1, %x)
rem -- Insert desired sort criteria, add to sorted list 1 --
if @equal(%%sort, "files")
LIST ADD, 1, %b"|"@item(L1, %x)
end
if @equal(%%sort, "percentage used")
LIST ADD, 1, %d"|"@item(L1, %x)
end
if @equal(%%sort, "date")
LIST ADD, 1, %e"|"@item(L1, %x)
end
%x = @succ(%x)
UNTIL @equal(%x, @count(L1))
LIST CLEAR, L1
LIST ADD, L1, %%parent
%x = 0
REPEAT
PARSE ";%a;%b;%c;%d;%e", @item(1, %x)
GOSUB AlignSortedData
%x = @succ(%x)
UNTIL @equal(%x, @count(1))
goto EVLOOP
:ExitMENU
:CLOSE
EXIT
rem ---- GOSUB ROUTINES ----
:GetInfo
%%bytes = 0
%%files = 0
LIST CLEAR, 1
LIST CLEAR, 2
LIST CLEAR, 3
rem -- Load files from chosen directory into List 1, and get count --
LIST FILELIST, 1, %d*.*
rem -- Loop thru and get file info, add to list 2 --
if @greater(@count(1), 0)
%p = 0
%y = 0
REPEAT
rem -- Get files of all attributes --
%f = @item(1,%y)
if @file(%f,AHRS)
%f = @file(%f,AHRSZ)
LIST ADD, 2, %f
else
if @file(%f)
%f = @file(%f,Z)
LIST ADD, 2, %f
end
end
rem -- Keep progress bar moving --
%p = @succ(%p)
if @greater(%p, 100)
%p = 0
end
DIALOG SET, Progbar, %p
%y = @succ(%y)
UNTIL @equal(%y, @count(1))
end
rem -- Get all subdirs, if any exists --
LIST FILELIST, 3, %s,*
if @greater(@count(3), 0)
rem -- Loop thru subdirs and get file list for each --
%y = 0
REPEAT
LIST CLEAR, 1
LIST FILELIST, 1, @item(3,%y)\*.*
rem -- Add files to List 2, which has those from main dir --
if @greater(@count(1), 0)
%p = 0
%z = 0
REPEAT
rem -- Get files of all attributes --
%f = @item(1,%z)
if @file(%f,AHRS)
%f = @file(%f,AHRSZ)
LIST ADD, 2, %f
else
if @file(%f)
%f = @file(%f,Z)
LIST ADD, 2, %f
end
end
rem -- Keep progress bar moving --
%p = @succ(%p)
if @greater(%p, 100)
%p = 0
end
DIALOG SET, Progbar, %p
%z = @succ(%z)
UNTIL @equal(%z, @count(1))
end
%y = @succ(%y)
UNTIL @equal(%y, @count(3))
end
rem -- Get total number of files --
%%files = @count(2)
rem -- Get total bytes --
if @greater(@count(2), 0)
%y = 0
REPEAT
if @numeric(@item(2, %y))
%%bytes = @fadd(%%bytes, @item(2, %y))
end
%y = @succ(%y)
UNTIL @equal(%y, @count(2))
end
rem -- Get fraction of kilobytes if less than 1000 bytes --
if @numeric(%%bytes)
if @greater(%%bytes, 999)
%%bytes = @div(%%bytes, 1000)
else
%%bytes = @fdiv(%%bytes, 1000)
%%bytes = @format(%%bytes, .2)
end
rem -- Get percentage of drive --
%%percent = @fdiv(%%bytes, %%drivesize)
%%percent = @format(@fmul(%%percent, 100), .2)
rem -- If less than .01 percent of drive --
if @greater(.01, %%percent)
%%percent = "<0.01"
end
if @greater(5, @len(%%percent))
%%percent = 0%%percent
end
else
%%bytes = "??"
%%percent = "??"
end
rem -- Pad entries with spaces to align --
%%date = @datetime(yyyy/mm/dd, @file(@item(L1),DT))
%s = @item(L1)
REPEAT
%s = %s" "
UNTIL @equal(@len(%s), @succ(%%longest))
REPEAT
%%files = "0"%%files
UNTIL @equal(@len(%%files), 8)
%%files = " "%%files
REPEAT
%%bytes = " "%%bytes
UNTIL @equal(@len(%%bytes), 10)
REPEAT
%%percent = " "%%percent
UNTIL @equal(@len(%%percent), 7)
REPEAT
%%date = " "%%date
UNTIL @equal(@len(%%date), 12)
rem -- Must have all field separators for sort --
LIST PUT, L1, %s "|"%%files files "|"%%bytes kbytes "|"%%percent"%" of drive "|"%%date
exit
:AlignSortedData
REPEAT
%a = %a" "
UNTIL @equal(@len(%a), @succ(%%longest))
REPEAT
%b = " "%b
UNTIL @equal(@len(%b), 15)
REPEAT
%c = " "%c
UNTIL @equal(@len(%c), 17)
REPEAT
%d = " "%d
UNTIL @equal(@len(%d), 17)
REPEAT
%e = " "%e
UNTIL @equal(@len(%e), 12)
LIST ADD, L1, %a "|"%b "|"%c "|"%d "|"%e
exit
|
EDIT - Modified code to sort by user's choice of
dir, files, usage, or date.
Cheers, Mac
Last edited by Mac on Sun Jan 13, 2002 11:09 am; edited 3 times in total |
|
Back to top |
|
|
Mac Professional Member
Joined: 08 Jul 2000 Posts: 1585 Location: Oklahoma USA
|
Posted: Thu Jan 03, 2002 12:29 am Post subject: |
|
|
Modified the code to sort the info by user's choice of
directory, number of files, usage, or dir date.
_________________ VDSug.dll does file IO, check/disable menu items,
non-VDS dlls, draw functions and more...
Free download (30k dll size) at:
http://www.vdsworld.com/download.php?id=361
|
|
Back to top |
|
|
Zoltar VDS Pirate
Joined: 26 Dec 2001 Posts: 91
|
Posted: Thu Jan 03, 2002 7:28 am Post subject: |
|
|
Hi Mac
could you please, attach the dsc file in the same time you
put a source code
Thanks
_________________ Zoltar
http://membres.lycos.fr/ |
|
Back to top |
|
|
Mac Professional Member
Joined: 08 Jul 2000 Posts: 1585 Location: Oklahoma USA
|
Posted: Thu Jan 03, 2002 8:15 am Post subject: |
|
|
I have no idea how to attach a file. Can we even do that?
You can copy and paste the code I posted.
_________________ VDSug.dll does file IO, check/disable menu items,
non-VDS dlls, draw functions and more...
Free download (30k dll size) at:
http://www.vdsworld.com/download.php?id=361
|
|
Back to top |
|
|
Henrik Valued Newbie
Joined: 09 Jul 2000 Posts: 35 Location: Copenhagen, Denmark
|
Posted: Thu Jan 03, 2002 5:56 pm Post subject: Parent Dir Not always included |
|
|
Hi guys !
I found an error in the code.
If you select a directory/dir that has only files in it, two items are added to the dir list, and the second one counts the files in this dir. That is OK, but if you select another drive that has subdirs in it, only one drive item is added to the list and this time there is no second item in the list to count usage (try a drive such as C
Mac, could you please try to fix this so that the parent dir is always counted
Thanks !
Henrik
_________________ Henrik Skov
Email: henrikskov@mail.dk |
|
Back to top |
|
|
Mac Professional Member
Joined: 08 Jul 2000 Posts: 1585 Location: Oklahoma USA
|
Posted: Thu Jan 03, 2002 6:30 pm Post subject: |
|
|
Henrik, it seems to works OK on my system.
Line 166 always loads the files from the parent directory first:
Code: |
LIST FILELIST, 1, %d*.*
|
Maybe I don't understand the problem you're having...
Has anybody else tried this code?
_________________ VDSug.dll does file IO, check/disable menu items,
non-VDS dlls, draw functions and more...
Free download (30k dll size) at:
http://www.vdsworld.com/download.php?id=361
|
|
Back to top |
|
|
Henrik Valued Newbie
Joined: 09 Jul 2000 Posts: 35 Location: Copenhagen, Denmark
|
Posted: Thu Jan 03, 2002 7:29 pm Post subject: The attached files illustrate the problem |
|
|
Mac, please see the two attached files - The one called OK has both a F: and a F:\ with the file count - This is the one drive with only files (no subdirs in the rootdir) on it and the other file is the D: drive which has both files in the rootdir and subdirs and there is only one line D: and not D:\ and thus no counting of the rootdir
They are both pure text files.
_________________ Henrik Skov
Email: henrikskov@mail.dk |
|
Back to top |
|
|
Henrik Valued Newbie
Joined: 09 Jul 2000 Posts: 35 Location: Copenhagen, Denmark
|
Posted: Thu Jan 03, 2002 7:34 pm Post subject: The attached files illustrate the problem - New Post !! |
|
|
Mac, please see the contents of the two files listed below - The one called OK has both a F: and a F:\ with the file count - This is the one drive with only files (no subdirs in the rootdir) on it and the other file is the D: drive which has both files in the rootdir and subdirs and there is only one line D: and not D:\ and thus no counting of the rootdir
THE CONTENTS OF THE FILE THAT'S OK
[DSA]
f:
f:\ | 00000001 files | 1149206 kbytes | 102.40% of f:| 2002-01-03
THE OTHER FILE'S [NOT OK] CONTENTS
[DSA]
d:
d:\bookmark | 00001126 files | 226 kbytes | <0.01% of d:| 2001-12-07
d:\GIRLS | 00000281 files | 85176 kbytes | 00.22% of d:| 2001-12-07
d:\Mail - Outlook - Internal | 00000084 files | 282961 kbytes | 00.74% of d:| 2001-12-07
d:\ms explorer bookmarks | 00001111 files | 223 kbytes | <0.01% of d:| 2001-12-07
d:\Nye MP3 | 00002428 files | ?? kbytes | ?? % of d:| 2001-12-07
d:\PROGZIPS | 00003528 files | 1170130 kbytes | 03.07% of d:| 2001-12-07
d:\projmirr | 00000004 files | 334740 kbytes | 00.88% of d:| 2001-12-07
d:\Skrivebord Backup | 00000000 files | 0.00 kbytes | <0.01% of d:| 2001-12-07
d:\Skrivebord Nyeste | 00000318 files | 42078 kbytes | 00.11% of d:| 2001-12-07
d:\studie_m | 00000001 files | 170573 kbytes | 00.45% of d:| 2001-12-07
d:\studiedata | 00000595 files | 20233 kbytes | 00.05% of d:| 2001-12-08
d:\WIN311 | 00000125 files | 6111 kbytes | 00.02% of d:| 2001-12-07
I had to do this pasting instead of attaching - I don't think we can do that !
Sorry !
Henrik
_________________ Henrik Skov
Email: henrikskov@mail.dk |
|
Back to top |
|
|
Mac Professional Member
Joined: 08 Jul 2000 Posts: 1585 Location: Oklahoma USA
|
|
Back to top |
|
|
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum You can attach files in this forum You can download files in this forum
|
|