Forum Discussion

creyssonbr's avatar
creyssonbr
New Member
5 years ago

Using regex to extract directory listing information

Hi,


I need to extract the filename and date of modification from prints that I receive.

Is it possbile on to put that info in a table?

I did it manually, but query gets broken when anything there changes.


They look like this:

D:\Temp>dir
 Volume in drive D is HDDX
 Volume Serial Number is XXXX-XXXX

 Directory of D:\Temp

02/28/2021  08:23 PM    <DIR>          .
02/28/2021  08:23 PM    <DIR>          ..
02/28/2021  08:22 PM               193 assistant_installer_20210228202253.log
02/28/2021  08:20 PM                 0 file1 - Copy (2).txt
02/28/2021  08:20 PM                 0 file1 - Copy (3).txt
02/28/2021  08:20 PM                 0 file1 - Copy (4).txt
02/28/2021  08:20 PM                 0 file1 - Copy (5).txt
02/28/2021  08:20 PM                 0 file1 - Copy (6).txt
02/28/2021  08:20 PM                 0 file1 - Copy (7).txt
02/28/2021  08:20 PM                 0 file1 - Copy (8).txt
02/28/2021  08:20 PM                 0 file1 - Copy (9).txt
02/28/2021  08:20 PM                 0 file1.txt
02/28/2021  08:20 PM                 0 file2.txt
02/28/2021  06:40 PM                 0 FXSAPIDebugLogFile.txt
02/28/2021  06:40 PM            50,216 ThrottleStop.sys
              13 File(s)         50,409 bytes
               2 Dir(s)  225,865,232,384 bytes free

3 Replies

  • Greg_Deckler's avatar
    Greg_Deckler
    Community Champion

    creyssonbr You should be able to use a folder query, that will get a list of source files in the directory. Not sure about the last modificiation date.

    • creyssonbr's avatar
      creyssonbr
      New Member

      Thanks for your reply Greg_Deckler .

       

      I would but I don't have access to that folder.

      I only receive a print in txt.

  • Anonymous's avatar
    Anonymous
    Not applicable

    Hi creyssonbr 

     

    You can use Web.Page to wrap regex, however, I don't know how to extract MM/DD/YYY HH:MM AM/PM. Below one is not working...just show Web.Page, you can add a custom column

     

    [   fx=(e as text) =>Web.Page(
            "<script>
            var regex = /^\d{2}/\d{2}/\d{4}\s+\d{2}:\d{2}\s+(AM|PM)$/;
            document.write('"&e&"'.match(regex));
            </script>")[Data]{0}[Children]{0}[Children]{1}[Text]{0},
        b = fx( [your Column])][b]

      

    If your print in text is all structured, use below ones?

     

    Table.AddColumn(Source, "Custom", each Text.Start([Column1],20)
    
    Table.AddColumn(#"Added Custom", "Custom1", each Text.Middle([Column1],20))