Unable to delete excel file from current directory: WindowsError: [Error 32] The process cannot access the file because it is being used by another process:

325 views
Skip to first unread message

Sandeep Pendyala

unread,
Mar 29, 2018, 12:38:59 PM3/29/18
to robotframework-users
Hi all

I'm validating excel files in Robot Framework. Every time I validate, I delete the recent file from current directory using Remove File keyword
So that new file with same name can accommodate in the folder. Some of them are deleting and some are not and throwing the above error.
some one please help, thanks in advance.!


Regards,
Sandeep

adam.wyp...@gmail.com

unread,
Mar 29, 2018, 1:09:22 PM3/29/18
to robotframework-users
Hi Sandeep,

Did you try to check what process is locking your excel file? If not, maybe will be worth to check it using some external application like i.e. unlocker.

Best Regards,
-Adam.

Sandeep Pendyala

unread,
Mar 29, 2018, 2:00:59 PM3/29/18
to robotframework-users
I used unlocker. It is locked by python.exe

Path: C:\Python27\python.exe

It is locked by python until the test is finished.

Regards,
Sandeep

spendya

unread,
Mar 30, 2018, 9:48:23 AM3/30/18
to robotframework-users
Hi,

Can anyone please help me with this issue, I need a way to close connection with my excel file. So that I can delete it after the test finishes. (I'm running bunch of excel tests in a suite)
Currently I'm using EXCEL Library. It don't have any keywords to close connection.

Regards,
Sandeep

Kevin O.

unread,
Mar 30, 2018, 11:20:24 AM3/30/18
to robotframework-users
Hmmm...
assuming you are working with robotframework-excellibrary
That library is global in scope and looking at the code it will not let go of the file until you open a new workbook.
My first suggestion would be to either put the files in unique folders or stop trying to use the same file name over and over (e.g. work on a copy).
Reload Library in BuiltIn is no help here because it doesn't fully reload the library.

If you are too stubborn to do change how you store the file, than there is always another way ;)
You can re-initialize the state, freeing up the file by:
    ${lib}    Get Library Instance    ExcelLibrary
    Call Method    ${lib}    __init__

This is a dirty hack, but it as clean as a dirty hack I can think of.
The file should be released shortly after (garbage collection needs to run). So you should retry Delete File with Wait Until Keyword Succeeds a couple of times.

spendya

unread,
Apr 3, 2018, 2:49:55 PM4/3/18
to robotframework-users
Thanks Kevin. I tried your 2nd option but it doesn't worked for me
        So, I renaming my file names and test suite is not breaking.


Regards,
Sandeep 

adam.wyp...@gmail.com

unread,
Apr 4, 2018, 2:46:21 AM4/4/18
to robotframework-users
You can try following code:

*** Settings ***
Library    ExcelLibrary
Library    OperatingSystem


*** Test Cases ***
Test
   
#${excel_filename}    Set Variable    b.xlsx
    $
{excel_filename}    Set Variable    b.xls
   
Copy File    temp${/}${excel_filename}    .
   
Open Excel Current Directory    ${excel_filename}    
    $
{lib}    Get Library Instance    ExcelLibrary
   
Call Method    ${lib.wb}    release_resources
   
Remove File    ${excel_filename}

The biggest problem of ExcelLibrary is that nobody is currently actively develop it.

Regards,
-Adam.
Reply all
Reply to author
Forward
0 new messages