Create file based on folder name and report folder contents

Discuss and share scripts and script files...
Post Reply
hermhart
Posts: 244
Joined: 13 Jan 2015 18:41

Create file based on folder name and report folder contents

Post by hermhart »

Hello, would anyone mind please taking a look at this and find the error in my ways. All I want this to do is to create a text file of the same name as the selected folder(s), then report the contents of the folder into the newly created text file. Thank you for any help that you can provide.

Code: Select all

   $SelectedItems = get("SelectedItemsNames", "|");
   foreach($Item, $SelectedItems, "|") {
      $ItemName = regexreplace($Item, "(.+(?=\.))(.+)", "$1");
         new($ItemName.".txt");
         folderreport("filesrel", "f", $SelectedItems, "r", $ItemName.".txt",);
   }
Windows 11 Pro; 100% scaling

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

Re: Create file based on folder name and report folder conte

Post by highend »

Code: Select all

    foreach($folder, "<get SelectedItemsNames |>") {
        if (exists("<curpath>\$folder") != 2) { continue; }
        $logFileName = regexreplace($folder, "(.+(?=\.))(.+)", "$1") . ".txt";
        if (exists("<curpath>\$logFileName") != 1) { new($logFileName); }
        folderreport("filesrel", "f", "<curpath>\$folder", "r", "<curpath>\$logFileName",);
   }
No time to make anything prettier...
One of my scripts helped you out? Please donate via Paypal

hermhart
Posts: 244
Joined: 13 Jan 2015 18:41

Re: Create file based on folder name and report folder conte

Post by hermhart »

highend,

I wasn't even close on what I had. Yours works like a charm. Thank you very much, I appreciate it.
Windows 11 Pro; 100% scaling

hermhart
Posts: 244
Joined: 13 Jan 2015 18:41

Re: Create file based on folder name and report folder conte

Post by hermhart »

Is there something that could be added to this script that would also copy the timestamp of each selected folder and use it as the timestamp for the newly created file?
Windows 11 Pro; 100% scaling

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

Re: Create file based on folder name and report folder conte

Post by highend »

Just add

Code: Select all

timestamp , "<curpath>\$folder", "<curpath>\$logFileName";
as the last line in the foreach() loop?
One of my scripts helped you out? Please donate via Paypal

hermhart
Posts: 244
Joined: 13 Jan 2015 18:41

Re: Create file based on folder name and report folder conte

Post by hermhart »

highend, I appreciate your help. Thank you.
Windows 11 Pro; 100% scaling

Post Reply