I noticed a while ago that in case I am trying to rename a folder that is currently open in Windows Explorer, the operation sometimes fails. In order to try and figure out what is happening, I created a small script that uses the LockesList plugin (to see if anything is really locked):
I also have the following folder structure:Name `LockedList Test`
OutFile LockedListTest.exe
RequestExecutionLevel admin
!define origFolder "C:\Program Files (x86)\Original"
!define newFolder "C:\Program Files (x86)\Original_Renamed"
Page Custom LockedListShow
Page instfiles
Function LockedListShow
LockedList::AddFolder "${origFolder}"
LockedList:😁ialog /autonext /searching "Searching for locked files in ${origFolder}"
Pop $R0
MessageBox MB_OK "$R0"
FunctionEnd
Function renameFolder
ClearErrors
MessageBox MB_OK "Renaming ${origFolder} to ${newFolder}"
Rename "${origFolder}" "${newFolder}"
IfErrors 0 done
MessageBox MB_OK "Failed to rename"
done:
ClearErrors
FunctionEnd
Section
Call renameFolder
SectionEnd
\Original
\config
\test.txt
I then execute LockedList.exe in different scenarios.
- All Windows Explorer windows closed
- Windows Explorer open with folder "Original" displayed
- Notepad open with Test.txt
- Windows Explorer open with folder Original\config displayed
Here are the results:
Case 1: LockedList returns "next" as no locks found, folder is renamed
Case 2: LockedList returns "next" as no locks found, folder is renamed
Case 3: LockedList displays Notepad.exe as a lock. I close it and it then returns "next". Rename failes (as folder Original\config displayed in Windows Explorer - since I opened the txt file)
Case 4: LockedList returns "next" as no locks found, rename failes.
Now I found this a bit "weird". Rename works ok if only the folder to be renamed is displayed in Windows Explorer but fails as soon as any subfolders thereof are displayed. Also, LockedList finds no locks and manual renaming also works.
Any idea why this might happen?
Thanks,
Mircea