简体   繁体   中英

Using powershell to turn a folder structure into an XML file

I've been downloading a bunch of music the lately(yes yes, perfectly legal )

Anyway, the random idea to turn the folderstructure into and XML file occured to me. I don't know what I'd do with it, but I'd like to be able to do it.

So I turned to Windows Powershell. Turning any data into and XML file is done via:

$P = "command to get data"
$P | export-CliXML "where you want your XML file to be saved"

Still, I'm having trouble listing the folders. They're all saved on an external harddrive with the letter E, under the map "Music check later".

Can anybody help me here? I know that Get-ChildItem -Recursive is a part of it, but that's about as far as I'm getting here.

Are you looking for something as simple as:

Get-ChildItem -Recurse 'E:\Music check later' | Export-CliXML <outputfile>

Of course, the CliCML format outputs the XML as a Powershell object so you'll find a lot of extra information you may not need.

It might be worth your while using the output from GetChildItem to generate your own XML schema based on your needs.

With PowerShell CTP3 you can use the ConvertTo-XML cmdlet. You'll need to know how deep your folder structure is in advance. By default the cmdlet convert the first level only. You can increase it with using the -Depth parameter.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM