Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3808400
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 19, 20262026-05-19T15:08:31+00:00 2026-05-19T15:08:31+00:00

Can someone suggest a script to create a xml representation of all the files,

  • 0

Can someone suggest a script to create a xml representation of all the files, alongwith the ones in the sub-directory(on Windows) by file-type. For example, if the current directory name is mypics, then for all jpg’s

<?xml version="1.0" encoding="utf-8"?>
<images xmlns="http://mydomain.com/images" version="1.0">
  <image>
      <big_url>myassets/pics/funnypics/big_pics/down.jpg</big_url>
  </image>
  <image>      
      <big_url>assets/pics/funnypics/big_pics/spider.jpg</big_url>
  </image>  
</images>

then for pdf’s

<?xml version="1.0" encoding="utf-8"?>
<pdfs xmlns="http://mydomain.com/pdf" version="1.0">
  <pdf>
      <big_url>myassets/pics/funnypics/big_pics/down.pdf</big_url>
  </pdf>
  <pdf>      
      <big_url>assets/pics/funnypics/big_pics/spider.pdf</big_url>
  </pdf>  
</pdfs>

since, number of filetype is unlimited, i can extend the suggested script

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-19T15:08:31+00:00Added an answer on May 19, 2026 at 3:08 pm

    The following perl code will do the trick (maybe minus the XML file indentation):

    package FilesToXml;
    use IO;
    use File::Find;
    use XML::Writer;
    
    use vars qw(@ISA @EXPORT @EXPORT_OK);
    require Exporter;
    @ISA = qw(Exporter);
    @EXPORT = qw(SetRequestedType GenerateXml);
    
    my $group_name = "";
    my $file_type = "";
    my $ext = "";
    my $writer = "";
    
    sub SetRequestedType
    {
        $group_name = shift;
        $file_type = shift;
        $ext = shift;
    }
    
    sub wanted
    {
        if ($File::Find::name =~ /\.$ext$/)
        {
            $writer->startTag($file_type);
            $writer->startTag('big_url');
            $writer->characters($File::Find::name);
            $writer->endTag();
            $writer->endTag();
        }    
    }
    
    sub GenerateXml
    {
        my $filename = shift;
        my $directory = shift;
    
        my $output = new IO::File(">$filename");
        $writer = new XML::Writer( OUTPUT => $output );
    
        $writer->xmlDecl( 'UTF-8' );
        $writer->startTag( $group_name, 'xmlns' => 'http://mydomain.com/'.$group_name, 
                            'version' => '1.0' );
        find(\&wanted, $directory);
        $writer->endTag();  
    }
    
    package main;
    
    FilesToXml::SetRequestedType('docs', 'doc', 'docx');
    FilesToXml::GenerateXml("output.xml", ".");
    

    You basically need to call SetRequestedType with the type of the files group, the string describing a single file and the file extension. Then you just need to call GenerateXml with the XML output file name and the directory to search under.

    It works using ActivePerl on Windows. May need some minor adjustments in other environments.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Can someone suggest a good module in perl which can be used to store
Can someone suggest a way to compare the values of two dates greater than,
Can someone suggest me some JAVA string library for JAVA ME that includes basic
Can someone suggest a good wiki for our dev team please. I know this
Can someone suggest me how to build up the following query using JPA Criteria
Can someone show me how to implement a recursive lambda expression to traverse a
Can someone explain the mechanics of a jump table and why is would be
Can someone give an example of a good time to actually use unsafe and
Can someone describe what a symbol table is within the context of C and
Can someone explain to me the advantages of using an IOC container over simply

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.