April 29, 2024, 06:25:12 AM

News:

IonicWind Snippit Manager 2.xx Released!  Install it on a memory stick and take it with you!  With or without IWBasic!


IBCleanUp written in EBasic

Started by billhsln, February 24, 2008, 02:00:06 PM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

billhsln

I asked to see the original code, many months ago.  However it seemed that no one had the original for IBCleanUp.  So, I decided that EBasic needed its own version with maybe a few enhancements for the eyes.  This has been a learning experience for me and I found it worth while.  Maybe some one else can benefit from the code (hopefully).  It will also make a useful utility for our users.

I default it to where EBasic's default install goes.  But allow you to change directory, if needed. 

Bill
When all else fails, get a bigger hammer.

Brian

Hi,

I've used it for ages - it is one of Fletchie's offerings - very useful

Brian

barry

I've been using a simple little console program instead.  I put copies wherever I might want it and it works in the current directory only.  I just double click it and it's done.


/*
EBClean
Made from the EBASIC example program READING_DIRECTORIES.EBA
Deletes all .OPTS, .MAP, .A and .O in the current diretory
The line that's commented out can delete .EXE files if it's compiled without comments.
*/

OPENCONSOLE
DEF dir,attrib:INT
DEF filename:STRING

dir = FINDOPEN(getstartpath+"*.*")
IF(dir)
    DO
        filename = FINDNEXT(dir,attrib)
IF attrib & (@FILE_NORMAL|@FILE_ARCHIVE) THEN
IF UCASE$(RIGHT$(filename, 4)) = ".MAP" then
DELETEFILE GETSTARTPATH+filename
ENDIF
IF UCASE$(RIGHT$(filename, 5)) = ".OPTS" then
DELETEFILE GETSTARTPATH+filename
ENDIF
IF UCASE$(RIGHT$(filename, 2)) = ".A" then
DELETEFILE GETSTARTPATH+filename
ENDIF
IF UCASE$(RIGHT$(filename, 2)) = ".O" then
DELETEFILE GETSTARTPATH+filename
ENDIF
/*
IF UCASE$(RIGHT$(filename, 4)) = ".EXE" then
DELETEFILE GETSTARTPATH+filename
ENDIF
*/
ENDIF
UNTIL filename = ""
    FINDCLOSE dir
ENDIF

CLOSECONSOLE
END

billhsln

I am trying very had to learn windows.  I figured trying to emulate a tool, that I thought was neat, would be fun to try to emulate.

Helped show me how to create and use LISTVIEWs and COMBO Boxes.

Just working on learning how to program in Ebasic while writing windows programs.

Bill
When all else fails, get a bigger hammer.

LarryMc

I see it as a good way to learn.

Larry
LarryMc
Larry McCaughn :)
Author of IWB+, Custom Button Designer library, Custom Chart Designer library, Snippet Manager, IWGrid control library, LM_Image control library

Brian

Bill,

I compiled Cleaner (Win XP, SP2) and ran it. I didn't get a GUI,
CPU usage went up to nearly 100% and stopped there, and memory
was being eaten up at an alarming rate. I had to End Task eventually
Any ideas

Brian

billhsln

I am also using Win XP, SP2.  All I am doing is compiling as a Windows.EXE.  Nothing special is done on my end.  I can send you my EXE if that would help.

Bill
When all else fails, get a bigger hammer.

LarryMc

Brian
I compiled and if displayed fine on my XP SP2 machine.

Bill
Only suggestion about program would be not to have "projects" path hard coded.  Let the user select the path they want.

Larry
LarryMc
Larry McCaughn :)
Author of IWB+, Custom Button Designer library, Custom Chart Designer library, Snippet Manager, IWGrid control library, LM_Image control library

pistol350

Quote from: Brian Pugh on February 26, 2008, 09:28:07 AM
Bill,

I compiled Cleaner (Win XP, SP2) and ran it. I didn't get a GUI,
CPU usage went up to nearly 100% and stopped there, and memory
was being eaten up at an alarming rate. I had to End Task eventually
Any ideas

Brian

Win XP SP2 here also and i got the same problem Brian got.
When i first compiled the source without adding any change, the program ran fine, but once i changed the path to my current Ebasic install it did the same thing discribed by Brian.Even after i set the source to its original shape and even deleted all the files brought by the compiling process the program still bugged.
Any Idea what's wrong with it ?
Regards,

Peter B.

billhsln

My program allows you to change/add the correct default address for your programs.  Press the BROWSE button, select the directory where your default files are.

