Do not continue until a file exists in powershell

Hi,
I was wondering if there is a method in powershell to get it to 
continually check whether a file exists and do not progress until it finds it.
i.e
DO WHILE  
c:\flag.txt NOT EXISTS
Wait 10 seconds
END
<Next command >
So that the <next Command> section is only executed once it finds the file c:\flag.txt
Is this possible?
Thanks,
Zoe

I doubt that it would have been very helpful anyway.  The requirement was
"check whether a file exists and
do not progress until it finds it"
so blocking is exactly what's called for.  Putting it into a background job is probably just going to trade checking of the file status for checking on the job status.
[string](0..33|%{[char][int](46+("686552495351636652556262185355647068516270555358646562655775 0645570").substring(($_*2),2))})-replace " "
My post was very helpful, indeed.
Blocking any instance of an application (PowerShell in this case) is almost always a very bad decision (*) because it blocks the UI.
Do you understand that a UI, when blocked cannot process any other command from user, just because the UI is blocked?
( Alright, Ctrl+Break can stop the process, and the terminate the PowerShell session too! )
Your argumentation is proper of a non-programmer.
Imagine the situation: you, the user, has a powerful computer at your finger tips, with last generation of MS server, which is running your smart PS script that's blocking (how many hours for?) your PS instance. In this case, you don't need a powerful computer,
what you need is a better PowerShell scripter.
Haven't heard of Star-Job?
Spend sometime reading about it, it's worth the reading.
( Alright, your mvp friend seems never heard of it, when I look at the crap code he did using Star-Job in another thread. )
The solution is very simple: Start a job to wait for whatever have to be waited; then, keep using the PS instance
normally, and check once or another if the job is completed (or use another sync mechanism).
This is smart!
Blocking the UI is since ever, not smart.
(*) except very specific situations; fortunately, current computers are preemptively multitask.
I understand it blocks the UI, but we don't have any indication in the question that this is going to be used in an interactive session or that the OP doesn't know about background jobs.  If it's going to have to monitor/wait for an extended period
of time it could well be being implemented as a scheduled task or job, or even as a persistent job.  No matter what the session environment is, some solution for implementing that blocking behavior will be needed to satisfy the stated requirements, and
the posted solution will do that.
The assumption is that the OP isn't smart enough to figure out or experienced enough to know that what they're asking for will block their interactive session while it waits for the file.  I don't see anything in the question to warrant that assumption. 
If it's going to have to wait an arbitrarily long time, a permanent registered event might be a better solution than the time loop.
[string](0..33|%{[char][int](46+("686552495351636652556262185355647068516270555358646562655775 0645570").substring(($_*2),2))})-replace " "

