Page 1 of 1

How to RenameFile() on a readonly folder?

Posted: Sat Dec 27, 2025 10:12 am
by Randy Walker
Trying to move a file into a read only folder fails.
Trying to move a read only folder into a regular folder also.
Using RenamFile()
Do i need to remove the RO attribute first? How to do that in PB?

Re: How to RenameFile() on a readonly folder?

Posted: Sat Dec 27, 2025 10:19 am
by infratec
chmod 666 filename

Re: How to RenameFile() on a readonly folder?

Posted: Sat Dec 27, 2025 11:13 am
by infratec
Oh ... if you are using windows: :wink:

attrib -r filename

Re: How to RenameFile() on a readonly folder?

Posted: Sat Dec 27, 2025 5:04 pm
by SMaag
with PB commands
SetFileAttributes()
GetFileAttributes(Dateiname$()

Re: How to RenameFile() on a readonly folder?

Posted: Sat Dec 27, 2025 11:52 pm
by Randy Walker
SMaag wrote: Sat Dec 27, 2025 5:04 pm with PB commands
SetFileAttributes()
GetFileAttributes(Dateiname$()
THANKS smaag!!!
Exactly what the doctor ordered.

Re: How to RenameFile() on a readonly folder?

Posted: Sat Dec 27, 2025 11:55 pm
by Randy Walker
infratec wrote: Sat Dec 27, 2025 11:13 am Oh ... if you are using windows: :wink:

attrib -r filename
Yes, Windows, But SetFileAttributes() is cross platfom and more what I was hoping for. If it works as advertised.
Thanks for the reply though.

Re: How to RenameFile() on a readonly folder?

Posted: Sun Dec 28, 2025 12:12 am
by Randy Walker
I spoke too soon. As I feared The #PB_FileSystem_Normal switch does not seem to remove read only status on the folder (that I created).
I tested and #PB_FileSystem_Read Only does work but useless if I cannot remove read only first.
So, I guess I need to research this "attrib -r filename" angle a bit.

Re: How to RenameFile() on a readonly folder?

Posted: Sun Dec 28, 2025 4:14 am
by Randy Walker
Here's the problem. I cannot move the file using RenameFile() and alterative also fails.
This is my code on Windos PB v5.40 and 5.62:

Code: Select all

a$ = "C:\Accessories\3-Way_CSM\TERATERM.INI"
b$ = "C:\Users\Owner\AppData\Roaming\teraterm5\TERATERM.INI"
Debug a$
Debug b$
If RenameFile(a$,b$) = 0 ; I wanted this to work, but tied to simulate when it failed
If CopyFile(a$,b$)
  Debug "This Works"
  Delay(1500)
  If DeleteFile(a$) ; Also fails
    Debug "This fails"
EndIf
EndIf
Debug "done"
I thought it was a read Only on both folders at first BUT!!! move Command on a terminal window works fine, so I am reduced to creating a bat file to execute the move, and the delete the bat file which doesn't seem to have any problem. Just a lot of gyrations because RenameFile fails,

Re: How to RenameFile() on a readonly folder?

Posted: Sun Dec 28, 2025 4:19 am
by Randy Walker
infratec wrote: Sat Dec 27, 2025 11:13 am Oh ... if you are using windows: :wink:

attrib -r filename
After researching ATTRIB command I discovered Windows does not regard the Read Only attribute on folders so that wasn't the issue at all. It's just a matter of RenameFile() not working, at least not in PB5,40 or 5.62.