WriteFile + FolderReport

Please check the FAQ (https://www.xyplorer.com/faq.php) before posting a question...
Post Reply
sl23
Posts: 272
Joined: 03 Feb 2015 23:34
Location: XYplorer 64 Latest beta, Win11x64 25H2, 1920x1080 @100%

WriteFile + FolderReport

Post by sl23 »

I've managed to get reports to write toa file using this:

Code: Select all

"Current Folder|:cliptext" writefile("- DirList - <curfolder>.ini", report("{Basename}{dir = DIR}<crlf>", , "; <curpath> on <date><crlf><crlf>"));
I've also managed to get a folderreport to show a text box, and to write to a .txt file using this:

Code: Select all

"Folders List|:cliptext" text folderreport("tree:{dir {name} ({count})}", "r", , "r");
Both work fine, It would just be more helpful if I could make the folderreport write to an .ini file in the same way the writefile does. So I tried this:

Code: Select all

"Current Folder|:cliptext" writefile("- DirList - <curfolder>.ini", folderreport("tree:{dir {name} ({count})}", "r", , "r"); <curpath> on <date><crlf><crlf>"));
Obviously these are basic examples I've manipulated from the manual. Which I am trying to decipher how to use the terms and what terms mean what. I've looked under both the folderreport and writefile sections and see in the writefile section that this is the correct order:
Syntax
writefile(filename, data, [on_exist], [mode], [start=1], [numbytes=-1])
So, where it says data, is that the correct place to put the syntax for the folderreport syntax? Sorry, I just have no clue what goes where, I'm trying to learn, but I'm not sure what is the correct way to combine these things.

Thank you for your help. :)

EDIT: Just tried this, cos I think using writefile is perhaps the wrong way to go:

Code: Select all

"Folders List|:cliptext" folderreport("tree:{dir {name} ({count})}", "f", , "r", "- DirList - <curfolder>.ini");
I get a flash of the app window, but no idea what's happening with it! It doesn't create a file at all!

Could someone shed some light on my mistake please? :)
I'm pretty sure it's the last part, as it works ok without that, but I would prefer it to save to .ini file rather than .txt.

highend
Posts: 14571
Joined: 06 Feb 2011 00:33
Location: Win Server 2022 @100%

Re: WriteFile + FolderReport

Post by highend »

Use a full path when doing this:

Code: Select all

"Folders List|:cliptext" folderreport("tree:{dir {name} ({count})}", "f", , "r", "<curpath>\- DirList - <curfolder>.ini");
One of my scripts helped you out? Please donate via Paypal

sl23
Posts: 272
Joined: 03 Feb 2015 23:34
Location: XYplorer 64 Latest beta, Win11x64 25H2, 1920x1080 @100%

Re: WriteFile + FolderReport

Post by sl23 »

Omg! So close! Thank you highend for the quick response, and the solution! :tup:
May I ask, why does this need full path but writefile doesn't?

I've just seen the dirrel command, should I have used that? What is the difference between tree and dir commands anyway?

highend
Posts: 14571
Joined: 06 Feb 2011 00:33
Location: Win Server 2022 @100%

Re: WriteFile + FolderReport

Post by highend »

- Ask Don, it's not mentioned in the help
- Why should a type influence the path where the report is written?
- Different outputs?
One of my scripts helped you out? Please donate via Paypal

sl23
Posts: 272
Joined: 03 Feb 2015 23:34
Location: XYplorer 64 Latest beta, Win11x64 25H2, 1920x1080 @100%

Re: WriteFile + FolderReport

Post by sl23 »

I just thought maybe the type had different response to the path. So using dirrel would make it unnesessary to use <curpath> ?

That was my thinking, but I made a quick test, swapped tree for dir and then dirrel, but they didn't work???! I'm ok with how it functions, would be nice if the layout could be adjusted to save me having to do major editing afterwards, but tbh, this little thing will save a LOT of time, so, thanks for the help!

highend
Posts: 14571
Joined: 06 Feb 2011 00:33
Location: Win Server 2022 @100%

Re: WriteFile + FolderReport

Post by highend »

All three types work fine here...
One of my scripts helped you out? Please donate via Paypal

sl23
Posts: 272
Joined: 03 Feb 2015 23:34
Location: XYplorer 64 Latest beta, Win11x64 25H2, 1920x1080 @100%

Re: WriteFile + FolderReport

Post by sl23 »

Without any other adjustments though? I literally only changed that one command.

highend
Posts: 14571
Joined: 06 Feb 2011 00:33
Location: Win Server 2022 @100%

Re: WriteFile + FolderReport

Post by highend »