Of course, that might be the problem that other people are having.  Change the DefDir = "C:\\Program Files\\EBDev\\projects\\" to be where your program source files are kept and then retry.

Maybe because the subdirectory does not exist on your machine it goes nuts?

Only a guess.  Still a fairly inexperienced member.

Bill
When all else fails, get a bigger hammer.

LarryMc

Quote from: billhsln on February 26, 2008, 05:17:18 PM
My program allows you to change/add the correct default address for your programs.  Press the BROWSE button, select the directory where your default files are.
I missed that, sorry
Quote from: billhsln on February 26, 2008, 05:17:18 PM
Of course, that might be the problem that other people are having.  Change the DefDir = "C:\\Program Files\\EBDev\\projects\\" to be where your program source files are kept and then retry.

Maybe because the subdirectory does not exist on your machine it goes nuts?
Mine worked and I don't have that directory so I don't think that is it.

I did get the program to go off in never-never land though.
I think I overwhelmed it since my "projects" folder has 11,552 files and 739 sub directories.

Going to do some experimenting and see if I can give you more useful information.

Larry
LarryMc
Larry McCaughn :)
Author of IWB+, Custom Button Designer library, Custom Chart Designer library, Snippet Manager, IWGrid control library, LM_Image control library

LarryMc

There appears to be a major flaw in how it goes through sub directories.

I opened the console within your program and added a printout to the console window of what you're sending to the listview.print lvi," ",ipath," ",filename
' Load Fields with data
CONTROLCMD d1,D1_LV,@LVINSERTITEM,lvi,filename
CONTROLCMD d1,D1_LV,@LVSETTEXT,lvi,1,ipath
' Set Flag on

It keeps reading the same subdirectories over and over but making them appear as they are nested.
In the attached screenshot you can see all the "\\\\\\\\\\\\\\\\\\\\\" between the CONTROLS directory and the files in that directory.
In other words there are one complete set of entries for the CONTROLS directory that appears as:
CONTROLS\blah.bla
and maybe there is 20 entries.
then then we get
CONTROLS\\blah.bla with the 20 entries
CONTROLS\\\blah.bla with the 20 entries
CONTROLS\|\\blah.bla with the 20 entries
CONTROLS\\\\blah.bla with the 20 entries

I wind up with what I'm guessing is over 200 of those \\\ before it goes on

Like I said before windows explorer tells me I have 11,552 files under my Project directory.
I had to control ALT DEL to stop your program and it had addedover 19,000 entries in the listview and was still at the top of my sub-directory structure.

Larry
LarryMc
Larry McCaughn :)
Author of IWB+, Custom Button Designer library, Custom Chart Designer library, Snippet Manager, IWGrid control library, LM_Image control library

LarryMc

February 26, 2008, 06:07:12 PM #12 Last Edit: February 26, 2008, 06:16:52 PM by Larry McCaughn
Other functional question.

If you are store the last dir I browsed to then why to I have to browse, starting at my root directory back to that same sub directory in order to get it to populate the listview.

On startup it should load the path that is in the ini and automatically populate the listveiw.  If there is nothing in the ini then there shouls be nothing in the path drop down.
That wasn't working because it was never finishing when it went off in never-never land.

Also would suggest a checkbox next to browse to choose whether or not to do in to subdirectories. and store that in ini file also.

Just suggestions.

Larry
LarryMc
Larry McCaughn :)
Author of IWB+, Custom Button Designer library, Custom Chart Designer library, Snippet Manager, IWGrid control library, LM_Image control library

LarryMc

Okay I got it working correctly.

1st problem was that when SelDir = GetFolder(d1, "Select directory...")was executed SelDir wasn't terminated with a "\".  So I made the following change SelDir = GetFolder(d1, "Select directory...")
SelDir =SelDir +"\\"

I also modified your getfile sub to look like this:SUB GetFiles(ipath:string)
int dir, attrib, r
string ext, filename

dir = findopen(ipath + "*.*")
IF (dir)
DO
filename = findnext(dir,attrib)
IF len(filename)
IF attrib & @file_directory
IF (filename <> ".") & (filename <> "..")
GetFiles(ipath + filename + "\\" )
ENDIF
ELSE
ext = FileExtension(filename)
IF (ext = ".A") or (ext = ".MAP") or (ext = ".O")
lvi++
' Load Fields with data
CONTROLCMD d1,D1_LV,@LVINSERTITEM,lvi,filename
CONTROLCMD d1,D1_LV,@LVSETTEXT,lvi,1,ipath
' Set Flag on
SetCheckState(d1,D1_LV,lvi,1)
' set column width to Automatic
controlcmd d1,D1_LV,@LVSETCOLWIDTH,0,-1
controlcmd d1,D1_LV,@LVSETCOLWIDTH,1,-1
ENDIF
ENDIF
ENDIF
UNTIL filename = ""
FINDCLOSE dir
ENDIF
SETCONTROLTEXT(d1,D1_ED,str$(lvi+1) + " Files Found")
RETURN
ENDSUB

