We help IT Professionals succeed at work.

Check out our new AWS podcast with Certified Expert, Phil Phillips! Listen to "How to Execute a Seamless AWS Migration" on EE or on your favorite podcast platform. Listen Now

x

locking files in DOS

Medium Priority
481 Views
Last Modified: 2012-06-27
is it possible to do file locking using DOS commands?  namely, i am referring to a reader/writer lock.  or does it have to be using a high level language such as c, c++, c#?
Comment
Watch Question

Information Services Manager
CERTIFIED EXPERT
Commented:
Unlock this solution and get a sample of our free trial.
(No credit card required)
UNLOCK SOLUTION
Ron MalmsteadInformation Services Manager
CERTIFIED EXPERT

Commented:
Permissions change would also lock it, if the process you are locking it from is running under an account that doesn't have permissions.  So you could also use Attrib to lock it for a specific account, then change permissions back to unlock.
Steve KnightIT Consultancy
CERTIFIED EXPERT
Commented:
Unlock this solution and get a sample of our free trial.
(No credit card required)
UNLOCK SOLUTION
Steve KnightIT Consultancy
CERTIFIED EXPERT

Commented:
Was clearly a little slow typing all that lot, please clarify your purpose and can advise more.
Ron MalmsteadInformation Services Manager
CERTIFIED EXPERT

Commented:
...errr...it's been a looong day.

I said attrib, but I actually meant Calcs as dragon-it stated.


However... if this is on Windows 7...you could make the file "hidden"... and if the program is running under an account that is not creator/owner, it won't be able to "see" it.

Author

Commented:
our CTO wants to accomplish the following using a batch file (the batch file is run by a file trigger agent, e.g. when there is a file in the folder, then the batch file will run).  The aim is to encrypt and then transfer files in a specific sequence.

pseudocode:

if (LockFileIsPresent() {
      return WAITING_FOR_WRITING_TO_COMPLETE;
}

Process any files that we were in the middle of transferring when we aborted

//Process files in prefix order
while (files exist with prefix) {
      EncryptFile();

      // renaming file
      RenameAndRemovePrefixforSFTP();

      // Transfer the file
      rc = SFTP file;

      if (rc != SUCCESS) {
            return rc;
      }

      DeleteFile();
}
return SUCCESS;

i am not sure if it's possible, or even the best solution when languages such as java and c# already have locking mechanisms built-in.  but before i question his approach, i want to find out more about how feasible his solution is.
Steve KnightIT Consultancy
CERTIFIED EXPERT

Commented:
OK, forget locking then.  Best bet is to rename or move the files, i.e.

move all files to subidr "processing"
@echo off
set maindir=c:\sourcedir
set processing=%maindir%\processing
cd /d "%maindir%"
mkdir "%processing%" 2>NUL
move *.* "%processing%"

at that point only any files that weren't locked and unable to move will be moved to the processing directory.  Work on the processing directory with the next bit of your script processing all files in that dir with your encryption command.  If it needs them individually then use a for loop to read the filenames or pass the encryption command "%processing%\*.*" as the path.

Have I understood correctly there?

Steve
Steve KnightIT Consultancy
CERTIFIED EXPERT

Commented:
Thanks for the points.  What did you use in the end btw?

Steve
Unlock the solution to this question.
Thanks for using Experts Exchange.

Please provide your email to receive a sample view!

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.