FiveTech Support Forums

FiveWin / Harbour / xBase community
Board index FiveWin for Harbour/xHarbour How to test if a folder is open?
Posts: 1091
Joined: Thu Nov 17, 2005 11:08 AM
How to test if a folder is open?
Posted: Fri Dec 29, 2017 09:30 AM
I have this problem

There is a menu item that give the possibility to open a folder

Code (fw): Select all Collapse
MENUITEM "Open Folder " + cMyFolder   ACTION SHELLEXECUTE( 0, 0, cMyFolder ,  0, 0, 1 )


I give also the possibility to rename the name of the Folder cMyFolder into cMyFolderNew in some other patrts of the program

Code (fw): Select all Collapse
      frename( cMyFolder , cMyFolderNew )


Is not possible to rename a folder if the folder is open

before changing the name I always warn to close the folder
but in 90% of cases the folder is closed, so I would first
test if it is open and only in this case to alert.

How can I test that the folder is open?

if it were a file I could open it in exclusive mode

any hints
Marco
Marco Boschi
info@marcoboschi.it
Posts: 9022
Joined: Thu Oct 06, 2005 08:17 PM
Re: How to test if a folder is open?
Posted: Fri Dec 29, 2017 09:43 AM
Code (fw): Select all Collapse
IF !MOVEFILE( cMyFolder, cMyFolderNew )
    // folder could not be renamed
ENDIF


EMG
Posts: 1091
Joined: Thu Nov 17, 2005 11:08 AM
Re: How to test if a folder is open?
Posted: Fri Dec 29, 2017 02:11 PM

Many Thanks Enrico,
and what about check only?
It would be great if there was a function for this

Bye
Marco

Marco Boschi
info@marcoboschi.it
Posts: 9022
Joined: Thu Oct 06, 2005 08:17 PM
Re: How to test if a folder is open?
Posted: Fri Dec 29, 2017 02:16 PM
Code (fw): Select all Collapse
IF !MOVEFILE( cMyFolder, cMyFolder )
    // folder could not be renamed
ENDIF


Note that the same name is using.

EMG
Posts: 1091
Joined: Thu Nov 17, 2005 11:08 AM
Re: How to test if a folder is open?
Posted: Fri Dec 29, 2017 02:38 PM

:D:!:

Marco Boschi
info@marcoboschi.it
Posts: 1091
Joined: Thu Nov 17, 2005 11:08 AM
Re: How to test if a folder is open?
Posted: Wed Jan 10, 2018 12:41 PM
Another question:
Is it possible to close an open folder?

Code (fw): Select all Collapse
MENUITEM "Open Folder " + cMyFolder   ACTION SHELLEXECUTE( 0, 0, cMyFolder ,  0, 0, 1 ) 

MENUITEM "Close Folder " + cMyFolder   ACTION SHELLEXECUTE( x, x, cMyFolder ,  x, x, x )

where x is a particular value?

Thanks again
Marco
Marco Boschi
info@marcoboschi.it
Posts: 9022
Joined: Thu Oct 06, 2005 08:17 PM
Re: How to test if a folder is open?
Posted: Wed Jan 10, 2018 01:03 PM

Just open another (the original?) folder.

EMG

Posts: 1091
Joined: Thu Nov 17, 2005 11:08 AM
Re: How to test if a folder is open?
Posted: Wed Jan 10, 2018 04:30 PM
Code (fw): Select all Collapse
#include "fivewin.ch"
FUNCTION MAIN()
LOCAL cMyFolder    := "n:\hse\400"
LOCAL cMyFolderNew := "n:\hse\001"  


SHELLEXECUTE( 0, 0, cMyFolder , 0, 0, 1 )
? "aspetta"
SHELLEXECUTE( 0, 0, cMyFolderNew , 0, 0, 1 )

RETURN NIL

Enrico only if the folder name is the same it works
if the name is differente the second folder is opened and the first remains open
Bye
Marco Boschi
info@marcoboschi.it
Posts: 9022
Joined: Thu Oct 06, 2005 08:17 PM
Re: How to test if a folder is open?
Posted: Wed Jan 10, 2018 05:06 PM

Try using SetCurDir().

EMG

Posts: 1091
Joined: Thu Nov 17, 2005 11:08 AM
Re: How to test if a folder is open?
Posted: Thu Jan 11, 2018 01:08 PM

Error: Unresolved external '_HB_FUN_SETCURDIR' referenced from C:\FWH_NEW\SAMPLES\SETCUR.OBJ
too old my version?

Marco Boschi
info@marcoboschi.it
Posts: 9022
Joined: Thu Oct 06, 2005 08:17 PM
Re: How to test if a folder is open?
Posted: Thu Jan 11, 2018 01:29 PM
Code (fw): Select all Collapse
#pragma BEGINDUMP

#include "windows.h"
#include "hbapi.h"


HB_FUNC( SETCURDIR )
{
    hb_retl( SetCurrentDirectory( hb_parc( 1 ) ) );
}

#pragma ENDDUMP


EMG
Posts: 8523
Joined: Tue Dec 20, 2005 07:36 PM
Re: How to test if a folder is open?
Posted: Thu Jan 11, 2018 01:41 PM
Code (fw): Select all Collapse
#Include "FiveWin.ch"

Static cDirName

function Main()

   #Ifdef __XHARBOUR__

      cDirName := CurDrive() + ":\" + CurDir()  // xHarbour

   #Else

      cDirName := hb_CurDrive() + ":\" + CurDir()  // Harbour

   #Endif

   ? cDirName

   SetCurDir( cDirName )

Return nil
João Santos - São Paulo - Brasil - Phone: +55(11)95150-7341
Posts: 9022
Joined: Thu Oct 06, 2005 08:17 PM
Re: How to test if a folder is open?
Posted: Thu Jan 11, 2018 02:52 PM
This is a working sample:

Code (fw): Select all Collapse
#include "Fivewin.ch"


FUNCTION MAIN()

    LOCAL cCur := CURDRIVE() + ":\" + CURDIR()

    LOCAL cDir := "MYTESTDIR"

    ? "CREATEDIR()", CREATEDIR( cDir )

    ? "SETCURDIR()", SETCURDIR( cDir )

    ? "ISOPEN()", ISOPEN( cDir )

    ? "SETCURDIR()", SETCURDIR( cCur )

    ? "ISOPEN()", ISOPEN( cDir )

    RETURN NIL


STATIC FUNCTION ISOPEN( cDir )

    RETURN !MOVEFILE( cDir, cDir )


#pragma BEGINDUMP

#include "windows.h"
#include "hbapi.h"


HB_FUNC( CREATEDIR )
{
    hb_retl( CreateDirectory( hb_parc( 1 ), ( LPSECURITY_ATTRIBUTES ) hb_parnl( 2 ) ) );
}


HB_FUNC( MOVEFILE )
{
    hb_retl( MoveFile( hb_parc( 1 ), hb_parc( 2 ) ) );
}


HB_FUNC( SETCURDIR )
{
    hb_retl( SetCurrentDirectory( hb_parc( 1 ) ) );
}

#pragma ENDDUMP


EMG

Continue the discussion