Announcement

Collapse
No announcement yet.

The file is in use

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

  • The file is in use

    I keep getting this error about the file is in use by another process.

    So I made a LIST of files and am 100% sure I closed all filehandles and hDir's but still no joy.

    Any idea why the movefileex function won't work?

    Basically sizes up folders until it reaches 4.7 gigs, moves those folders into Disk1, Disk2 etc to be lined up for burning.

    Code:
    '#Register None
    #Option Version5
    #Compile Exe
    #Include "WIN32API.INC"
    Declare Function GetSizeofFolderinMB(ByVal InputDir As String) As Dword
    Declare Function ShellCopyFile(ByVal Source As String, ByVal Destination As String) As Long
    Declare Function GetLastErrorDescription( ByVal ErrorCode As Long) As String
    
    '============================================<WINMAIN>==================================================================
    Function WinMain (ByVal hInstance     As Long, _
                      ByVal hPrevInstance As Long, _
                      ByVal lpCmdLine     As Asciiz Ptr, _
                      ByVal iCmdShow      As Long) As Long
    
    
    Local f             As Asciiz * %MAX_PATH
    Local FindData      As WIN32_FIND_DATA
    Local hDir          As Long
    
    Local DiskNo        As Long 'Which DVD folder are we on.
    Local sTmp          As String
    Local FolderSize    As Quad
    Local TotalinMB     As Quad
    Local DVDSize       As Quad
    Local RootDir       As String
    Local WorkingDir    As String
    Local ErrType       As Long
    Local lResult       As Long
    Local lLoop         As Long
    
    Local OldFolderName As String
    Local NewFolderName As String
    Local DiskFolder    As String
    
    Local FolderCount           As Long
    Dim   FolderList(1 To 100)  As String
    
    DVDSize = 470000 'mb's
    RootDir = "G:\UserData\"
    
    'Read in all folders
    FindData.dwFileAttributes = %FILE_ATTRIBUTE_DIRECTORY
    f = RootDir & "\*.*" 'Read all files, filter later
    hDir = FindFirstFile(f, FindData)
    If hDir = %INVALID_HANDLE_VALUE Then
        StdOut "Unale to read directory!"
        Exit Function
    End If
    DiskNo = 1
    DiskFolder = RootDir & "Disk" & Format$(DiskNo)
    MkDir DiskFolder
    
    Do
        Select Case Left$(FindData.cFileName,1)
               Case ".","_"
                   Iterate
        End Select
        DiskFolder = RootDir & "Disk" & Format$(DiskNo) 'ie Disk1, Disk2
        If Left$(FindData.cFileName,4) = "Disk" Then Iterate 'It happens..
    
        'Get name of current directory
        WorkingDir = RootDir & FindData.cFileName
        'Get Size of current directory
        FolderSize = GetSizeofFolderinMB(ByVal WorkingDir)
        'Check foldersize against size of a DVD, 4.7GB.
        If FolderSize > DVDSize Then Iterate 'Have to do it manually for now 'ie VP30
        'Check foldersize and total MB to see if we will crest over 4.7 gb
        If TotalinMB + FolderSize < DVDSize Then 'OK to move
            TotalinMB = TotalinMB + FolderSize
        Else ' Not OK to move, create a new disk folder
            Incr DiskNo
            DiskFolder = RootDir & "Disk" & Format$(DiskNo)
            MkDir DiskFolder
            StdOut "------------------------------"
            StdOut "Disk" & Format$(DiskNo) & " size: " & Format$(TotalInMB)
            StdOut "------------------------------"
    
            TotalInMB = FolderSize 'Reset it to current size
        End If
        OldFolderName = WorkingDir
        NewFolderName = RootDir & DiskFolder & "\" & FindData.cFileName
    
        Incr FolderCount
        FolderList(FolderCount) = OldFolderName & "|" & NewFolderName
    
    Loop While FindNextFile(hDir, FindData)
    FindClose hDir
    
    'Now we have total file sizes, need to create new folders and MOVE folders to fill up to 4.7gb
    
    For lLoop = 1 To FolderCount
        OldFolderName = Parse$(FolderList(lLoop),"|",1) & Chr$(0)
        NewFolderName = Parse$(FolderList(lLoop),"|",-1) & Chr$(0) & Chr$(0)
        StdOut "Moving " & OldFolderName & " to " & NewFolderName
    '    lResult = ShellCopyFile(ByVal OldFolderName,ByVal NewFolderName) 'This will allow copying folders
        lResult = MoveFileEx(ByVal StrPtr(OldFolderName), ByVal StrPtr(NewFolderName), ByVal %MOVEFILE_WRITE_THROUGH)
        'If the function fails, the return value is zero
        If IsFalse lResult Then
            ErrType = GetLastError()
            StdOut "There has been an error: " & Format$(ErrType) & " - " & GetLastErrorDescription(ErrType)
        End If
    Next
    
    End Function
    '---------------------------------------------------------------------------------
    Function GetSizeofFolderinMB(ByVal InputDir As String) As Dword
    Local hDir        As Long
    Local FolderSize  As Quad
    Local f           As Asciiz * %MAX_PATH
    Local FindData    As WIN32_FIND_DATA
    
    Local Quadrafrier As Quad
    
    Quadrafrier = %MAXDWORD+1
    
    ChDir InputDir
    FindData.dwFileAttributes = %FILE_ATTRIBUTE_DIRECTORY
    f = "*.*" 'Read all files, filter later
    hDir = FindFirstFile(f, FindData)
    If hDir = %INVALID_HANDLE_VALUE Then
        Function = -1
        Exit Function
    Else
        FolderSize = (FindData.nFileSizeHigh * (Quadrafrier)) + FindData.nFileSizeLow
    End If
    
    Do
        FolderSize = FolderSize + (FindData.nFileSizeHigh * (Quadrafrier)) + FindData.nFileSizeLow
    Loop While FindNextFile(hDir, FindData)
    FindClose hDir
    Function = (FolderSize/1074)
    End Function
    '------------------------------------------------------------------------------------------
    '¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤
    'Copy file routine, using shell function (with dialog)
    'Returns zero if successful, or nonzero otherwise.
    'With two exceptions, you cannot use SHFileOperation to move special folders
    'from a local drive to a remote computer by specifying a network path.
    '--------------------------------------------------------------------
    Function ShellCopyFile(ByVal Source As String, ByVal Destination As String) As Long
      Local lResult     As Long
      Local shfos       As SHFILEOPSTRUCT
      Local ErrType     As Long
      Local ErMsg       As String
    
      'wFlags = %FOF_NOCONFIRMMKDIR Or %FOF_NOCONFIRMATION
      shfos.hwnd    = %HWND_DESKTOP
      shfos.wFunc   = %FO_MOVE
      shfos.pFrom   = StrPtr(Source)
      shfos.pTo     = StrPtr(Destination)
      shfos.fFlags  = %FOF_NOCONFIRMMKDIR Or %FOF_NOCONFIRMATION Or %FOF_SILENT Or %FOF_WANTNUKEWARNING
      lResult = SHFileOperation(shfos)
    
    
      If lResult <> %ERROR_SUCCESS Or shfos.fAnyOperationsAborted <> 0 Then
         'user aborted, do whatever is needed..
         ErrType = GetLastError()
         If ErrType <> %ERROR_SUCCESS Then
             ErMsg = "There has been an error: " & Format$(ErrType) & " - " & GetLastErrorDescription(ErrType)
             MessageBox ByVal %HWND_DESKTOP, ByVal StrPtr(ErMsg), ByVal StrPtr(Source), ByVal %MB_ICONWARNING
         End If
      End If
      SHFreeNameMappings shfos.hNameMappings
      Function = lResult
    End Function
    '------------------------------------------------------------------------------------------
    Function GetLastErrorDescription( ByVal ErrorCode As Long) As String
    Dim sRtrnCode   As Asciiz * 256
    Dim lRet        As Long
    If ErrorCode = %ERROR_SUCCESS Then Exit Function
    lRet = FormatMessage( %FORMAT_MESSAGE_FROM_SYSTEM, _
                        ByVal 0&, _
                        ErrorCode, _
                        ByVal 0&, _
                        sRtrnCode, _
                        SizeOf( sRtrnCode ), _
                        ByVal 0& )
    
    If lRet > 0 Then Function = Left$( sRtrnCode, lRet )
    End Function
    
    '---------------------------------------------------------------------------------
    '---------------------------------------------------------------------------------
    '---------------------------------------------------------------------------------
    Scott Turchin
    MCSE, MCP+I
    http://www.tngbbs.com
    ----------------------
    True Karate-do is this: that in daily life, one's mind and body be trained and developed in a spirit of humility; and that in critical times, one be devoted utterly to the cause of justice. -Gichin Funakoshi

  • #2
    Could there be a malware scanner (AV, AdWare) involved, which keeps the files open after you touched them?

    Comment


    • #3
      Scotty try using Process Explorer to search through the open handles for the locked file just to make sure that all open handles to it are indeed closed
      -

      Comment


      • #4
        pTo and pFrom members of SHFILEOPSTRUCT must be double-null terminated. This drove me nuts once.

        If you don't explicitly append a $NUL, the resulting buffer will be only single-null terminated if that name has a LEN of exactly (string allocation size) - 1

        That does not explain this particular error message, but it is something which will bite you in an area of soft tissue sooner or later.
        Michael Mattias
        Tal Systems Inc. (retired)
        Racine WI USA
        [email protected]
        http://www.talsystems.com

        Comment


        • #5
          Michael - I've never double null'd that but I too read up on that yesterday at MSN - and I'd rather use that function than the movefileex but neither are working...

          I'll check that out when I get to work, just up drinking coffee early this morning

          Tx guys!
          Scott Turchin
          MCSE, MCP+I
          http://www.tngbbs.com
          ----------------------
          True Karate-do is this: that in daily life, one's mind and body be trained and developed in a spirit of humility; and that in critical times, one be devoted utterly to the cause of justice. -Gichin Funakoshi

          Comment


          • #6
            The thing is, that error message suggests it's not some kind of leak in your program which is the problem.. it's some other program which is using that file, meaning SHFileOperation can't delete the file from present location because of that.

            But that double-null thing has got to be addressed in any case. Talk about an obscure data condition difficult to recreate! IIRC, the error you get is the Windows' equivalent of BASIC's "Error 5 (illegal function call)"... "The parameter is invalid."
            Michael Mattias
            Tal Systems Inc. (retired)
            Racine WI USA
            [email protected]
            http://www.talsystems.com

            Comment


            • #7
              FWIW, from the Inno Setup newsgroup a couple of days ago...


              >[name redacted] wrote:
              > Some installers resolve the "locked file" problem by displaying the name
              > of the program that has the file opened and prompting the user to
              > terminate that program before continuing the setup.
              >
              > It would be really great to have that feature in Inno Setup as well...

              Like this?
              http://www.vincenzo.net/isxkb/index...._use_extension
              I went to the referenced page and it looks like simply a function in a DLL one can call to get the name of the 'current user(s?) of file <filename>.'

              Unfortunately, the 'download' part of the web site was broken when I tried to D/L the package.

              I was thinking, wouldn't it be cool if it IS a DLL with no special dependencies, AND whatever license restrictions exist would permit it... to just use this DLL in our PB programs?

              If I can get the package downloaded I will be looking at this closely.

              MCM
              Michael Mattias
              Tal Systems Inc. (retired)
              Racine WI USA
              [email protected]
              http://www.talsystems.com

              Comment


              • #8
                Originally posted by Michael Mattias View Post
                Unfortunately, the 'download' part of the web site was broken when I tried to D/L the package.
                Seems to works right now.
                -- The universe tends toward maximum irony. Don't push it.

                File Extension Seeker - Metasearch engine for file extensions / file types
                Online TrID file identifier | TrIDLib - Identify thousands of file formats

                Comment


                • #9
                  Well, I got the same error as yesterday "Internet Explorer is not able to open this site. The site was either not found or unavailable. Please try again later"

                  Maybe it has something to do with my system.. I got a warning from IE about downloading and I had to 'click for options' and then hit "download the file" .. at which point it gave a message re "getting info about..." followed by above.

                  If it would not be too muich trouble could you attach whatever you got to an email and send it to me please?

                  Thanks,
                  MCM
                  [email protected]
                  Michael Mattias
                  Tal Systems Inc. (retired)
                  Racine WI USA
                  [email protected]
                  http://www.talsystems.com

                  Comment


                  • #10
                    Originally posted by Michael Mattias View Post
                    If it would not be too muich trouble could you attach whatever you got to an email and send it to me please?
                    Sure, I'm sending it now!

                    Bye!
                    -- The universe tends toward maximum irony. Don't push it.

                    File Extension Seeker - Metasearch engine for file extensions / file types
                    Online TrID file identifier | TrIDLib - Identify thousands of file formats

                    Comment


                    • #11
                      Got it, thank you .. but...

                      What opens a "*.rar" file?

                      I thought WinZip would, but mine (10.0) does not.

                      I'll Google for it and probably find something quickly, but I'm not so dumb as to not ask for advice.
                      Michael Mattias
                      Tal Systems Inc. (retired)
                      Racine WI USA
                      [email protected]
                      http://www.talsystems.com

                      Comment


                      • #12
                        My File in use was NOT having a backslash and having one in the wrong place...Strange..

                        Maybe add a "/" to your URL?
                        Scott Turchin
                        MCSE, MCP+I
                        http://www.tngbbs.com
                        ----------------------
                        True Karate-do is this: that in daily life, one's mind and body be trained and developed in a spirit of humility; and that in critical times, one be devoted utterly to the cause of justice. -Gichin Funakoshi

                        Comment


                        • #13
                          Originally posted by Michael Mattias View Post
                          Got it, thank you .. but...

                          What opens a "*.rar" file?

                          I thought WinZip would, but mine (10.0) does not.
                          Rar archives are created with WinRAR.
                          Many files manager or other archiver are able to unpack Rar files too.

                          Bye!
                          -- The universe tends toward maximum irony. Don't push it.

                          File Extension Seeker - Metasearch engine for file extensions / file types
                          Online TrID file identifier | TrIDLib - Identify thousands of file formats

                          Comment


                          • #14
                            I upgraded my WinZip to 11.2, which opens the file just fine.

                            Looking at the DLL and the imports (Show exports and imports for PB/Win 6x, 7x (original by Torsten Reinow))
                            ......
                            Code:
                            [ removed Proc names and only posting library names]
                            Listing of imported functions for file D:\Utility\Inno Setup\Who is using my file\IssProc.dll
                            Run Date & Time 06-20-2008    10:48:36
                            
                            COMCTL32.DLL
                            GDI32.dll
                            VERSION.dll
                            ADVAPI32.DLL
                            KERNEL32.dll
                            msvcrt.dll
                            SHELL32.DLL
                            USER32.dll
                                    END OF REPORT    138  items printed
                            ... there's nothing special vis a vis dependencies, except for the required INI file.

                            I think I can set this up using PB to work essentially as a 'one call' function returning TRUE (module in use) or FALSE (it ain't).

                            NOTE: This software does NOT show "who" it shows "what program" is using the 'module of interest.'

                            But the screen is really cool. Can I attach the GIF file here?

                            Hmm, I guess I CAN add the GIF file. Cool.

                            To answer the question... yes you can change the text which appears via that ini file. It also looks like you can bypass the screen completely and get back a simple TRUE or FALSE, "module of interest in use"



                            MCM
                            Attached Files
                            Last edited by Michael Mattias; 20 Jun 2008, 11:03 AM.
                            Michael Mattias
                            Tal Systems Inc. (retired)
                            Racine WI USA
                            [email protected]
                            http://www.talsystems.com

                            Comment

                            Working...
                            X