# How to convert .root to .txt file?

**URL:** <https://root-forum.cern.ch/t/how-to-convert-root-to-txt-file/30534>\
**Category:** ROOT\
**Created:** [September 4, 2018, 5:22am UTC](https://root-forum.cern.ch/t/how-to-convert-root-to-txt-file/30534 "2018-09-04T05:22:39Z")\
**Posts on this page:** 1\
**Showing post:** 4

<div class="post-metadata">

**Author:** ![pcanal](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/pcanal/32/12439_2.png) [@pcanal](https://root-forum.cern.ch/u/pcanal)\
**Post date:** [September 4, 2018, 7:35pm UTC](https://root-forum.cern.ch/t/how-to-convert-root-to-txt-file/30534/4 "2018-09-04T19:35:50Z")

</div>

> [@Donghyeon\_Lee](#):
>
> It DIDN’T work and got some errors.

hummm … in ROOT 6, the usage of this script should be:

```auto
.> dump.txt
.x dump.cxx
.>

```

The `.x dump.cxx(); > dump.txt` part is a retired interface supported only in ROOT 5 and older.

Alternative use the following script:

```auto
// Name this file "dump.cxx" and use as:
//
// root [0] .x dump.cxx("dump.txt")
//
// Produces "dump.txt" and "dump.xml" files.
//

void dump(const char *outputname = "dump.txt",
          const char *fname = "dump.root",
          const char *nname = "ntuple")
{
  if (!outputname || !(*outputname) || !fname || !(*fname) || !nname || !(*nname)) return; // just a precaution
  
  TFile *f = TFile::Open(fname, "READ");
  if (!f || f->IsZombie()) { delete f; return; } // just a precaution
  
  TTree *t; f->GetObject(nname, t);
  if (!t) { delete f; return; } // just a precaution
  
  t->SetScanField(0);
  ((TTreePlayer*)t->GetPlayer())->SetScanRedirect(kTRUE);
  ((TTreePlayer*)t->GetPlayer())->SetScanFileName(outputname);
  t->Scan("*");
  t->SaveAs("dump.xml");
  
  delete f; // no longer needed (automatically deletes "t")
}

```

Cheers,  
Philippe.

---

_[View the full topic](https://root-forum.cern.ch/t/how-to-convert-root-to-txt-file/30534)._