Similar Messages

  • Is there any way to not wait for a subVI to output so that the background loop can continue (until the output exists)?

    hello everyone,
    I am in a loop but want to modify an element in that loop. This modification takes time, but i cannot have the loop stop while it is being changed or else the buffer overflows and crashes the computer.
    Is there any way to make the output null until the subVI finishes and actually gives the desired output? This way the loop could continue until the subVI's output is ready.

    Inside the subVI, you can set a condition, for example, if data is not given, set the output to some kind of value (NaN is good for numeric), if data is present, just take it out. But be sure the subVI has no loop to get data, but check data only once. If you need a loop to get data, you'll have to put it in paralell with the main loop.
    Hope this helps

  • TS4433 After 30 chapters in each book of Game of Thrones e-book the iPod sound chatters, dithers and will not continue.  Same files on computer or other device have no issues.

    After 30 chapters in each book of Game of Thrones audio book, the iPod audio dithers, chatters and will not proceed.  The same files work in other devices and computers.

    A bit confused by your statement
    bcboarder wrote:
    . I do not understand why the music is clearly on the Ipod but wont reconize it anywhere.
    Are you seeing your music listed in the iPod screen, or in Win explorer as in your earlier post?
    I can see all the songs in my Edrive>al's Ipod> Ipod Control> Music folder.
    A corrupted iPod database, will report zero music used, and have your music size reported as others, so you wont see the music in the iPod screen. Sorry, I thought there was some hope for you with iPodAccess, in recovery of the corrupted iPod database with your ratings.
    You can try to borrow and  use the Mac Disk Utility ->First Aid ->Repair.
    Of course, if your iPod Hardisk is in a bad state, from the Disk Diagnostic report, then all my suggestion are futile.

  • APP-PER-07510 You Can not continue,Future Changes Exists.(Purchasing Employee Window while updating  Location)

    In above mention error i followed this metalink doc
    Error Updating Employee Record In Shared HR Environment APP-PER-07510 You can not continue. Future events
    exist (Doc ID 1483127.1)
    Kindly verify that whether i m going in Right direction or not.
    If its a right solution then i get this error while applying the patch mention in Doc.
    AutoPatch warning:
    Product Data File
    /Data/u01/prodappl/prod/apps/apps_st/appl/admin/zfaprod.txt
    does not exist for product "zfa".
    This product is registered in the database but the
    above file does not exist in APPL_TOP.  The product
    will be ignored without error.
    Kindly help its Urgent.
    Thanks,
    Harvir

    Hi Harvir,
    Apologies for my previous reply. Please disregard the previous reply as I have wrongly replied to your thread
    Anyhow you can safely ignore the error warning message, and let us know whether your issue is solved after patch application..
    Please see note:
    Product Data File Error Applying Patch 4440000 (Doc ID 421136.1)
    Thanks &
    Best Regards

  • SQL Server not Starting Up - Could not open error log file system error = 5(Access is denied.)

    Hi guys,
     I am working on issue with SQL Server 2008 R2 .. we rebooted the server and after that all SQL services is not coming up. below is the error from eventlog...
    SQL Server running under NetworkService account and has full control on this files..
    from Config Manager ....
    The request failed or the service did not respond in a timely fashion....
    From Event log..
    initerrlog: Could not open error log file 'C:\Program Files\Microsoft SQL Server\MSSQL10_50.MSSQLSERVER\MSSQL\Log\ERRORLOG'. Operating system error = 5(Access is denied.).
    Any idea or workaround..?
    Thanks..
    Please Mark As Answer if it is helpful. \\Aim To Inspire Rather to Teach

    Finally I found solution and was able to bring back online the SQL Services...
    I had a very similar issue with the following error (event log):
    Description:
    The SQL Server (MSSQLSERVER) service terminated with service-specific error 17058 (0x42A2).
    For more information, see Help and Support Center at http://go.microsoft.com/fwlink/events.asp.
    Event Type:      Error
    Event Source:      MSSQLSERVER
    Event Category:      (2)
    Event ID:      17058
    Date:            19/05/2012
    Time:            10:20:14
    User:            N/A
    Computer:      NSQLXX
    Description:
    initerrlog: Could not open error log file 'C:\Program Files\Microsoft SQL Server\MSSQL.1\MSSQL\LOG\ERRORLOG'.
    Operating system error = 5(error not found).
    In this case the ERRORLOG file had been marked as read only. This was following a scheduled automated boot.  -This
    was culprit
    MSSQL wouldn't not start until this file had been changed.
    http://www.experts-exchange.com/Database/MS-SQL-Server/Q_23951723.html
    Thanks everyone for your kind replies and time...
    Please Mark As Answer if it is helpful. \\Aim To Inspire Rather to Teach

  • How to remove preinstalled files of adobe photoshop from my mac mini so that i can install a new version of the same software.The previous version was removed using the app cleaner software.Could not continue installation bcoz of earlier files

    How to remove preinstalled files of adobe photoshop from my mac mini so that i can install a new version of the same software.The previous version was removed using the app cleaner software.Could not continue installation of the new version because of the existance of files from the previous version.plz help

    What "app cleaner software" ? I ask because installing Photoshop over a previous version has never been a problem. Perhaps your difficulty stems from another source, eg. "cleaner software" ?
    If you look in your hard drive, at the root level there is a Library. In there is a folder called Application Support, and in that you will find a folder called Adobe. Files from your previous version are there.
    However, I urge you to call Adobe support to make sure you are not doing anything that would mess up other Adobe applications.
    http://www.adobe.com/support/connect/connecthostedsupport.html

  • File.exists() is not accurate on smb2 network share (use WatchService?)

    Hi,
    According to this document: SMB2 Client Redirector Caches Explained File.exists() is not accurate on a smb2 network share. I am not able to change any register settings, so I want to deal with it. According to the document there is an API to get the notifications from the file system. I assumed that the WatchService is the Java implementation of this API. Am I correct?
    I started with the WatchDir example from the jdk samples and stripped it a bit. I only need to know when a file is created and delete (I don't care about file modifications). For testing I have added new File.exists() when a new event has been triggered. I also start a separated Thread which test the file existence also. When I don't start this separated thread the file exists returns true immediately. When the extra thread is started it is not accurate any more. I need a more accurate file.exists check in the whole application and all running threads.
    The output for my test case is this:
    FileExistsThread: subdir\test.txt == false
    watch registered for dir: subdir\
    FileExistsThread: subdir\test.txt == false
    FileExistsThread: subdir\test.txt == false
    FileExistsThread: subdir\test.txt == false
    FileExistsThread: subdir\test.txt == false
    FileExistsThread: subdir\test.txt == false
    FileExistsThread: subdir\test.txt == false
    WatchDir event: ENTRY_CREATE: test.txt
    WatchDir: subdir\test.txt exists == false
    FileExistsThread: subdir\test.txt == false
    FileExistsThread: subdir\test.txt == false
    FileExistsThread: subdir\test.txt == false
    FileExistsThread: subdir\test.txt == false
    FileExistsThread: subdir\test.txt == false
    FileExistsThread: subdir\test.txt == false
    FileExistsThread: subdir\test.txt == false
    FileExistsThread: subdir\test.txt == false
    FileExistsThread: subdir\test.txt == false
    FileExistsThread: subdir\test.txt == true
    FileExistsThread: subdir\test.txt == true
    FileExistsThread: subdir\test.txt == true
    FileExistsThread: subdir\test.txt == true
    As you can see the file test.txt  is created on line 9. The FileExistsThread have seen it on line 20, (at least 10 x 300 ms later).
    For testing I have used 2 Windows 7 pc's (with smb2 enabled which is default). The working directory must be on the remote pc and the file test.txt must be created (or copied from another folder) on the remote pc (not using the network drive, but on the pc itself).
    Here is my test code:
    package nl.test.main;
    import static java.nio.file.StandardWatchEventKinds.ENTRY_CREATE;
    import static java.nio.file.StandardWatchEventKinds.ENTRY_DELETE;
    import static java.nio.file.StandardWatchEventKinds.OVERFLOW;
    import java.io.File;
    import java.io.IOException;
    import java.nio.file.ClosedWatchServiceException;
    import java.nio.file.FileSystems;
    import java.nio.file.Path;
    import java.nio.file.Paths;
    import java.nio.file.WatchEvent;
    import java.nio.file.WatchKey;
    import java.nio.file.WatchService;
    public class WatchDir
      private final WatchService _watcher;
      private final String _dir;
      public WatchDir( String dir ) throws IOException
        _dir = dir;
        _watcher = FileSystems.getDefault().newWatchService();
        Paths.get( dir ).register( _watcher, ENTRY_CREATE, ENTRY_DELETE );
        System.out.println( "watch registered for dir: " + dir );
      public void run()
        try
          while ( true )
            WatchKey key = _watcher.take();
            for ( WatchEvent<?> event : key.pollEvents() )
              WatchEvent.Kind<?> kind = event.kind();
              if ( kind == OVERFLOW )
                continue;
              @SuppressWarnings( "unchecked" )
              WatchEvent<Path> ev = (WatchEvent<Path>)event;
              Path fileName = ev.context();
              System.out.println( "WatchDir event: " + kind.name() + ": " + fileName );
              if ( kind == ENTRY_CREATE )
                String realPath = _dir + fileName;
                System.out.println( "WatchDir: " + realPath + " exists == " + new File( realPath ).exists() );
            key.reset();
        catch ( ClosedWatchServiceException x )
          return;
        catch ( InterruptedException ex )
          return;
      public static void main( String[] args )
        Thread t = new Thread( new Runnable()
          @Override
          public void run()
            try
              while ( true )
                String filename = "subdir\\test.txt";
                boolean fileExists = new File( filename ).exists();
                System.err.println( "FileExistsThread: " + filename + " == " + fileExists );
                Thread.sleep( 300 );
            catch ( InterruptedException e )
              e.printStackTrace();
              return;
        t.start();
        try
          new WatchDir( "subdir\\" ).run();
        catch ( IOException e )
          e.printStackTrace();
    Any idea's?
    Thanks,
    Olaf

    If you donot have access to note 45172.1 as specified by Laurent Schneider.
    Snippet from note
    a. Mapped Drive : To use a mapped drive, the user that the service starts as
    must have setup a drive to match UTL_FILE_DIR and be logged onto the server
    when UTL_FILE is in use.
    b. Universal Naming Convention : UNC is preferable to Mapped Drives because
    it does not require anyone to be logged on and UTL_FILE_DIR should be set to
    a name in the form :
    \\\<machine name>\<share name>\<path>
    or
    "\\<machine name>\<share name>\<path>"

  • File exist/file not exist

    OK, i create a directory i have read/write permissions on the directory, but still even if the file exists its bringing back the result as if it doesnt i need help with this...
    set serveroutput on
    DECLARE
    fexists    BOOLEAN;
    flen  NUMBER;
    bsize NUMBER;
    BEGIN
    sys.utl_file.fgetattr('TMP_LOCATION', 'test.txt', fexists, flen, bsize);
      IF fexists THEN
        dbms_output.put_line('File Exists');
      ELSE
        dbms_output.put_line('File Does Not Exist');
      END IF;
      dbms_output.put_line('File Length: ' || TO_CHAR(flen));
      dbms_output.put_line('Block Size: ' || TO_CHAR(bsize));
    END fgetattr;
    File Does Not Existmy directory.. CREATE or replace DIRECTORY tmp_location AS 'Server-1\configsheets\completed\pdf approved'

    Good afternoon,
    If you are loooking at a mapped drive, you can only see it if you change how the Oracle services start. You need to have them start with a specific user ID rather than starting as system services. The problem is that the system services cannot see mapped drives.
    So, do this:
    <li>Create a user to be used by Oracle services. Make sure they have the correct rights (I gave mine Server ADMIN so as to have all the access I needed)
    <li>Log into the server and modify the services
    <li>Click the 'Log On' tab and enter the account and password you created for the Oracle Processes
    <li>Reboot the server, allowing the Oracle services to log in with this new ID.
    This should then fix your problem.
    Thanks,
    Don.
    REWARDS: Please remember to mark helpful or correct posts on the forum, not just for my answers but for everyone! :)

  • Checking to see if files exist not working as expected.

    Hey, so I've set up a script that determines the artist playing on iTunes and sets the background image to a preselected picture of them. I want to expand this to allow different pictures of the artists, and after a few attempts, decided to use a time based system. However, some artists have 2 images (named Artist1.jpg and Artist2.jpg), whilst others only have one (Artist.jpg). I can get the scripting right for if all artists have 2 images, yet am having problems with the system determining if certain files exist.
    who is the artist playing, and myNum is either 1 or 2, and changes based on the time, both set earlier in the script and verified to work.
    set MultiWall to ("/Users/ethan/Pictures/Music Wallpaper/" & who & myNum & ".jpg")
    set SingleWall to ("/Users/ethan/Pictures/Music Wallpaper/" & who & ".jpg")
    tell application "System Events"
                       if not (exists MultiWall) then
                                                           tell application "Finder"
                                                                          set desktop picture to file SingleWall
                                                           end tell
                       else
                                                           tell application "Finder"
                                                                          set desktop picture to file MultiWall
                                  end tell
                                            end if
    end tell
    I've tried many variations of this, from less variables to more, restructuring it and whatnot and it just isn't working for me. Thanks all.

    If you are still having difficulties you may like to try this method:
    set myPath to "/Users/neville/Desktop/test" & ".png"
    if (do shell script "/bin/test -e '" & myPath & "'; echo $?") is "0" then
      tell application "Safari" to open myPath
    end if
    It should work if you copy and paste it.
    Please note the combined single and double quotes. Don't put a space between them. You may not need the single quotes if you have control over the path. Most people would opt for 'quoted form of' but I prefer concise code.

  • I have been transfering info to an external hard drive and when I try and trash contents off my computor i get the message it will not continue with the message SUID file syst/library/coreS has been modified and will not be repaired. Hence I cannot free u

    I have been transfering photos and movies to an external hard drive and when I try and secure trash contents off my computor i get the message it will not continue In utilities  the message is: SUID file syst/library/coreS has been modified and will not be repaired. Hence I cannot free up space on my computor. What can i do?

    Do not worry. It is probably a permission you should ignore, but you should check that the permission appears in this site > http://support.apple.com/kb/TS1448?viewlocale=en_US&locale=en_US

  • I'm trying to clean up my mailbox and when I delete an item(s) I get a message that say's "operation could not be completed- file exists. Further, when I do this one message is copied (not deleted) to the trash folder. Can someone help me through this?

    I'm trying to clean my mailbox and when I click on delete or highlight and move to trash I get a message that says "operation could not be completed - file exists. Further, when I select a message or group of messages, one of them is copied (not deleted) to the trash folder. Can someone help me through this?
    Thanks.

    It's a POP account. I decided to clean up my mailbox today after noticing the computer was real slow after USA Today started sending their daily top stories with new graphics. Also before I noticed the problem with mail deletion - two things happened. 1) I updated security sofware as prompted by Apple and 2) downloaded Mackeeper and went throught some preliminary scans but did not buy their package. Thanks forn nstaying with me.

  • Cannot make a cache safe URL for "1025/styles/Themable/corev4.css", file not found. Please verify that the file exists under the layouts directory.

    HI
    i restored a sharepoint web 80 application in our test domain
    and after when i browse the new web application 
    it says 
    Cannot make a cache safe URL for "1025/styles/Themable/corev4.css", file not found. Please verify that the file exists under the layouts directory. 
    adil

    Hi  adil,
    According to your description, my understanding is that you encountered the error “Cannot make a cache safe URL for "1025/styles/Themable/corev4.css", file not found. Please verify that the file
    exists under the layouts directory.” .
    The issue happens in
    We have customized master page
    In the master page, we use path the script/style file like this: <SharePoint:CssRegistration name="<% $SPUrl:~SiteCollection/Style Library/coe/mainCOE.css%>"
    runat="server"/>
    While using the dynamic path in a multiple languages enabled site, language Id(1033 etc) will be added to the path automatically. That cause the file to be not found.
    To solve the issue, please download  the Arabic language pack http://www.microsoft.com/en-us/download/details.aspx?id=3411 ,
    install it on  your SharePoint and refresh your browser.
    Reference:
    http://sharepoint-community.net/profiles/blogs/cannot-make-a-cache-safe-url-for-1036-sytles-themable-corev4-css
    Best Regards,
    Eric
    Eric Tao
    TechNet Community Support

  • How do I determine if a file exists or not on my PC?

    I thought this would be an easy one and maybe I am just making it harder than what it has to be. I simply want to search in a given directory to see if a file exists on not on my hard drive. Are there any ideas as to how to do this without causing an error if the file does not exist?

    Hi:
    In those situations what I've done till now is opening  the file
    and  close it inmediatly, if I find out and error while opening it
    I guess it doesn't exist. I know this is not the best way since there
    may be other reasons for the Open File Function to fail, but it has
    worked for me. Does somebody know a better way to do it?
    Regards
    Robst - CLD
    Using LabVIEW since version 7.0

  • Whats the best way to check weather a file exists online, or not?

    Hi!
    I need to show an Image File in my app which may have different sizes. _1.jpg, _2.jpg and so on.. If, for example, _2.jpg does not exist, I have to take _1.jpg.
    So my question is: is there a better way instead of making/allocating a pic and asking pic != nil ?
    thx!
    alex

    Hi Alex -
    The subject line says "file exists online, or not?". Are you trying to check existence at a network site, or the local file system? I'll cover the local fs first, since that's the easiest. If you need to search a remote site, I think we'll need some more details.
    Assuming an iPhone project (not specified, but your usual topic), NSFileManager will probably be all you need unless the files are localized and/or in the application bundle, in which case you'll want NSBundle. For example, say you're storing all the jpg's in the user's cache directory:
    #define MAXFN 5
    // return nil or the path to the file with the highest numeric suffix
    - (NSString)getPathForBestFile:(NSString)baseName extension:(NSString*)ext {
    NSString *bestFilePath = nil;
    NSFileManager *fileManager = [NSFileManager defaultManager];
    // locate the user's cache directory
    NSArray *paths = NSSearchPathForDirectoriesInDomains(
    NSCachesDirectory, NSUserDomainMask, YES);
    NSString *cacheDirectory = [paths objectAtIndex:0];
    NSLog(@"cacheDirectory=%@", cacheDirectory);
    // loop through file names with numeric suffixes
    for (int i = 1; i <= MAXFN; i++) { />/
    NSString *fileName =
    [NSString stringWithFormat:@"%@_%d.%@", baseName, i, ext];
    NSString *filePath =
    [cacheDirectory stringByAppendingPathComponent: fileName];
    NSLog(@" filePath=%@", filePath);
    if ([fileManager fileExistsAtPath:filePath])
    bestFilePath = filePath;
    return bestFilePath;
    If you need to use NSBundle, see pathForResource:ofType:. If you need to determine the existence of a file at a network site, please give us some details about the kind of server and how much you'll know about the possible file locations.
    Hope that helps!
    - Ray

  • I reinstalled my OS as I do every year or so. when I install CS4 I do not have Premiere Pro Adobe Premiere Pro Error 1603. Error 1311.Source file not found: F:\Adobe CS4\payloads\AdobePremierePro4All\AdobePremierePro4All1.cab.  Verify that the file exists

    Error 1603. Error 1311.Source file not found: F:\Adobe CS4\payloads\AdobePremierePro4All\AdobePremierePro4All1.cab.  Verify that the file exists and that you can access it.

    And what exactly? You have not provided any system info or other details.
    Mylenium

Maybe you are looking for

  • Works on emulators but not on mobile devices

    Hello, My project works on emulators but not on mobile devices (no image and on Samsung it says "unsupported file"). Please help, I don't know what to do. My configurations: MIDP 2.1, CLDC 1.1. Thanks in advance. Edited by: Vitali.pom on Oct 27, 2011

  • Using MDT to re-join computers to a domain after a re-image

    Since 2010 we have been using WDS to build, capture and deploy our image across our organisation (A High School) which has worked well enough. While WDS can do all this the build and capture is a little clunky and relies on you to manually installing

  • Unable to open Facebook

    Both my Browsesr - Safari & Firefox doesn't load Facebook home page completely. I've attached screen shots from both the browser. As seen from many other dicussions I'v deleted all my cookies as well as tried reset option in both the browser. Still p

  • Activity icon always running on certain websites

    When viewing certain websites in Safari (such as AllThingsD) the Activiy icon is always spinning. If I switch to another tab, the icon will disappear after a few seconds, but will return as soon as I switch back to the offending websites. Is there so

  • Post QA Refresh Steps in an HR Environment

    Hello All I'm hoping to get some additional information on this. When the UMR is imported in post-refresh activities, this will wipe out the target system's roles/profiles/users and replace with the source system's UMR (the backup). However with HR R