Database has "locked" added to its name after fileerase doesn't delete it

I have several databases, SubDiv01, SubDiv02, etc, which are deleted successively with the fileerase statement - this is the code:

;  A procedure to merge the subdivided files and to delete the parts as they are joined.

OpenFile "SubDiv 01"
window FileName1
deleteall
importdatabase "SubDiv 01"
fileerase "SubDiv 01.pandb"

I = 2
Loop
    openfile "SubDiv " + pattern(I,"##")
    window FileName1
    importdatabase "SubDiv " + pattern(I,"##")
    window "SubDiv " + pattern(I,"##")
    closefile
    
    fileerase "SubDiv " + pattern(I,"##") + ".pandb"
    SelectAll

    I=I+1
Until I > NumParts

The SubDiv01 file is not deleted and its name has “locked” added to it:

35%20pm

I can close it manually. Why is this happening?