Apart from checking where the focus is / what's inside the current folder? Nope
One of my scripts helped you out? Please donate via Paypal

sl23
Posts: 272
Joined: 03 Feb 2015 23:34
Location: XYplorer 64 Latest beta, Win11x64 25H2, 1920x1080 @100%

Re: WriteFile + FolderReport

Post by sl23 »

I need a little help with this again please. :)

I've managed to almost get what I want, but although it's close, I think there's still a fair bit missing code-wise. I have absolutely no idea where to start, ie, what commands to use. I've been checking the manual, but I just get lost in it all!

My aim: select folders in the drive root, click the "Reports" ctb I've created, then select a submenu item called "Dir Size". This should then create a file with the selected folders sizes and number of files and folders within each of the selected folders. Whilst avoiding RecycleBin and other system folders
My ctb code:

Code: Select all

"Files + Folders|:cliptext" writefile("- DirList - <curfolder>.ini", report("{Basename}{dir = DIR}<crlf>", , "; <curpath> on <date><crlf><crlf>"));
"Folders Only|:cliptext" folderreport("tree:{dir {name}}", "f", , "r", "<curpath>\- DirList - <curfolder>.ini", <crlf>,);
"Create Playlist|:cliptext" writefile("- <curfolder>.m3u", report("{Basename}.{ext}<crlf>", ,));
"Dir Size|:cliptext" folderreport("dirs:[{name}]<crlf>; <date><crlf>{size} ({size b})<crlf>", "f", , , "<curpath>\- [<curfolder>] Size.ini", <crlf>,);
I suspect part of what I need is already there and I just need to figure out how to combine it, but the bit about reporting only selected folders I don't yet have and really don't have a clue with.

Ideally, I was hoping to get this:
[Documents]
; 2024.08.12
364 GB = (391,431,964,109 bytes)
118,290 Files / 3,539 Folders

[Games]
; 2024.08.12
636 GB = (682,940,770,622 bytes)
172 Files / 8 Folders

[SyMenu] + [SyMenu - Other]
; 2024.08.12
133 GB = (143,100,365,350 bytes)
552,683 Files / 29,628 Folders

[Videos]
; 2024.08.12
1.06 TB = (1,168,793,852,941 bytes)
5,175 Files / 377 Folders
Maybe that's a bit much to expect from this function? I don't know, but it looks like it could be possible to me, just not able to understand how the scripting works so I can get it to do what I want. :oops:
Is there any chance of some help please.
Thank you. :tup:

highend
Posts: 14571
Joined: 06 Feb 2011 00:33
Location: Win Server 2022 @100%

Re: WriteFile + FolderReport

Post by highend »

Code: Select all

"Files + Folders|:cliptext" writefile("- DirList - <curfolder>.ini", report("{Basename}{dir = DIR}<crlf>", , "; <curpath> on <date><crlf><crlf>"));
"Folders Only|:cliptext" folderreport("tree:{dir {name}}", "f", , "r", "<curpath>\- DirList - <curfolder>.ini", <crlf>,);
"Create Playlist|:cliptext" writefile("- <curfolder>.m3u", report("{Basename}.{ext}<crlf>", ,));
"Dir Size|:cliptext"
    $content = "";
    foreach($item, <get SelectedItemsPathNames>, <crlf>, "e") {
        if (regexmatches($item, "^.*?\\(\$Recycle\.bin|System Volume Information)")) { continue; }
        $short = gpc($item, "file");
        status "Processing " . $short . "...", , "progress";
        $content .= "[" . $short . "]" . <crlf>;
        $size     = foldersize($item, "<r>|<f>|<d>");
        $sizeRaw  = gettoken($size, 1, "|");
        $content .= formatbytes($sizeRaw, "FLEX") . " (" . formatbytes($sizeRaw, "b") . " bytes)" . <crlf>;
        $content .= formatbytes(gettoken($size, 2, "|"), "b") . " Files / " . formatbytes(gettoken($size, 3, "|"), "b") . " Folders" . <crlf 2>;
    }
    if ($content) {
        $content = "; " . gpc(, "drive") . ": - " . formatdate(, "yyyy.mm.dd") . <crlf> . $content;
        writefile("- [<curfolder>] Size.ini", $content, , "utf-8");
    }
One of my scripts helped you out? Please donate via Paypal

sl23
Posts: 272
Joined: 03 Feb 2015 23:34
Location: XYplorer 64 Latest beta, Win11x64 25H2, 1920x1080 @100%

Re: WriteFile + FolderReport

Post by sl23 »

Oh wow! That's insane thank you highend! I'd never have figured that out! :tup:

Post Reply