| View previous topic :: View next topic |
| Author |
Message |
vtol Valued Contributor


Joined: 05 Feb 2004 Posts: 656 Location: Eastern Indiana
|
Posted: Wed Jan 10, 2007 7:32 pm Post subject: detect empty sub folders |
|
|
Whats the best way to detect empty sub folders, I had a way to do it but forgot how I did it.
I have no problem getting the entire directory tree and converting every item to PATH only - etc.., but finding only the enpty folders seems tricky at the moment.
I tried flist DLL with no success, but I maybe I missed something.
I need something like below:
| Code: | IF @equal(@DIRECTORY(@item(1)),@null())
INFO found empty folder
END |
Any ideas would be nice, thanks.. |
|
| Back to top |
|
 |
vdsalchemist Admin Team

Joined: 23 Oct 2001 Posts: 1448 Location: Florida, USA
|
Posted: Wed Jan 10, 2007 7:59 pm Post subject: |
|
|
vtol,
Try this...
| Code: |
List create,9
List FILELIST,9,@Item(1)
If @Equal(@count(9),0)
Info Directory is empty.
Else
If @Greater(@count(9),1)
Info Directory has @count(9) items
Else
Info Directory has @count(9) item
End
End
|
You could do a file list and if the list count is zero then show your message
The code above has a little more too it  _________________ Home of
Give VDS a new purpose!
 |
|
| Back to top |
|
 |
vtol Valued Contributor


Joined: 05 Feb 2004 Posts: 656 Location: Eastern Indiana
|
Posted: Thu Jan 11, 2007 12:32 am Post subject: |
|
|
Thanks DragonSphere, very very nice idea
It works just like you have it, but I added a loop and it still needs some work.
Last edited by vtol on Thu Jan 11, 2007 2:29 am; edited 1 time in total |
|
| Back to top |
|
 |
vtol Valued Contributor


Joined: 05 Feb 2004 Posts: 656 Location: Eastern Indiana
|
Posted: Thu Jan 11, 2007 12:53 am Post subject: |
|
|
OK, I got it working but its adding a few not empty folders.
I added the "LIST clear,9" line, helped some.
Last edited by vtol on Thu Jan 11, 2007 2:27 am; edited 1 time in total |
|
| Back to top |
|
 |
vtol Valued Contributor


Joined: 05 Feb 2004 Posts: 656 Location: Eastern Indiana
|
Posted: Thu Jan 11, 2007 1:13 am Post subject: |
|
|
A few of them are ones that are folders that have sub folders (but no files) so it thinks that folder is empty.
I forget how to delete these useless pages(ones I would rather remove than edit) on the forum, grrrr. 
Last edited by vtol on Thu Jan 11, 2007 2:32 am; edited 1 time in total |
|
| Back to top |
|
 |
vtol Valued Contributor


