How to RenameFile() on a readonly folder?

Just starting out? Need help? Post your questions and find answers here.
Randy Walker
Addict
Addict
Posts: 1203
Joined: Sun Jul 25, 2004 4:21 pm
Location: USoA
Contact:

How to RenameFile() on a readonly folder?

Post 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?
Last edited by Randy Walker on Sun Dec 28, 2025 12:07 am, edited 2 times in total.
- - - - - - - - - - - - - - - -
Randy
I *never* claimed to be a programmer.
infratec
Always Here
Always Here
Posts: 7774
Joined: Sun Sep 07, 2008 12:45 pm
Location: Germany

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

Post by infratec »

chmod 666 filename
infratec
Always Here
Always Here
Posts: 7774
Joined: Sun Sep 07, 2008 12:45 pm
Location: Germany

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

Post by infratec »

Oh ... if you are using windows: :wink:

attrib -r filename
SMaag
Enthusiast
Enthusiast
Posts: 364
Joined: Sat Jan 14, 2023 6:55 pm
Location: Bavaria/Germany

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

Post by SMaag »

with PB commands
SetFileAttributes()
GetFileAttributes(Dateiname$()
Randy Walker
Addict
Addict
Posts: 1203
Joined: Sun Jul 25, 2004 4:21 pm
Location: USoA
Contact:

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

Post 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.
- - - - - - - - - - - - - - - -
Randy
I *never* claimed to be a programmer.
Randy Walker
Addict
Addict
Posts: 1203
Joined: Sun Jul 25, 2004 4:21 pm
Location: USoA
Contact:

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

Post 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.
- - - - - - - - - - - - - - - -
Randy
I *never* claimed to be a programmer.
Randy Walker
Addict
Addict
Posts: 1203
Joined: Sun Jul 25, 2004 4:21 pm
Location: USoA
Contact:

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

Post 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.
- - - - - - - - - - - - - - - -
Randy
I *never* claimed to be a programmer.
Randy Walker
Addict
Addict
Posts: 1203
Joined: Sun Jul 25, 2004 4:21 pm
Location: USoA
Contact:

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

Post 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,
- - - - - - - - - - - - - - - -
Randy
I *never* claimed to be a programmer.
Randy Walker
Addict
Addict
Posts: 1203
Joined: Sun Jul 25, 2004 4:21 pm
Location: USoA
Contact:

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

Post 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.
- - - - - - - - - - - - - - - -
Randy
I *never* claimed to be a programmer.
Post Reply