Page 1 of 1

How to test if a folder is open?

PostPosted: Fri Dec 29, 2017 9:30 am
by MarcoBoschi
I have this problem

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

Code: Select all  Expand view

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: Select all  Expand view

      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

Re: How to test if a folder is open?

PostPosted: Fri Dec 29, 2017 9:43 am
by Enrico Maria Giordano
Code: Select all  Expand view
IF !MOVEFILE( cMyFolder, cMyFolderNew )
    // folder could not be renamed
ENDIF


EMG

Re: How to test if a folder is open?

PostPosted: Fri Dec 29, 2017 2:11 pm
by MarcoBoschi
Many Thanks Enrico,
and what about check only?
It would be great if there was a function for this

Bye
Marco

Re: How to test if a folder is open?

PostPosted: Fri Dec 29, 2017 2:16 pm
by Enrico Maria Giordano
Code: Select all  Expand view
IF !MOVEFILE( cMyFolder, cMyFolder )
    // folder could not be renamed
ENDIF


Note that the same name is using.

EMG

Re: How to test if a folder is open?

PostPosted: Fri Dec 29, 2017 2:38 pm
by MarcoBoschi
:D :!:

Re: How to test if a folder is open?

PostPosted: Wed Jan 10, 2018 12:41 pm
by MarcoBoschi
Another question:
Is it possible to close an open folder?

Code: Select all  Expand view


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

Re: How to test if a folder is open?

PostPosted: Wed Jan 10, 2018 1:03 pm
by Enrico Maria Giordano
Just open another (the original?) folder.

EMG

Re: How to test if a folder is open?

PostPosted: Wed Jan 10, 2018 4:30 pm
by MarcoBoschi
Code: Select all  Expand view

#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

Re: How to test if a folder is open?

PostPosted: Wed Jan 10, 2018 5:06 pm
by Enrico Maria Giordano
Try using SetCurDir().

EMG

Re: How to test if a folder is open?

PostPosted: Thu Jan 11, 2018 1:08 pm
by MarcoBoschi
Error: Unresolved external '_HB_FUN_SETCURDIR' referenced from C:\FWH_NEW\SAMPLES\SETCUR.OBJ
too old my version?

Re: How to test if a folder is open?

PostPosted: Thu Jan 11, 2018 1:29 pm
by Enrico Maria Giordano
Code: Select all  Expand view
#pragma BEGINDUMP

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


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

#pragma ENDDUMP


EMG

Re: How to test if a folder is open?

PostPosted: Thu Jan 11, 2018 1:41 pm
by karinha
Code: Select all  Expand view

#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

Re: How to test if a folder is open?

PostPosted: Thu Jan 11, 2018 2:52 pm
by Enrico Maria Giordano
This is a working sample:

Code: Select all  Expand view
#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