Joined: 05 Feb 2004 Posts: 656 Location: Eastern Indiana
|
Posted: Thu Jan 11, 2007 1:52 am Post subject: |
|
|
I got it working good in below code, except the first 2 are wrong, not bad for 2 out of 143 items.
Its the only 2 paths that dont have files, but have sub folders with files, so I guess it thinks those 2 items(paths) are empty folders.
Below are the only true REAL empty folders in text.txt:
| Code: | C:\Warzone1100- testing\sequences\New Folder
C:\Warzone1100- testing\multiplay\players\empty1
C:\Warzone1100- testing\multiplay\players\empty1\empty2
C:\Warzone1100- testing\multiplay\players\empty1\empty2\empty3
C:\Warzone1100- testing\texpages\slides\empty5
C:\Warzone1100- testing\texpages\bdrops\empty6
C:\Warzone1100- testing\sequences\New Folder |
Heres the text (directory tree) test.txt file with 143 paths(items) below:
http://www.vtol.us/web-forums/VDS5/projects/detect-empty-folder/test.zip
It has to be in same folder as the compiled EXE.
| Code: | #
# \\\ The TEXT.TXT (directory tree) file must be where program runs ///
#
DIALOG CREATE,Detect empty folders,-1,0,400,354,COLOR white,savepos
DIALOG ADD,STYLE,STYLE1,,9,b,,red
DIALOG ADD,STYLE,STYLE2,,9,,,blue
DIALOG ADD,STYLE,STYLE3,,4,,,blue
DIALOG ADD,STYLE,STYLE4,,11,,,red
DIALOG ADD,text,TEXTtest1,21,10,,,Total number of List"1" Items being Processed
DIALOG ADD,edit,test1,20,227,70,18,,,READONLY
DIALOG ADD,text,TEXTtest2,51,10,,,Process List"#"1,,style3
DIALOG ADD,edit,test2,50,85,305,18,,,READONLY
DIALOG ADD,text,TEXTtest3,81,10,,,Found Items,,style3
DIALOG ADD,edit,test3,80,85,305,18,,,READONLY
DIALOG ADD,text,TEXTtest4,111,10,,,L1 Remaining,,style3
DIALOG ADD,edit,test4,110,85,70,18,,,READONLY
DIALOG ADD,text,TEXTrejected,140,10,,,Rejected,,style3
DIALOG ADD,edit,rejected,140,85,305,18,,,READONLY
DIALOG ADD,text,finished,170,150,,,status,,style4
DIALOG ADD,text,amountTEXT,182,257,,,Total Found,,style2
DIALOG ADD,edit,amount,180,320,70,18,,,READONLY
DIALOG ADD,text,TEXTemptys,195,10,,,Empty Folders Found
DIALOG ADD,edit,emptys,210,10,380,100,,,READONLY,MULTI,scroll
DIALOG ADD,BUTTON,apply,320,10,50,24,APPLY,,,hand
DIALOG ADD,BUTTON,leave,320,340,50,24,Close,,,hand
dialog show
dialog focus,apply
:Evloop
wait event
goto @event()
:applyBUTTON
List create,1
List create,2
List create,9
list loadfile,1,@PATH(%0)test.txt
dialog set,test1,@count(1)
REPEAT
LIST seek,1,0
List FILELIST,9,@Item(1)
dialog set,test2,@item(1)
If @Equal(@count(9),0)
LIST append,2,@item(1)
Else
dialog set,rejected,@item(1)
END
LIST delete,1
LIST clear,9
wait "0.02"
dialog set,test3,@item(2)
dialog set,test4,@count(1)
UNTIL @equal(@count(1),0)
Dialog set,emptys,@text(2)
dialog set,amount,@count(2)
dialog set,finished,Finished "!"
List close,1
List close,2
List close,9
goto evloop
:leaveBUTTON
:close
EXIT |
Last edited by vtol on Thu Jan 11, 2007 11:12 pm; edited 1 time in total |
|
| Back to top |
|
 |
vdsalchemist Admin Team

Joined: 23 Oct 2001 Posts: 1448 Location: Florida, USA
|
Posted: Thu Jan 11, 2007 5:11 pm Post subject: |
|
|
vtol,
Try the code below and let me know.
Find this code
| Code: |
List FILELIST,9,@Item(1)
dialog set,test2,@item(1)
If @Equal(@count(9),0)
LIST append,2,@item(1)
Else
dialog set,rejected,@item(1)
END
|
Replace with this code
| Code: |
List FILELIST,9,@Item(1)
dialog set,test2,@item(1)
If @Equal(@count(9),0)
List clear,9
List FILELIST,9,@Item(1),D
If @Equal(@count(9),0)
LIST append,2,@item(1)
Else
dialog set,rejected,@item(1)
End
Else
dialog set,rejected,@item(1)
END
|
Ok I think I fixed the code above. It should now only give you empty directories. We got rid of all the files first then we get rid of all the directories that have files folders below it. What is left over is just empty folders without any files or folders below them. have fun.... _________________ Home of
Give VDS a new purpose!
 |
|
| Back to top |
|
 |
vtol Valued Contributor


