I am trying to do some project and get stuck with it. I was doing Java and C++, no C#, but I got this to work on - create and save an XML file containing complete hierarchy of folders on a specified drive including a list of all files that are short (short file has up to 8 characters for name and up to 3 characters for extension). I also need to have size of file and folder in bytes and in letters and print files with small name (smaller then 11 char including extension). This is my code:
using System;
using System.IO;
using System.Xml;
using System.Linq;
public class Program{
public static void Main(string[] args)
{
//Your code goes here
string[] folders = {"Folder1", "Folder2"};
string[] files = {"File1.txt", "File2.txt"};
XmlTextWriter w1 = new XmlTextWriter("filesandfolders.xml", System.Text.Encoding.UTF8);
w1.WriteStartElement("Folders");
Console.WriteLine(folders[0]);
Console.WriteLine(files[0]);
Console.WriteLine(folders[1]);
Console.WriteLine(files[1]);
w1.WriteEndElement();
w1.WriteEndDocument();
File.WriteAllText("filesandfolders.xml", "structure of folders and files");
long fileSize = 0;
int fileLegth = 0;
int NumberOfShortFiles;
Console.WriteLine("Folder names are: [{0}]", string.Join(", ", folders));
Console.WriteLine("File names are: [{0}]", string.Join(", ", files));
for(long p=0; p<=files.Length; p++){
Console.WriteLine("Size of this file is "+fileSize);
}
for(int q=0; q<=files.Length; q++){
Console.WriteLine("Directory length is "+q);
}
for(int m=0; m<=11; m++){
NumberOfShortFiles = m;
}
if(fileLegth<=11){
Console.WriteLine("File name is short.");
}
else{Console.WriteLine("File name is short or not evaluated.");}
}
}
I know the idea - make files and folders, I used array for files and another for folders hoping to know how to make them to be one XML, then save it and use some functions/loops to see size, print them etc, but I am quite confused since I never saw this kind of programming language earlier.
Let me say that for now problem is that I have size in bytes, but don't have number of letters, and I am missing root element (that is what compiler said). I didn't work with serialization, so I took something that I am familiar with (array or list).