It is currently Wed Nov 13, 2019 11:18 am

All times are UTC + 1 hour




Post new topic Reply to topic  [ 6 posts ] 
Author Message
 Post subject: IsFileOpen (by other program?) [Multi.OS][x86,x64]
PostPosted: Sat Oct 05, 2019 1:17 pm 
Offline
Enthusiast
Enthusiast
User avatar

Joined: Mon Jul 08, 2013 8:43 pm
Posts: 243
Hi guys! im back again :)
This is a simple but very interesting lib to know if one file is opened by other program.
Well, i need this to know when an external program finish job with a file. Is nice if you are waiting for other programs.
I was looking for other ways to know it, reading size, and others but no work i spect. If some body know other ways to do this im very interested to learn how.

Enjoy it!.. PBforum the best forum!
feel free to improve or modify..

Code:
; -------------------------------------------------------------
; -------------------------------------------------------------
;
;         lib name: IsFileOpen
;         code by : minimy
;         date    : 2019.10.05
;         O.S.    : Multi (not tested..) tell me about please :)
;         CPU     : x86, x64

;         info    : check if file is open by other program
;         syntax  : check= IsFileOpen(mifile.s)
;         return  : 1 if file is open by other program, 0 if is not opened
;         
;         garanty : three steps ;-)
;         worktime: two beers..  __.oO
;         
; -------------------------------------------------------------
; -------------------------------------------------------------

Procedure IsFileOpen(filename.s)
  Protected.i file= OpenFile(#PB_Any,filename,#PB_File_Append)
  If file
    CloseFile(file)
    ProcedureReturn #False
  Else
    ProcedureReturn #True
  EndIf
EndProcedure

CompilerIf #PB_Compiler_IsMainFile
  CompilerIf #PB_Compiler_Processor= #PB_Processor_x86
    softname.s= "IsFileOpen() [x86]"
  CompilerElse
    softname.s= "IsFileOpen() [x64]"
  CompilerEndIf
 
  ;start check
    mifile.s= "C:\Users\Usuario\Desktop\Proy\TEST\test.txt"
    CreateFile(0,mifile)
    WriteStringN(0,"wtf?")
   
    Debug IsFileOpen(mifile) ;check if file is open by other program
   
    MessageRequester(softname,"File must be open by CreateFile(0,mifile) or other external program. Then return 1")
   
    CloseFile(0)
   
    Debug IsFileOpen(mifile)
    MessageRequester(softname,"File was closed. Now return 0")

CompilerEndIf



Evolution?
Ice age, stone age, iron age, bronze age, industrial age, modern, age, stupidity age..
:)

_________________
If translation=Error: reply="Sorry, Im Spanish": Endif


Top
 Profile  
Reply with quote  
 Post subject: Re: IsFileOpen (by other program?) [Multi.OS][x86,x64]
PostPosted: Sat Oct 05, 2019 9:40 pm 
Offline
Addict
Addict
User avatar

Joined: Thu Jun 07, 2007 3:25 pm
Posts: 3699
Location: Berlin, Germany
viewtopic.php?p=360442#p360442

_________________
Please excuse my flawed English. My native language is PureBasic.
Search
RSBasic's backups


Top
 Profile  
Reply with quote  
 Post subject: Re: IsFileOpen (by other program?) [Multi.OS][x86,x64]
PostPosted: Sun Oct 06, 2019 12:51 pm 
Offline
Enthusiast
Enthusiast
User avatar

Joined: Wed Jun 25, 2014 5:25 pm
Posts: 371
Location: Germany
Under Windows XP: Both codes work.
Under Linux: Both codes don't work.

I have created a new code that should work under Windows, Linux and Mac: IsFileOpen.pbi

_________________
Image
Why OpenSource should have a license
PureBasic-CodeArchiv-Rebirth: Git-Repository / Download -- Any help is welcome!
Manjaro Xfce x64 (Main system) :: WindowsXP/Xubuntu x86 (VirtualBox) :: PureBasic (Linux: x86/x64, Windows: x86) :: All are up to date


Top
 Profile  
Reply with quote  
 Post subject: Re: IsFileOpen (by other program?) [Multi.OS][x86,x64]
PostPosted: Sun Oct 06, 2019 1:52 pm 
Offline
Enthusiast
Enthusiast
User avatar

Joined: Mon Jul 08, 2013 8:43 pm
Posts: 243
Little John wrote:
https://www.purebasic.fr/english/viewtopic.php?p=360442#p360442


