BookmarkSubscribeRSS Feed
LineMoon
Lapis Lazuli | Level 10

Hello Experts,

In action 1 : I  zip a file  toto in  toto.zip

In action 2: I  unzip a file  toto.zip  in  test

Before doing the action 2, I would to check if the file toto.zip is not in use.

 

Thank you

 

 

 

4 REPLIES 4
ChrisNZ
Tourmaline | Level 20

The easiest way to do this is to try and rename the file. If the rename action works, then the file is not locked.

Another way is try and FOPEN() or MOPEN() the file.

Kurt_Bremser
Super User

@ChrisNZ wrote:

The easiest way to do this is to try and rename the file. If the rename action works, then the file is not locked.

Another way is try and FOPEN() or MOPEN() the file.


Won't work on UNIX. Since in UNIX, file metadata (location on disk, permissions, timestamps) is stored in the inode, and the filename(s) in the directories, a rename can be done while a file is in use. One can even remove (unlink) a file that is in use, something I use to avoid "file is locked by another user" issues.

In UNIX, one should use the fuser commandline tool to determine if processes have a file handle on the file (inode) in question.

ChrisNZ
Tourmaline | Level 20
@Kurt_Bremser I assume we have a windows user here, but you are right, Unix is different. The functions should work on unix too though, shouldn't they?
Kurt_Bremser
Super User

The functions will work on UNIX, but you would need to specify at least APPEND mode for FOPEN/MOPEN to force an error if the file is opened by another process.

 

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

Register now!

How to Concatenate Values

Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

Find more tutorials on the SAS Users YouTube channel.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 4 replies
  • 1380 views
  • 0 likes
  • 3 in conversation