Is there a proper way to rename a directory? I tried using renamefile() but it failed to rename...
(if it matters, I'm on windows, and I suppose I could use movefile_() but I'm trying to keep it cross platform)
remame directory?
Re: remame directory?
the PB helpfile for RenameFile says "This function can also be used to rename/move directories" so it should be fine, so retest your code (feel free to post example!)
- make sure you didn't have any Explorer or command prompt or other programs with an open handle to that directory (use Process Explorer to do a Handle Search to confirm the directory isn't open)
- make sure the directory you're renaming to doesn't already exist
- make sure it doesn't contain invalid cars like /\:*?"<>|
- make sure permissions and attributes are ok
You can also try getting the error and checking MSDN:
- make sure you didn't have any Explorer or command prompt or other programs with an open handle to that directory (use Process Explorer to do a Handle Search to confirm the directory isn't open)
- make sure the directory you're renaming to doesn't already exist
- make sure it doesn't contain invalid cars like /\:*?"<>|
- make sure permissions and attributes are ok
You can also try getting the error and checking MSDN:
Code: Select all
SetLastError_(0)
RenameFile("doesntexist","doesntexistb")
rc = GetLastError_()
Last edited by Keya on Fri Jan 27, 2017 8:48 am, edited 8 times in total.
Re: remame directory?
That works !
If not, there is a problem with the permissions ... or the name is already in that directory...
If not, there is a problem with the permissions ... or the name is already in that directory...
Re: remame directory?
Code: Select all
#folder = "f:\test\test .me" ; f is a fat32 formatted disk, so permissions are NOT the issue.
#target = "f:\test\test.me"
If CreateDirectory(#folder)
Debug "Folder created"
Else
Debug "Failed to create folder: "+FileSize(#folder)
End
EndIf
Debug "Target folder? "+FileSize(#target)
If RenameFile(#folder,#target)
Debug "Folder renamed"
Else
Debug "Failed folder rename"
EndIf
Re: remame directory?
Sorry, but I tested your code on Windows XP SP3 x86 and Windows 8.1 x64 with PB 5.44 x86 and it worked without any problem. The only change I made was to change the folder path (file system NTFS):
On my Windows XP SP3 machine even your unmodified example worked without any problem (PB 5.44 x86 in ASCII and Unicode mode).
By the way, on which Windows version did you experience the problem and which PB version did you use? You should always state these infos!
Code: Select all
#folder = "C:\Temp\test .me"
#target = "C:\Temp\test.me"
By the way, on which Windows version did you experience the problem and which PB version did you use? You should always state these infos!
Last edited by Shardik on Fri Jan 27, 2017 12:47 pm, edited 1 time in total.
Re: remame directory?
Hi
Tested PB 5.51 x86 - 5.44 x86 Windows 10 x64
Tested PB 5.51 x86 - 5.44 x86 Windows 10 x64
Code: Select all
If FileSize("f:\test") = -2
CreateDirectory("f:\test\test .me")
Else
CreateDirectory("f:\test")
CreateDirectory("f:\test\test .me")
EndIf
If FileSize("f:\test\test .me") = -2
SetCurrentDirectory("f:\test")
RenameFile("test .me","test.me")
EndIf
Egypt my love