Thanks guys for you inputs.

I now able to read directories and sub directoires and able to print the xml output file.

made some cleanup work on my inital script so it will be much more eaiser to read and follow.

problem now is it's not recusively going through sub-directoires and printing th xml output. It just reads first sub-directories file1 content and print just that as output

Can anyone tell me which loop i am missing out

Script:
#! /usr/bin/perl use strict; use warnings; use File::Basename; use File::Find; use Class::CSV; use Text::CSV; use XML::TreeBuilder; use Data::Dumper; #variable/arrays declartions my ($csv,$inputfilename,$resultfile,$fh,$line,$dir,$fp,$base_dir,$dh,$ +file,$mycontainerless,$paramsfile,$connection,$resultxmlfile,$config) +; my ($tree,$container,$row,$contree,$index,$tag,$tagname); my (@dir,@dir_names,@filenames,@taglist,@columns); #path declartions $base_dir = 'C:\Test'; $paramsfile = 'C:\Test\input.csv'; @dir = $base_dir; #read through the given directory path to look for dir/subdir's while (@dir) { $dir = pop(@dir); opendir($dh, $dir); while($file = readdir($dh)) { next if $file eq '.'; next if $file eq '..'; $file = "$dir/$file"; if (-d $file) { push(@dir, $file); push(@dir_names, basename($file)); } elsif (-f $file) { $file =~ s/.*\///; $file =~ s/\.[^.]+$//; push(@filenames, $file); } } } &write_datato_csvfile; #sleep(25); print "<!-- ************************************************** +**************-->\n"; print @dir_names; print "\n"; print "<!-- ************************************************** +**************-->\n"; print @filenames; print "\n"; print "<!-- ************************************************** +**************-->\n"; &write_output_xml; # sub functions #sub function to write input file data into csv format sub write_datato_csvfile{ open $resultfile, '>>', 'C:\Test\input.csv' or die "Can't open file: $ +!"; foreach $fp (glob("$dir/*.bat")) { print $fp; print "\n"; open ($fh, "<", $fp) or die "can't read open '$fp':"; while ($line = <$fh>) { $line=~ s/ /,/g; print $resultfile $line; print $resultfile "\n"; } close $fh or die "can't read close '$fp':"; } #close $fh or die "can't read close '$fp':"; } #sub function to write xml format in output file sub write_output_xml{ open ($resultxmlfile, '>>', 'C:\Test\resultxml.xml') or die "Can't ope +n file: $!"; print $resultxmlfile '<?xml version="1.0" encoding="utf-16"?>'; print $resultxmlfile "\n<!-- ************************************* +***************************-->\n"; print $resultxmlfile "<!-- * + *-->\n"; print $resultxmlfile "<!-- * PuTTY Configuration Manager save file + - All right reserved. *-->\n"; print $resultxmlfile "<!-- * + *-->\n"; print $resultxmlfile "<!-- *************************************** +*************************-->\n"; print $resultxmlfile "<!-- The following lines can be modified at +your own risks. -->\n"; #&write_datato_csvfile; #sleep(30); #my $time = 15; #while($time--){ #sleep(1); #} $resultfile = 'C:\Test\input.csv'; my $csv = Text::CSV->new(); open (CSV, "<", $resultfile) or die $!; print "Reading input csv file.... \n"; while (<CSV>) { next if ($. == 0); if ($csv->parse($_)) { @columns = $csv->fields(); #print "$columns[1] \n"; } else { my $err = $csv->error_input; print "Failed to parse line: $err"; } print $resultxmlfile <<EOF <configuration version="0.1.1.2" savepassword="True"> <root type="database" name="$dir_names[0]" expanded="True"> <container type="folder" name="$dir_names[1]" expanded="True"> <container type="folder" name="$dir_names[2]" expanded="Tr +ue"> <connection type="PuTTY" name="$filenames[0]"> <connection_info> <name>$filenames[0]</name> <protocol>SSH</protocol> <host>$columns[5]</host> <port>$columns[4]</port> <session>Default Settings</session> <commandline>$columns[9]</commandline> <description /> </connection_info> <login> </login> <password /> <prompt /> </login> <timeout> <connectiontimeout>1000</connectiontimeout> <logintimeout>750</logintimeout> <passwordtimeout>750</passwordtimeout> <commandtimeout>750</commandtimeout> </timeout> <command> <command1 /> <command2 /> <command3 /> <command4 /> <command5 /> </command> <options> <loginmacro>False</loginmacro> <postcommands>False</postcommands> <endlinechar>10</endlinechar> </options> </connection> EOF ; } close CSV; print $resultxmlfile "</root>\n"; print $resultxmlfile "</configuration>\n"; #close CSV; print "Output xml file has been generated successfully.. \n"; }

In reply to Re: Recursive file processing from a path and printing output in a file by Vijay81
in thread Recursive file processing from a path and printing output in a file by Vijay81

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.