You are not logged in.
Pages: 1
I was wondering is there a way to set the file attributes with Pascal Script? I am using the program to process a large set of files and it would be nice to be able to set the file attributes programmatically (for example: hidden) when running the script.
Thanks you!
Offline
There are all available functions you can use in a PascalScript for ReNamer:
https://www.den4b.com/wiki/ReNamer:Pasc … :Functions
Since ReNamer is a tool to rename file names, such file modifications are not in scope of this tool, me think.
Why not using the scripting tools of your OS, like DOS batch , VBScript or Powershell?
Open CMD and type in: attrib /?
Maybe you can "abuse" the PascalScript ExecConsoleApp() function for your task
https://www.den4b.com/wiki/ReNamer:Pasc … _Execution
I would use an scripting tools of my OS or a dedicated file manager.
my opinion
Read the *WIKI* for HELP + MANUAL + Tips&Tricks.
If ReNamer had helped you, please *DONATE* to Denis or buy a PRO license. (Read *Lite vs Pro*)
Offline
That is what I am doing right now, I am using ExecConsoleApp() and call a .bat script to set the file attribute. It works but is rather cumbersome. The point of it is that it would be nice to set the attributes as some files are renamed, so that I do not need to search for the files after they are renamed and set the attributes in other software.
Offline
At least we can export the NewName column
https://www.den4b.com/wiki/ReNamer:Export_menu
I can provide a VBScript or Powershell command to parse that exported list
line-by-line and then there can be done something to each file name.
Stil two steps, but would work...
Read the *WIKI* for HELP + MANUAL + Tips&Tricks.
If ReNamer had helped you, please *DONATE* to Denis or buy a PRO license. (Read *Lite vs Pro*)
Offline
You can call Windows API functions directly in Pascal Script.
The functions you are interested in are GetFileAttributesW and SetFileAttributesW.
Below is a script that will read common file attributes and will in insert them as text into the filename, for a demonstration:
function GetFileAttributesW(lpFileName: WideString): Cardinal;
external 'GetFileAttributesW@kernel32.dll stdcall';
function SetFileAttributesW(lpFileName: WideString; dwFileAttributes: Cardinal): Cardinal;
external 'SetFileAttributesW@kernel32.dll stdcall';
const
FILE_ATTRIBUTE_READONLY = $0000001;
FILE_ATTRIBUTE_HIDDEN = $0000002;
FILE_ATTRIBUTE_SYSTEM = $0000004;
FILE_ATTRIBUTE_ARCHIVE = $0000020;
FILE_ATTRIBUTE_NORMAL = $0000080;
FILE_ATTRIBUTE_TEMPORARY = $0000100;
FILE_ATTRIBUTE_OFFLINE = $0001000;
var
Attributes: Cardinal;
AttrText: String;
begin
// Get file attributes
AttrText := '';
Attributes := GetFileAttributesW(FilePath);
if (Attributes and FILE_ATTRIBUTE_READONLY <> 0) then
AttrText := AttrText + 'R';
if (Attributes and FILE_ATTRIBUTE_HIDDEN <> 0) then
AttrText := AttrText + 'H';
if (Attributes and FILE_ATTRIBUTE_SYSTEM <> 0) then
AttrText := AttrText + 'S';
if (Attributes and FILE_ATTRIBUTE_ARCHIVE <> 0) then
AttrText := AttrText + 'A';
if (Attributes and FILE_ATTRIBUTE_TEMPORARY <> 0) then
AttrText := AttrText + 'T';
if (Attributes and FILE_ATTRIBUTE_OFFLINE <> 0) then
AttrText := AttrText + 'O';
FileName := '[' + AttrText + '] ' + FileName;
end.
If you wish to change file attributes, replace the code body (between "begin" and "end") with something like this:
// Set READONLY attribute
Attributes := GetFileAttributesW(FilePath);
Attributes := Attributes or FILE_ATTRIBUTE_READONLY;
SetFileAttributesW(FilePath, Attributes);
// Unset READONLY attribute
Attributes := GetFileAttributesW(FilePath);
Attributes := Attributes and (not FILE_ATTRIBUTE_READONLY);
SetFileAttributesW(FilePath, Attributes);
Remember that the pascal script rule is executed every time a new name is generated!
Offline
Pages: 1