Announcement

Collapse
No announcement yet.

Files are in use

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Files are in use

    Good Morning,

    The folder contains a lot of EXE files.

    How do I know if one or more files are in use?

    I need something like this...
    Test = File.IsInUse(_WindowsFolder.."\\*.exe");

    Thanks

  • #2
    The action File.IsInUse() does already exist and checks if a file is open or running. I don't understand your question, please elaborate...

    Ulrich

    Comment


    • #3
      Ulrich,

      Yes, but is only for a single file, not for multiple files.

      Will work if I use -> C:\File.txt
      Will not work if I use -> C:\*.txt

      Thanks

      Comment


      • #4
        You would use File.Find() to get a list of all files in the desired location, and then loop over the table of results, performing the File.IsInUse() on each of the files.

        Ulrich

        Comment


        • #5
          Hi Ulrich,

          Thanks for the information.

          Do you have an example?

          Comment


          • #6
            This should give you an idea:
            Code:
            [COLOR="#0000FF"]local[/COLOR] tLocked [COLOR="#FF0000"]=[/COLOR] [COLOR="#FF0000"]{};[/COLOR]
            
            [COLOR="#0000FF"]function[/COLOR] CheckFileInUse(sFilePath)
              [COLOR="#0000FF"]if[/COLOR] File[COLOR="#FF0000"].[/COLOR]IsInUse(sFilePath) [COLOR="#0000FF"]then[/COLOR]
                Table[COLOR="#FF0000"].[/COLOR]Insert(tLocked[COLOR="#FF0000"],[/COLOR] [COLOR="#FF0000"]#[/COLOR]tLocked+[COLOR="#000000"]1[/COLOR][COLOR="#FF0000"],[/COLOR] sFilePath)[COLOR="#FF0000"];[/COLOR]
              [COLOR="#0000FF"]end[/COLOR]
              [COLOR="#0000FF"]return[/COLOR] [COLOR="#0000FF"]true[/COLOR][COLOR="#FF0000"];[/COLOR]
            [COLOR="#0000FF"]end[/COLOR]
            
            [COLOR="#008000"]-- perform search[/COLOR]
            StatusDlg[COLOR="#FF0000"].[/COLOR]Show()[COLOR="#FF0000"];[/COLOR]
            StatusDlg[COLOR="#FF0000"].[/COLOR]SetAutoSize([COLOR="#0000FF"]true[/COLOR])[COLOR="#FF0000"];[/COLOR]
            StatusDlg[COLOR="#FF0000"].[/COLOR]ShowCancelButton([COLOR="#0000FF"]false[/COLOR])[COLOR="#FF0000"];[/COLOR]
            StatusDlg[COLOR="#FF0000"].[/COLOR]ShowProgressMeter([COLOR="#0000FF"]false[/COLOR])[COLOR="#FF0000"];[/COLOR]
            File[COLOR="#FF0000"].[/COLOR]Find(_SourceFolder[COLOR="#FF0000"],[/COLOR] [COLOR="#800080"]"*.exe"[/COLOR][COLOR="#FF0000"],[/COLOR] [COLOR="#0000FF"]true[/COLOR][COLOR="#FF0000"],[/COLOR] [COLOR="#0000FF"]false[/COLOR][COLOR="#FF0000"],[/COLOR] [COLOR="#0000FF"]nil[/COLOR][COLOR="#FF0000"],[/COLOR] CheckFileInUse)[COLOR="#FF0000"];[/COLOR]
            StatusDlg[COLOR="#FF0000"].[/COLOR]Hide()[COLOR="#FF0000"];[/COLOR]
            
            [COLOR="#008000"]-- show results[/COLOR]
            Debug[COLOR="#FF0000"].[/COLOR]ShowWindow()[COLOR="#FF0000"];[/COLOR]
            Debug[COLOR="#FF0000"].[/COLOR]Print([COLOR="#FF0000"]#[/COLOR]tLocked [COLOR="#FF0000"]..[/COLOR] [COLOR="#800080"]" files found[COLOR="#800080"]\r[/COLOR][COLOR="#800080"]\n[/COLOR]"[/COLOR])[COLOR="#FF0000"];[/COLOR]
            [COLOR="#0000FF"]for[/COLOR] i [COLOR="#FF0000"]=[/COLOR] [COLOR="#000000"]1[/COLOR][COLOR="#FF0000"],[/COLOR] [COLOR="#FF0000"]#[/COLOR]tLocked [COLOR="#0000FF"]do[/COLOR]
              Debug[COLOR="#FF0000"].[/COLOR]Print(tLocked[COLOR="#FF0000"][[/COLOR]i[COLOR="#FF0000"]][/COLOR] [COLOR="#FF0000"]..[/COLOR] [COLOR="#800080"]"[COLOR="#800080"]\r[/COLOR][COLOR="#800080"]\n[/COLOR]"[/COLOR])[COLOR="#FF0000"];[/COLOR]
            [COLOR="#0000FF"]end[/COLOR]
            Ulrich

            Comment

            Working...
            X