You could use the sfdx convert
commands as follows.
Let's say your metadata API files are stored in a folder called mdapi
.
In folder mdapi
, add a package.xml
file with one metadata type found in your files for e.g ApexClass. The package.xml
is required for convert command and must exist in the folder even if it does not list all components:
<?xml version="1.0" encoding="UTF-8"?>
<Package xmlns="http://soap.sforce.com/2006/04/metadata">
<types>
<members>*</members>
<name>ApexClass</name>
</types>
<version>47.0</version>
</Package>
Convert mdapi
folder to source format:
sfdx force:mdapi:convert -r ./mdapi/ -d force-app
Then convert the newly created force-app
source format repository again to metadata API to generate the package.xml
based on the files found
sfdx force:source:convert -r ./force-app/ -d mdapi2
The mdapi2
folder will contain the package.xml
file and the subfolders with the metadata components