Scripting Question

Find a File

09/25/2015 1111 views

Does anyone know how to script a "find a file on a computer" type script?

Basically, I was hoping to create a while statement that does one part until it no longer sees a file on the targeted machine, once the "findfile" = false then it would kick of the second part of the script.

something like:

while checkfile = false

    do this staement

    if checkfile = true

    do this statment


I have my statements and everything working... I just need something that looks at a certain file path and verifies if a file has been removed or not, then report true or false back so the next part of the program can start.

2 Comments   [ + ] Show comments


  • is this file in the always in the same location and have same name?
    • yes, the file will always be the same name and in the same location.
  • Hmm. I am not sure if this would produce the results I need.
    here is a lttle more depth to my issue.
    I am uninstalling a program on a computer. I have a statement that does that - so I am good there. I am then running a statement that installs a different program - again, I have this working as well.

    what I need though is a way to delay the install until the uninstall is completed. So I was hoping I could have a way to search for a file that exsits in program 1 (and keep searching until it can no longer be found). Once the file search returns "false" then program 2 launchs.

    I don't want the "check file" statement to actually do anything with the files, execpt see if a it is on the machine. Otherwise, it returns a value that I can then use to launch the next step.
    • are you using any kind of a management product?
      what type of script? If it is a batch script you are pushing this type of call will work as a batch script.

      start /wait call uninstall command
      start /wait call install command

      the start /wait will make sure the uninstall has run prior to starting the install
    • This content is currently hidden from public view.
      Reason: Removed by member request For more information, visit our FAQ's.

All Answers

you should be able to use an "if exists then" statement to delete the file and then call the the second part of your script.  use start /wait to keep them sequenced

start /wait if exists "file" then delete
start /wait part 2 of your script

Answered 09/25/2015 by: SMal.tmcc
Red Belt

you can use the if then else using it to call goto's

if exists filename goto DoesFileExist else goto install
Answered 09/25/2015 by: SMal.tmcc
Red Belt

This content is currently hidden from public view.
Reason: Removed by member request For more information, visit our FAQ's.

Don't be a Stranger!

Sign up today to participate, stay informed, earn points and establish a reputation for yourself!

Sign up! or login

View more:


This website uses cookies. By continuing to use this site and/or clicking the "Accept" button you are providing consent Quest Software and its affiliates do NOT sell the Personal Data you provide to us either when you register on our websites or when you do business with us. For more information about our Privacy Policy and our data protection efforts, please visit GDPR-HQ