Joined: 05 Feb 2004 Posts: 656 Location: Eastern Indiana
|
Posted: Thu Jan 11, 2007 10:50 pm Post subject: |
|
|
YES!
That fixed it Thanks
I forgot about the D: Directory attribute
I'll update everything and post a resolved after this.
I was using DOS DIR to check leftovers which worked, but I like your way(the right way) much better.
I'll use the same code you just updated in empty folder deletion, cause it may need it when it attempts to delete long paths more than once causing a MS error - hehe.
Thanks for taking time to help, maybe someone else will find a use for this code as well.
I was looking over your Gadget HELP file and see you have tons of work into that project, well worth the price - great job
Last edited by vtol on Fri Jan 12, 2007 12:44 am; edited 3 times in total |
|
| Back to top |
|
 |
vtol Valued Contributor


Joined: 05 Feb 2004 Posts: 656 Location: Eastern Indiana
|
Posted: Fri Jan 12, 2007 8:15 am Post subject: |
|
|
RESOLVED - works as intended now Thanks to dragonsphere
Below are the only true REAL empty folders in text.txt:
| Code: | C:\Warzone1100- testing\multiplay\players\empty1
C:\Warzone1100- testing\multiplay\players\empty1\empty2
C:\Warzone1100- testing\multiplay\players\empty1\empty2\empty3
C:\Warzone1100- testing\Directmodem\empty4
C:\Warzone1100- testing\texpages\slides\empty5
C:\Warzone1100- testing\texpages\bdrops\empty6
C:\Warzone1100- testing\sequences\New Folder |
Heres the text (directory tree) test.txt file with 143 paths(items) below:
http://www.vtol.us/web-forums/VDS5/projects/detect-empty-folder/test.zip
test.txt has to be in same folder as the compiled EXE.
CODE is updated - done Jan 12 2007 2AM
| Code: | #
# \\\ The TEST.TXT (directory tree) file must be where program runs ///
#
DIALOG CREATE,Detect empty folders,-1,0,400,354,COLOR white,savepos
DIALOG ADD,STYLE,STYLE1,,9,b,,red
DIALOG ADD,STYLE,STYLE2,,9,,,blue
DIALOG ADD,STYLE,STYLE3,,4,,,blue
DIALOG ADD,STYLE,STYLE4,,11,,,red
DIALOG ADD,text,TEXTtest1,21,10,,,Total number of List"1" Items being Processed
DIALOG ADD,edit,test1,20,227,70,18,,,READONLY
DIALOG ADD,text,TEXTtest2,51,10,,,Process List"#"1,,style3
DIALOG ADD,edit,test2,50,85,305,18,,,READONLY
DIALOG ADD,text,TEXTtest3,81,10,,,Found Items,,style3
DIALOG ADD,edit,test3,80,85,305,18,,,READONLY
DIALOG ADD,text,TEXTtest4,111,10,,,L1 Remaining,,style3
DIALOG ADD,edit,test4,110,85,70,18,,,READONLY
DIALOG ADD,text,TEXTrejected,140,10,,,Rejected,,style3
DIALOG ADD,edit,rejected,140,85,305,18,,,READONLY
DIALOG ADD,text,finished,170,150,,,status,,style4
DIALOG ADD,text,amountTEXT,182,257,,,Total Found,,style2
DIALOG ADD,edit,amount,180,320,70,18,,,READONLY
DIALOG ADD,text,TEXTemptys,195,10,,,Empty Folders Found
DIALOG ADD,edit,emptys,210,10,380,100,,,READONLY,MULTI,scroll
DIALOG ADD,BUTTON,apply,320,10,50,24,APPLY,,,hand
DIALOG ADD,BUTTON,leave,320,340,50,24,Close,,,hand
dialog show
dialog focus,apply
List create,1
List create,2
List create,9
List create,11,SORTED
:Evloop
wait event
goto @event()
:applyBUTTON
%%file = @PATH(%0)test.txt
IF @FILE(%%file)
list loadfile,1,@PATH(%0)test.txt
ELSE
TITLE Data FILE not found"!"
%%file = @PATH(%0)test.txt
WARN Make sure the TEST"."TXT "FILE" is in the PATH@CR()No action taken".."
TITLE Detect empty folders
goto evloop
END dialog set,test1,@count(1)
# test1 = Total number in List 1 Items to be Processed
# test2 = Process List # 1
# test3 = Found Items
# test4 = L1 Remaining
#
# rejected = Rejected
# finished = Finished
# amount = Total Found
# emptys = Empty Folders Found
REPEAT
LIST seek,1,0
List FILELIST,9,@Item(1)
dialog set,test2,@item(1)
If @Equal(@count(9),0)
List clear,9
List FILELIST,9,@Item(1),D
If @Equal(@count(9),0)
LIST append,2,@item(1)
Else
dialog set,rejected,@item(1)
End
Else
dialog set,rejected,@item(1)
END
LIST delete,1
LIST clear,9
wait "0.02"
dialog set,test3,@item(2)
dialog set,test4,@count(1)
UNTIL @equal(@count(1),0)
Dialog set,emptys,@text(11)
dialog set,amount,@count(2)
dialog set,finished,Finished "!"
goto evloop
:leaveBUTTON
:close
List close,1
List close,2
List close,9
List close,11
EXIT |

