# Power Query - txt files from Folder



## pepe74287 (Apr 29, 2016)

Hello PQ experts,

I want to import multiple text files from folder (this is not a problem at all), but when I expand the content column, txt file name disappears. I need to have it there since I later need to merge the output with another table( based on filename). For CSV files I could use  Csv.Document([Content]), but how to achieve the same for txt files?

Thanks

Pepe


----------



## billszysz (Apr 29, 2016)

Add step 

```
= Table.AddColumn(YourPreviousStep, "txtFileAsTable", each Table.FromColumns({Lines.FromBinary([Content],null,null,1250)}))
```

Regards


----------



## pepe74287 (Apr 29, 2016)

Hi Bill,

Thanks for your input, but I'm not sure how to incorporate it in my code. So far I only have:

```
let
    Source = Folder.Files("\\PTT QUERY\TXT attachments")
 
in
    Source
```
When I expand the Content column (binary type), I get almost exactly what I want (PQ split text files into 7 columns exactly as expected), but without file names. I would need to have the output in the same format but with file name. I've tried to add your code to new custom column, but now I have all 7 columns merged into 1.


----------



## billszysz (Apr 29, 2016)

Ok...so, based on your code.

```
let
    Source = Folder.Files("\\PTT QUERY\TXT attachments"),
    AddColumn = Table.AddColumn(Source, "txtFileAsTable", each Table.FromColumns({Lines.FromBinary([Content],null,null,1250)}))
 
in
    AddColumn
```
Npw you can remove unwanted columns (but not "Name" column) and expand column "txtFileAsTable".
Regards


----------



## pepe74287 (Apr 29, 2016)

The problem is still the same.. It works, but instead of 7 desired columns from txt files I get only one. And I can't split it easily into original 7 columns. The txt structure is like this:


ASSET_NAMESITE_NAME STREETCITYPROVINCEPVC_PARENT_APVC_PARENT_BABN VC 845EQUINIX CDBRAMTREETORONTOONABBA


----------



## billszysz (Apr 29, 2016)

Maybe yoyr txt files are like Csv files (i'm not sure because i do not see an example file and don't know what is a delimiter)
Ok...try use Csv document intead of Lines.FromBinary. I mean something like this

```
let
    Source = Folder.Files("\\PTT QUERY\TXT attachments"),
    AddColumn = Table.AddColumn(Source, "txtFileAsTable", each Csv.Document([Content], null, "#(tab)"))
 
in
    AddColumn
```

This means that TAB is a delimiter. You can use 7 instead of null if you are sure your table has 7 columns.
Maybe, you will have to change this delimiter.

Regards


----------



## pepe74287 (Apr 29, 2016)

That was it 

Thank you
Pepe


----------