Hey, yes LJ your code work! nice!
When i loocking some thing similar no found your code.. good job dude! Thanks!! :wink:

Goof job to kiffi original autor. Nice date 2011 12:11 pm.. like good wine!!

Sicro.. about your code contribution.. Thanks!.. good job!.. I like your license.. Really is amazing! :mrgreen: But Kiffi did it before you [2011 12:11 pm].. keep your medals!! :lol:

Code:
; MIT License
;
; Copyright (c) 2019 Sicro
;
; Permission is hereby granted, free of charge, to any person obtaining a copy
; of this software and associated documentation files (the "Software"), to deal
; in the Software without restriction, including without limitation the rights
; to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
; copies of the Software, and to permit persons to whom the Software is
; furnished to do so, subject to the following conditions:
;
; The above copyright notice and this permission notice shall be included in all
; copies or substantial portions of the Software.
;
; THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
; IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
; FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
; AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
; LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
; OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
; SOFTWARE.


I prefer my waranty license.. LOL :mrgreen: is more fun!
Code:
;         garanty : three steps ;-)
;         worktime: two beers..  __.oO

_________________
If translation=Error: reply="Sorry, Im Spanish": Endif


Top
 Profile  
Reply with quote  
 Post subject: Re: IsFileOpen (by other program?) [Multi.OS][x86,x64]
PostPosted: Mon Oct 07, 2019 6:39 pm 
Offline
Enthusiast
Enthusiast
User avatar

Joined: Mon Jul 08, 2013 8:43 pm
Posts: 243
Hey again, i need do a program to encode streams and is really important have a good detection of final stream signal. Ok.. when i use my code work as i expect. But when use the RenameFile() option no work. I use Win 10 x64.. weird thing..

_________________
If translation=Error: reply="Sorry, Im Spanish": Endif


Top
 Profile  
Reply with quote  
 Post subject: Re: IsFileOpen (by other program?) [Multi.OS][x86,x64]
PostPosted: Tue Oct 08, 2019 7:13 pm 
Offline
Enthusiast
Enthusiast
User avatar

Joined: Wed Jun 25, 2014 5:25 pm
Posts: 371
Location: Germany
minimy wrote:
I like your license.. Really is amazing! :mrgreen:
It is a popular open source license that offers a lot of freedom and is compatible with many countries.
https://choosealicense.com/licenses/mit/
https://choosealicense.com/no-permission/
But yes, the code is possibly not creative enough so that I have a copyright on the code. In that case, my license can just be ignored and everything is fine.

minimy wrote:
But Kiffi did it before you [2011 12:11 pm].. keep your medals!! :lol:
Ideas are not protected without a patent and I only use the native PB command RenameFile() from Kiffi's code and Kiffi can't have copyright on this single command.
Additionally, in my code I have a link to his forum post to honor his idea.

minimy wrote:
I prefer my waranty license.. LOL :mrgreen: is more fun!
Code:
;         garanty : three steps ;-)
;         worktime: two beers..  __.oO
It's not a license, but this in your first post:
minimy wrote:
feel free to improve or modify..

This is also worth to be mentioned here:
luis wrote:
But what's the practical use for something like this ?

I'm asking because:

Code:
if FileIsClosed ("file.txt") ; ok the file was not in use, some time ago, inside that proc
    ; but now ?
endif
Source: https://www.purebasic.fr/english/viewtopic.php?p=398079#p398079

The file could be opened again by a program, if you execute a code inside the If block.

minimy wrote:
But when use the RenameFile() option no work. I use Win 10 x64.
Kiffi's code doesn't work on your operating system?

minimy wrote:
i need do a program to encode streams and is really important have a good detection of final stream signal.
We need more information, such as whether the encoding program terminates after the task.

_________________
Image
Why OpenSource should have a license
PureBasic-CodeArchiv-Rebirth: Git-Repository / Download -- Any help is welcome!
Manjaro Xfce x64 (Main system) :: WindowsXP/Xubuntu x86 (VirtualBox) :: PureBasic (Linux: x86/x64, Windows: x86) :: All are up to date


Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 6 posts ] 

All times are UTC + 1 hour


Who is online

Users browsing this forum: No registered users and 5 guests


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

Search for:
Jump to:  

 


Powered by phpBB © 2008 phpBB Group
subSilver+ theme by Canver Software, sponsor Sanal Modifiye