It now recurses my nested directory like it is suppose to.

Larry
LarryMc
Larry McCaughn :)
Author of IWB+, Custom Button Designer library, Custom Chart Designer library, Snippet Manager, IWGrid control library, LM_Image control library

billhsln

I put in the corrections that Larry McCaughn found.  I only have a few subdirectories under my main Projects, which is probably why it worked ok for me.  Windows says 491 files and 13 folders.  Will also see about adding in your suggestions.

Thanks for alll the help.  Maybe now the program will be more useful.

Thanks,
Bill
When all else fails, get a bigger hammer.

LarryMc

Quote from: billhsln on February 26, 2008, 09:08:48 PM
... I only have a few subdirectories under my main Projects, which is probably why it worked ok for me.

I think it worked for you because you had this line of code in your program:DefDir = "C:\\Program Files\\EBDev\\projects\\"
1) it is a valid path on your machine
2) it is terminated with \\

Larry
LarryMc
Larry McCaughn :)
Author of IWB+, Custom Button Designer library, Custom Chart Designer library, Snippet Manager, IWGrid control library, LM_Image control library

LarryMc

BTW,
I agree that it is a useful program for people to use.

Larry
LarryMc
Larry McCaughn :)
Author of IWB+, Custom Button Designer library, Custom Chart Designer library, Snippet Manager, IWGrid control library, LM_Image control library

billhsln

I added a RadioButton and the logic to use it.  Now you can set the RadioButton to tell whether to parse subdirectories or not.

When the program does the BROWSE, I don't know how to get the Folder Browser to start at any directory other than C:\.

I do save all the places you have BROWSEd, but not exactly sure how to make sure that the last one a person selected ends up being the first one shown.  What it does is show the last one in the Combo Box.

Am putting up this latest version here.

Thanks again for the help in fixing what it did wrong.

Bill
When all else fails, get a bigger hammer.

pistol350

Here is a folder browser example by Sapero.
I think that  is just what you need.
I'll try to find other examples.

'browse for folder
'ibasic pro code
'by sapero

Declare import,SHBrowseForFolder(param1:uint),int
Declare import,SHGetPathFromIDList(param1:uint, param2:uint),int
Declare import,CoTaskMemFree(param1:int),int
Declare Import,RtlZeroMemory(dat:uint,length:int),int
Declare import,SendMessageA(hWnd:uint, message:uint, wParam:int, lparam:uint),uint
'optional
Declare import,SetWindowTextA(hwnd:uint, txt:pointer),int
Declare import,SetWindowLongA(hWnd:uint, nIndex:int, dwNewLong:uint),uint
Declare import,GetWindowLongA(hwnd:uint,nIndex:int),uint
TYPE BROWSEINFO
   UINT hOwner
   UINT pidlRoot
   POINTER pszDisplayName
   POINTER lpszTitle
   UINT ulFlags
   UINT lpfn
   UINT lParam
   UINT iImage
ENDTYPE
CONST WM_USER = 0x400
CONST BFFM_SETSELECTION = WM_USER + 102
CONST BFFM_INITIALIZED = 1
CONST BFFM_VALIDATEFAILED = 3
CONST BIF_RETURNFSANCESTORS = 8
CONST BIF_RETURNONLYFSDIRS = 1
CONST BIF_NEWDIALOGSTYLE = 0x40
CONST BIF_DONTGOBELOWDOMAIN = 2
'optional
CONST BFFM_SELCHANGED = 2
CONST GWL_EXSTYLE = -20
CONST WS_EX_CONTEXTHELP = 0x400

'_________________________________ DEMO
ISTRING dir[261]
IF FolderRequest(0, "get folder", dir, GetStartPath, 0x441) Then messagebox 0, dir, ""

