Can Unrar Output File Lists in XML Format?

The official unrar command-line utility does not natively support exporting file lists directly into XML format. While unrar provides several listing commands to view archive contents in plain text, it lacks built-in switches for structured data outputs like XML or JSON. To obtain an XML file list from a RAR archive, you must either use an alternative tool that supports XML output natively or parse standard unrar output using a script.

Native unrar Limitations

The standard unrar tool offers switches such as unrar l (standard list), unrar lt (detailed technical list), and unrar vb (bare format listing paths only). None of these commands include options for formatting flags like --xml or --json. Running these commands only produces unstructured or semi-structured plain text designed for human reading rather than machine parsing.

Solution 1: Use 7-Zip with XML Output

The most straightforward way to get a native XML listing from a RAR archive is using 7-Zip (7z), which includes native XML reporting.

Run the following command:

7z l -sxml archive.rar > filelist.xml

The -sxml switch instructs 7-Zip to output the complete archive metadata, directory hierarchy, and file attributes formatted as valid XML.

Solution 2: Parse unrar vb Using Bash

If you must use unrar in a Linux or macOS shell environment, you can use the bare list command (vb) to print only the file paths, then wrap the output in XML tags:

echo '<?xml version="1.0" encoding="UTF-8"?>' > filelist.xml
echo '<archive>' >> filelist.xml
unrar vb archive.rar | sed 's/\(.*\)/  <file>\1<\/file>/' >> filelist.xml
echo '</archive>' >> filelist.xml

This generates a clean XML document containing each relative file path inside a <file> tag.

Solution 3: Parse RAR Archives via Python

For more detailed metadata (such as file sizes, compression ratios, and modification dates) structured into XML, a Python script utilizing the rarfile or standard xml.etree.ElementTree library is the most robust approach:

import xml.etree.ElementTree as ET
import rarfile

archive = rarfile.RarFile("archive.rar")
root = ET.Element("archive", filename=archive.filename)

for info in archive.infolist():
    file_el = ET.SubElement(root, "file")
    ET.SubElement(file_el, "name").text = info.filename
    ET.SubElement(file_el, "size").text = str(info.file_size)
    ET.SubElement(file_el, "compressed_size").text = str(info.compress_size)
    ET.SubElement(file_el, "isdir").text = str(info.isdir())

tree = ET.ElementTree(root)
tree.write("filelist.xml", encoding="utf-8", xml_declaration=True)

This method gives you complete control over the XML schema and extracts all technical metadata that unrar otherwise prints as unstructured text.