How to test if a folder is open?

How to test if a folder is open?

Postby MarcoBoschi » Fri Dec 29, 2017 9:30 am

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
User avatar
MarcoBoschi
 
Posts: 1065
Joined: Thu Nov 17, 2005 11:08 am
Location: Padova - Italy

Re: How to test if a folder is open?

Postby Enrico Maria Giordano » Fri Dec 29, 2017 9:43 am

Code: Select all  Expand view
IF !MOVEFILE( cMyFolder, cMyFolderNew )
    // folder could not be renamed
ENDIF


EMG
User avatar
Enrico Maria Giordano
 
Posts: 8713
Joined: Thu Oct 06, 2005 8:17 pm
Location: Roma - Italia

Re: How to test if a folder is open?

Postby MarcoBoschi » Fri Dec 29, 2017 2:11 pm

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

Bye
Marco
User avatar
MarcoBoschi
 
Posts: 1065
Joined: Thu Nov 17, 2005 11:08 am
Location: Padova - Italy

Re: How to test if a folder is open?

Postby Enrico Maria Giordano » Fri Dec 29, 2017 2:16 pm

Code: Select all  Expand view
IF !MOVEFILE( cMyFolder, cMyFolder )
    // folder could not be renamed
ENDIF


Note that the same name is using.

EMG
User avatar
Enrico Maria Giordano
 
Posts: 8713
Joined: Thu Oct 06, 2005 8:17 pm
Location: Roma - Italia

Re: How to test if a folder is open?

Postby MarcoBoschi » Fri Dec 29, 2017 2:38 pm

:D :!:
User avatar
MarcoBoschi
 
Posts: 1065
Joined: Thu Nov 17, 2005 11:08 am
Location: Padova - Italy

Re: How to test if a folder is open?

Postby MarcoBoschi » Wed Jan 10, 2018 12:41 pm

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
User avatar
MarcoBoschi
 
Posts: 1065
Joined: Thu Nov 17, 2005 11:08 am
Location: Padova - Italy

Re: How to test if a folder is open?

Postby Enrico Maria Giordano » Wed Jan 10, 2018 1:03 pm

Just open another (the original?) folder.

EMG
User avatar
Enrico Maria Giordano
 
Posts: 8713
Joined: Thu Oct 06, 2005 8:17 pm
Location: Roma - Italia

Re: How to test if a folder is open?

Postby MarcoBoschi » Wed Jan 10, 2018 4:30 pm

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
User avatar
MarcoBoschi
 
Posts: 1065
Joined: Thu Nov 17, 2005 11:08 am
Location: Padova - Italy


Re: How to test if a folder is open?

Postby MarcoBoschi » Thu Jan 11, 2018 1:08 pm

Error: Unresolved external '_HB_FUN_SETCURDIR' referenced from C:\FWH_NEW\SAMPLES\SETCUR.OBJ
too old my version?
User avatar
MarcoBoschi
 
Posts: 1065
Joined: Thu Nov 17, 2005 11:08 am
Location: Padova - Italy

Re: How to test if a folder is open?

Postby Enrico Maria Giordano » Thu Jan 11, 2018 1:29 pm

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
User avatar
Enrico Maria Giordano
 
Posts: 8713
Joined: Thu Oct 06, 2005 8:17 pm
Location: Roma - Italia

Re: How to test if a folder is open?

Postby karinha » Thu Jan 11, 2018 1:41 pm

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
João Santos - São Paulo - Brasil - Phone: +55(11)95150-7341
User avatar
karinha
 
Posts: 7813
Joined: Tue Dec 20, 2005 7:36 pm
Location: São Paulo - Brasil

Re: How to test if a folder is open?

Postby Enrico Maria Giordano » Thu Jan 11, 2018 2:52 pm

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
User avatar
Enrico Maria Giordano
 
Posts: 8713
Joined: Thu Oct 06, 2005 8:17 pm
Location: Roma - Italia


Return to FiveWin for Harbour/xHarbour

Who is online

Users browsing this forum: Google [Bot] and 106 guests