'_________________________________
Sub FolderRequest(hWnd:uint, title:pointer, dir:pointer, initial:pointer, flags:uint),int
   INT r : r = FALSE
   ISTRING buffer[261]
   UINT item_list
   BROWSEINFO bi
   RtlZeroMemory(&bi, len(bi))
   bi.hOwner = hWnd
   bi.lpszTitle = title
   bi.ulFlags = flags
   IF flags = 0 Then bi.ulFlags = BIF_RETURNFSANCESTORS | BIF_RETURNONLYFSDIRS | BIF_NEWDIALOGSTYLE | BIF_DONTGOBELOWDOMAIN
   bi.lpfn = &BrowseFolderCallback
   bi.lParam = initial
   ' Display the browser.
   item_list = SHBrowseForFolder(&bi)
   IF item_list
      IF SHGetPathFromIDList(item_list, &buffer)
         #<STRING>dir = buffer + "\\"
         r = TRUE
      Endif
      CoTaskMemFree(item_list)
   Endif
   Return r
EndSub

'_________________________________
Sub BrowseFolderCallback(hWnd:uint, uMsg:uint, lParam:uint, lpData:uint),int
   UINT dwStyle
   ISTRING szText[261]
   Select uMsg
      Case BFFM_INITIALIZED
         ' Set start directory
         SendMessageA( hWnd, BFFM_SETSELECTION, TRUE, lpData )
         ' Remove the ? from the caption - optional
         dwStyle = GetWindowLongA(hWnd, GWL_EXSTYLE)
         IF (dwStyle & WS_EX_CONTEXTHELP)
            SetWindowLongA(hWnd, GWL_EXSTYLE, dwStyle || WS_EX_CONTEXTHELP)
         Endif
      Case BFFM_SELCHANGED :' optional
         ' Set the window text to the path
         szText= "\x0"
         SHGetPathFromIDList(lParam, &szText)
         SetWindowTextA(hWnd, szText)
      Case BFFM_VALIDATEFAILED
         Return 1
   EndSelect
   Return 0
EndSub
Regards,

Peter B.

pistol350

Another one By Joske  ;)


'browse for folder
'ibasic pro code
'by jos, based on an old example from sean

'declare types and functions
TYPE BROWSEINFO
    DEF hOwner:UINT
    DEF pidlRoot:UINT
    DEF pszDisplayName:POINTER
    DEF lpszTitle:POINTER
    DEF ulFlags:UINT
    DEF lpfn:UINT
    DEF lParam:INT
    DEF iImage:INT
ENDTYPE

DECLARE IMPORT,SHGetPathFromIDList(pidl:INT,pszPath:STRING),INT
DECLARE IMPORT,SHBrowseForFolder(lpbi:BROWSEINFO),INT
DECLARE IMPORT,CoTaskMemFree(pidl:INT)
DECLARE IMPORT,RtlZeroMemory(pData AS POINTER,length AS INT)


DEF w1:WINDOW
DEF fn[260]:ISTRING

OPENWINDOW w1,0,0,600,400,0,0,"BrowseFolder...",&hnd
MOVE w1,0,0

fn = GetFolder(w1, "Select directory...")

IF fn<>""
    MOVE w1, 10,10
    PRINT w1,fn
ELSE
    MOVE w1, 10,10
    PRINT w1,"Cancelled"
ENDIF

WAITUNTIL w1=0

END

'__________________________________________________
SUB hnd
    'handler for the window w1
   
    SELECT @CLASS
           
        CASE @IDCREATE
            CENTERWINDOW w1
           
        CASE @IDCLOSEWINDOW
            CLOSEWINDOW w1
           
    ENDSELECT
   
    RETURN
   
ENDSUB


'__________________________________________________
SUB GetFolder(win:WINDOW, title:STRING), STRING
'open a folderrequest dialog
DEF path[260] AS ISTRING
DEF pszPath AS INT
DEF bi:BROWSEINFO
DEF lpIDList:INT
DEF Buffer:STRING
   
    'initialize variables
    path[0] = 0
    RtlZeroMemory(bi,LEN(bi))
    bi.hOwner = win.hwnd
    bi.pszDisplayName = Buffer
    bi.lpszTitle = title
    bi.ulFlags = 0x00000001

'browse for folder
    lpIDList = SHBrowseForFolder(bi)
    IF lpIDList <> 0
        pszPath = SHGetPathFromIDList(lpIDList,path)
        CoTaskMemFree(lpIDList)
    ENDIF
    RETURN path
ENDSUB
Regards,

Peter B.

LarryMc

February 27, 2008, 07:36:04 AM #20 Last Edit: February 27, 2008, 07:42:38 AM by Larry McCaughn
The one by sapero is the one I use in my programs.  It works great.

