How to set file properties with a script command?
-
Jerry
- Posts: 835
- Joined: 05 May 2010 15:48
- Location: The UnUnited States of America
How to set file properties with a script command?
Hi all,
I've looked everywhere but can't find the answer: How do you use a script to set file properties? For example, I want to simply have a script or script command to change all selected files to read-only. More specifically, I want to use it as a on/off toggle. I see the property command but it only retrieves properties.
I've looked everywhere but can't find the answer: How do you use a script to set file properties? For example, I want to simply have a script or script command to change all selected files to read-only. More specifically, I want to use it as a on/off toggle. I see the property command but it only retrieves properties.
Running on Windows 10 Pro 64-bit quad-core ASUS G752-VY notebook with 64 GB RAM, over 26 external USB3 drives attached via multiple powered hubs with letters and mount points, totaling 120+ TB. SCREEN SCALING: 125%
-
admin
- Site Admin
- Posts: 67313
- Joined: 22 May 2004 16:48
- Location: Win8.1, Win10, Win11, all @100%
- Contact:
Re: How to set file properties with a script command?
There is currently no scripting command to set attributes.
But you can simply do it from the Properties tab on the Info Panel (F12). Click on one file to get the info tab filled, then select the files you want to set the attributes to, then click the attributes checkboxes, then click the appearing "green tick" button to apply the settings.
But you can simply do it from the Properties tab on the Info Panel (F12). Click on one file to get the info tab filled, then select the files you want to set the attributes to, then click the attributes checkboxes, then click the appearing "green tick" button to apply the settings.
FAQ | XY News RSS | XY X
-
Jerry
- Posts: 835
- Joined: 05 May 2010 15:48
- Location: The UnUnited States of America
Re: How to set file properties with a script command?
Yes, I occasionally use that method, but it involves a lot of steps: After selecting the files, you have to 1) click on the toolbar to show the properties panel; 2) click on the Read-only checkbox; 3) click on the "green tick" button; and 4) click on the toolbar again to dismiss the properties panel. That's because when I use XYplorer, I always have it sized to the full width of my desktop but only half the height so I therefore don't want the info panel to always show.admin wrote:There is currently no scripting command to set attributes.
But you can simply do it from the Properties tab on the Info Panel (F12). Click on one file to get the info tab filled, then select the files you want to set the attributes to, then click the attributes checkboxes, then click the appearing "green tick" button to apply the settings.
Alternatively, I have using the Attributes plugin to Creative Elements Powertools but even this is cumbersome when there is a mixed set of read and read-only files in the selected list -- in that situation it always first toggles off before toggling on. Since discovering XYplorer, I have been using CE Powertools less and less but this read-only toggle function is still more efficient than doing it in XYplorer.
So, I would like to see a scripting command for setting/clearing properties, at least one for the basic file properties, read-only, hidden, system, etc. Is this a possibility or does Don consider it too specific a request?
Running on Windows 10 Pro 64-bit quad-core ASUS G752-VY notebook with 64 GB RAM, over 26 external USB3 drives attached via multiple powered hubs with letters and mount points, totaling 120+ TB. SCREEN SCALING: 125%
-
admin
- Site Admin
- Posts: 67313
- Joined: 22 May 2004 16:48
- Location: Win8.1, Win10, Win11, all @100%
- Contact:
Re: How to set file properties with a script command?
Yes, it's a possibility. I'll add it.
FAQ | XY News RSS | XY X
-
Jerry
- Posts: 835
- Joined: 05 May 2010 15:48
- Location: The UnUnited States of America
Re: How to set file properties with a script command?
Wonderful news! Thanks Don.admin wrote:Yes, it's a possibility. I'll add it.
Running on Windows 10 Pro 64-bit quad-core ASUS G752-VY notebook with 64 GB RAM, over 26 external USB3 drives attached via multiple powered hubs with letters and mount points, totaling 120+ TB. SCREEN SCALING: 125%
-
admin
- Site Admin
- Posts: 67313
- Joined: 22 May 2004 16:48
- Location: Win8.1, Win10, Win11, all @100%
- Contact:
Re: How to set file properties with a script command?
So, does it work for you now?
FAQ | XY News RSS | XY X
-
Jerry
- Posts: 835
- Joined: 05 May 2010 15:48
- Location: The UnUnited States of America
Re: How to set file properties with a script command?
Oh, in the current beta. Yes, looks good. I had to write the following script around it to get the precise toggling behavior I want, since attrstamp("r", 3); won't turn the attribute off on all the selected files if any of them are already set. But I recognize that's a specific usage not to reasonably expect in the core function. ;-)admin wrote:So, does it work for you now?
Thanks Don.
Code: Select all
// Toggles readonly attribute on selected files: If any file has readonly already
// set than all the files are unset. Otherwise all are set
$fileList = Report("{Fullname}<crlf>", 1);
$anyReadOnly=0; // indicates whether any of the files have readonly set
foreach ($file, "$fileList", "<crlf>") {
if ((attrstamp("r", 0, $file) % 2) == 1) {
$anyReadOnly=1;
break;
}
}
if ($anyReadOnly == 1) {
attrstamp("r", 4); // remove readonly on selected files
}
else {
attrstamp("r"); // set readonly on selected files
}
Running on Windows 10 Pro 64-bit quad-core ASUS G752-VY notebook with 64 GB RAM, over 26 external USB3 drives attached via multiple powered hubs with letters and mount points, totaling 120+ TB. SCREEN SCALING: 125%
-
TheQwerty
- Posts: 4373
- Joined: 03 Aug 2007 22:30
Re: How to set file properties with a script command?
You could really shorten this by using report to get the items' attributes and then checking for 'r':Jerry wrote:Code: Select all
// Toggles readonly attribute on selected files: If any file has readonly already // set than all the files are unset. Otherwise all are set $fileList = Report("{Fullname}<crlf>", 1); $anyReadOnly=0; // indicates whether any of the files have readonly set foreach ($file, "$fileList", "<crlf>") { if ((attrstamp("r", 0, $file) % 2) == 1) { $anyReadOnly=1; break; } } if ($anyReadOnly == 1) { attrstamp("r", 4); // remove readonly on selected files } else { attrstamp("r"); // set readonly on selected files }
Code: Select all
"Toggle Read-Only"
if (StrPos(Report('{Attr}', 1), 'r') < 0) {
AttrStamp('r', 1);
} else {
AttrStamp('r', 4);
}Don, any reason the attribute argument of AttrStamp is case-sensitive? And worse so quiet about it?
-
Jerry
- Posts: 835
- Joined: 05 May 2010 15:48
- Location: The UnUnited States of America
Re: How to set file properties with a script command?
Excellent! And more efficient performance-wise no doubt. I am just starting out with XY's scripting so I appreciate the tips!You could really shorten this by using report to get the items' attributes and then checking for 'r':
Running on Windows 10 Pro 64-bit quad-core ASUS G752-VY notebook with 64 GB RAM, over 26 external USB3 drives attached via multiple powered hubs with letters and mount points, totaling 120+ TB. SCREEN SCALING: 125%
-
admin
- Site Admin
- Posts: 67313
- Joined: 22 May 2004 16:48
- Location: Win8.1, Win10, Win11, all @100%
- Contact:
Re: How to set file properties with a script command?
Right, I just made it case-insensitive. Error on invalid argument does not seem necessary.TheQwerty wrote:Don, any reason the attribute argument of AttrStamp is case-sensitive? And worse so quiet about it?
FAQ | XY News RSS | XY X
-
TheQwerty
- Posts: 4373
- Joined: 03 Aug 2007 22:30
Re: How to set file properties with a script command?
Much better, and the fact that it ignores other characters silently is actually a good thing since you can plug in the results of Report's {Attr} value without reformatting it.admin wrote:Right, I just made it case-insensitive.
Indeed, especially since my own laziness and lack of thinking led me to ignore the returned values from AttrStamp which I could have used to verify the operation's success.admin wrote:Error on invalid argument does not seem necessary.
-
Jerry
- Posts: 835
- Joined: 05 May 2010 15:48
- Location: The UnUnited States of America
Re: How to set file properties with a script command?
Here's the script that I wrote and have been using, oh my goodness, for over 10 years now:
// Toggles readonly attribute on selected files:
// If any file has readonly already set then all the files are unset. Otherwise all are set.
if (StrPos(Report('{Attr}', 1), 'r') < 0) {
AttrStamp('r', 1);
} else {
AttrStamp('r', 4);
}
Running on Windows 10 Pro 64-bit quad-core ASUS G752-VY notebook with 64 GB RAM, over 26 external USB3 drives attached via multiple powered hubs with letters and mount points, totaling 120+ TB. SCREEN SCALING: 125%
XYplorer Beta Club