locked
Forcefully close opened files RRS feed

  • Question

  • Hello,

    I am interested in checking a specific network location for Excel files. Those file have a mask like part1_part2_part3.xlsx. I need to make sure that none of the files matching that mask are opened. If they one or more are opened by a user/process/application, I need to forcefully shut down the connection/remove the file, so that I am able to overwrite it.

    Can anyone chime in on how I may achieve such result?

    Thank you

    Wednesday, June 29, 2016 12:45 PM

Answers

  • You would need to hire a consultant to help you design a solution.  There is no script command to do this and any script that might do this would be very technical.

    You can also just set the security to block all access to the file.

    On a server you might be able to set a file filter. That is a question for another forum.


    \_(ツ)_/

    Wednesday, June 29, 2016 1:07 PM

All replies

  • Google is your friend, try the following script which I got from http://stackoverflow.com/questions/14672479/how-do-i-close-all-open-network-files-in-powershell

    $results = net file | Select-String -SimpleMatch "C:\Apps\"
    foreach ($result in $results) {
        #Get id
        $id = $result.Line.Split(" ")[0]
    
        #Close file
        net file $id /close
    
    }


    If you find that my post has answered your question, please mark it as the answer. If you find my post to be helpful in anyway, please click vote as helpful.

    Wednesday, June 29, 2016 1:05 PM
  • You would need to hire a consultant to help you design a solution.  There is no script command to do this and any script that might do this would be very technical.

    You can also just set the security to block all access to the file.

    On a server you might be able to set a file filter. That is a question for another forum.


    \_(ツ)_/

    Wednesday, June 29, 2016 1:07 PM