My opinion:
1)
The search sub-dir flag should not be tied to a specific directory entry.
As it is now if I do a search on "c:\eb\projects" without sub dir checked I get one entry.  If I then check the sub-dir box then I have to browse for a new folder which might be the same one but I wind up with a second entry for the same folder.

What I would expect to be able to do is browse to a dir and select it.  If the sub-dir box is checked the listview should be populated with my chosen dir and all the sub-dirs.
Now, while looking at the listview and without BROWSING I should be able to uncheck the box and have the listview automatically update, this time leaving out all the sub-dirs.
Then, again without BROWSING, I should be able to check the box and all the sub-dir entried reappear.

Having it operate that way would leave only one dir entry in the listbox.

2)
Duplicate entries should not be entered in the dir listbox.
When a user BROWSES and selects a folder it is easy enough to scan the list and see if that path is already there and if it is select it instead of adding a duplicate OR delete the existing duplicate and re-add it to the top of the list.  The second choice would always have the most recent choice at the top of list.

3)
Get rid of that default dir being loaded into the ini the first time the program is run.  Don't add any entry and just test for no entry elsewhere.

4)
I see nothing that limits the number of entries in the listbox.

I've set up ini files to handle what I think you need to do before

If you take my suggestion about not making duplicates and putting the current selection at the top of the list then finding the last used dir on startup would be easy; its the first one in the ini file (that's because you completely rewrite the ini file each time a change is made.

In order to see if the sub dir flag is set you make it an ini entry also.
your ini records could look something like this:
FLAG|0
PATH|c:\eb\projects\
PATH|c:\aurora\examples\

then you use a structure sort of like this

max_entries=20
entries=0
first_pass_flag=0

'while not EOF
read inifile, linetext$

   if len(linetext$)
      pos =instr(linetext$,"|")
      type$=left$(linetext$,pos-1)
      dat$= mid$(linetext$,pos+1)
      select type$
         case "FLAG"
            ' set or reset the sub-dir checkbox
         Case "PATH"
            if first_pass_flag=0
               current_path$= dat$
               first_pass_flag=1
            endif
           entries++
           if entries < max_entries+1
            ' add path to bottom of listbox
           endif
       endselect

'end while

everytime you change dir or change the sub dir flag the ini file would be completely rewritten so no matter how the program is ended(normal or abnormal) the ini file will be correct.

I hope you understand that what I have said is in no way meant to criticize what you have done.

I'm just offering my ideas for how I would make it work and how I would go about it.
I'm sure that other people have other ideas and other ways to accomplish what I have suggested.  And we can ALL be right.

It's all a learning experience.

Larry
LarryMc
Larry McCaughn :)
Author of IWB+, Custom Button Designer library, Custom Chart Designer library, Snippet Manager, IWGrid control library, LM_Image control library

billhsln

To Larry McCaughn, no, I am not offended in any way.  In fact, I am going to take your suggestions and add them into the program.  I find that your suggestions are all valid and worth while, enough that I am going to work on adding them in to the program.  So, in reality I want to thank you for your suggestions and will work on adding them in.  May take a few days at least to put all this into the program.  Like my Icon says, I am a beginner and working on learning how to use EBasic as much as I can.

I have stored the state of the Flag, but just as a 0 or 1 in front of the SubDirectory, that way each can be saved individually.  Looks a little strange when shown in the Combo box, but was easier for me to implement.

Also, thanks to Pistol350 for the Browser examples.  Will take a close look at them and see what I can take from them and add to mine.

Thanks again,
Bill

PS, anyone who uses the program and then gets the update, I would recommend deleting the INI file every time you get a new version of the program.  I keep making changes to how it looks, so it would be better to delete it every time you get a new update.  Will be working on v1.4....changes given to me by Larry McCaughn.
When all else fails, get a bigger hammer.

pistol350

hi, i just wanted to suggest to had the size of each file
and to finally calculate the total size of all the checked files so that the user knows the size of the space to be free

BTW, due to the small size of each file, it's clear that one won't get much free space  ::)
Regards,

Peter B.

billhsln

I like the ideas (pistol350).  Will incorporate them also.  Gives me another column and a little more experience with files.  Will put total space on the bottom line (not in ListView).

Thanks,
Bill
When all else fails, get a bigger hammer.

billhsln

Larry or pistol350, I am trying to setfont to Courier New, I have tried putting the SETFONT in various places, but nothing seems to make any difference.

Where exactly do I put it.  Any help will be appreciated.

Thanks,
Bill
When all else fails, get a bigger hammer.