Last edited by vtol on Sat Jan 13, 2007 3:30 am; edited 2 times in total |
|
| Back to top |
|
 |
DaveR Valued Contributor


Joined: 03 Sep 2005 Posts: 413 Location: Australia
|
Posted: Fri Jan 12, 2007 12:49 pm Post subject: |
|
|
Your happy dance is little bit premature.
Using your test.txt file is useless for anybody but you, unless they have an identical "C:\Warzone1100- testing\" folder tree to you.
And your | Code: | IF @FILE(%%file)
ELSE
TITLE Data FILE not found"!"
%%file = @PATH(%0)test.txt
WARN Make sure the TEST"."TXT "FILE" is in the PATH@CR()No action taken".."
TITLE Detect empty folders
goto evloop
END
|
Should be | Code: | %%file = @PATH(%0)test.txt
IF @FILE(%%file)
ELSE
TITLE Data FILE not found"!"
WARN Make sure the TEST"."TXT "FILE" is in the PATH@CR()No action taken".."
TITLE Detect empty folders
goto evloop
END
|
or else the %%file variable is non-existant when your code checks if the file exists.
Also, just curious, but why do people often use | Code: | IF @FILE(%%file)
ELSE
blah blah
|
instead of | Code: | IF @not(@FILE(%%file) )
blah blah
|
I added | Code: | list create,10
list filelist,10,C:\Temp,*
list savefile,10,%%path0\test.txt
list close,10
info path is %%path0\
|
to create a test.txt file that I could actually use but while it processes the file and finds 6 empty directories there are no directories listed in the 'empty folders found' textbox. I haven't had a chance to look into why just yet.
I'm also curious as to why you're loading the directory list from a file, instead of using list filelist,1,C:\Warzone1100- testing,* ? _________________ cheers
Dave |
|
| Back to top |
|
 |
vtol Valued Contributor


Joined: 05 Feb 2004 Posts: 656 Location: Eastern Indiana
|
Posted: Sat Jan 13, 2007 3:19 am Post subject: |
|
|
Over all I been testing it here all week and it works on any long paths.
Don't know why my system would be any different as far as directory structure, I tested it on XPpro, XPhome, Win98se and Win2000pro.
The part I wanted works if you get the DATA in correctly, but I never included the GET DATA part, figured everyone else could do that part the way they wanted and modify the other part accordingly.
I just threw in the ELSE statement part in a hurriedly last moment kinda like you misspelled %%path0\ , I updated some parts and moved the LIST statements where there would work better. Thanks for bringing that out
I guess we're all humans with or without synaptic links  |
|
| Back to top |
|
 |
vdsalchemist Admin Team

Joined: 23 Oct 2001 Posts: 1448 Location: Florida, USA
|
Posted: Mon Jan 15, 2007 2:23 pm Post subject: |
|
|
| DaveŽ wrote: | Your happy dance is little bit premature.
Using your test.txt file is useless for anybody but you, unless they have an identical "C:\Warzone1100- testing\" folder tree to you.
|
Dave,
I noticed this as well and just figured that vtol was building some custom program just for this Warzone program. I didn't think vtol was intending this as a generic program to determine empty folders. However it certianly could be made into a generic program or better yet a DSU as I use many parts of it in several programs of my own. _________________ Home of
Give VDS a new purpose!
 |
|
| 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
|
|