SRMicro Info Systems Interview Question
Testing / Quality AssurancesCountry: INDIA
Interview Type: Written Test
I didn't really understand the question. What do you mean by?
a.abc file contains
file:b.abc
value:4
file:c.abc
value:6 ....
>>read a.abc file and get the file name and check that file is exist or not if file is exit read the value and print ..
When a.abc is read, we get file b.abc and there's a value 4 associated..so we print 4 ?
And if that's the case, when we get c.abc (also with a.abc.. should the o/p be 6 or should the other file be opened, with d.abc and e.abc inside?
P.S: I think we can do with less confusing filenames.
you can try this:
my $file12 = "a.abc";
&fileDep($file12);
# generate the dependency order
sub fileDep {
my $file = shift;
open(READ1,"<$file");
while(<READ1>) {
chomp;
if ($_=~ /(.*\.abc)/ ) {
if (-e $1) {
print "found file $1 \n";
&fileDep($1);
} else {
print " file $1 not found\n";
return;
}
} else {
print " no further dep\n";
return;
}
}
close READ1;
}
It is a C# solution for the question
- karthiga.m1988 February 22, 2013using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
namespace FileHierarchy_Csharp
{
class Program
{
static void Main(string[] args)
{
string traverseDirectory ="..\\..\\..\\..\\";
string extension = ".txt";
string[] keyword = new string[] { "file", "value" };
string[] lines,elements;
char[] seperator = new Char[]{':','\n'};
int index = 0;
string currentDirectory = Directory.GetCurrentDirectory();
string filePath = traverseDirectory+"a.abc"+extension;
string fileName = null;
bool found = false;
if (File.Exists(filePath))
{
lines = File.ReadAllLines(filePath);
for(int i = 0 ; found==false && i<lines.Count();i++)
{
elements = lines[i].Split(seperator);
foreach (string element in elements)
{
if (element.ToString() == keyword[0])
{
index = element.IndexOf(element);
fileName = elements[index+1];
found = true;
break;
}
}
}
found = false;
if(fileName!=null)
{
if (File.Exists(traverseDirectory + fileName + extension))
{
lines = File.ReadAllLines(filePath);
elements = lines[0].Split(seperator);
for (int i = 0; found == false && i < lines.Count(); i++)
{
elements = lines[i].Split(seperator);
foreach (string element in elements)
{
if (element.ToString() == keyword[1])
{
index = element.IndexOf(element);
fileName = elements[index+1];
found = true;
break;
}
}
}
}
}
Console.WriteLine(fileName);
}
string s = Console.ReadLine();
}
}
}