how to loop files in the folders and subfolders
I am having a problem writing the files in folders and subfolders .
For Example:- test is the main folder
1) C:\test\
and i want to read and write the subfolder files
2)C:\test\12-05-2011\12-05-2011.txt
3)C:\test\13-05-2011\13-05-2011.txt
4)C:\test\14-05-2011\14-05-2011.txt
my code is .
private void button1_Click(object sender, EventArgs e)
{
const string Path1 = @"C:\test";
DoOnSubfolders(Path1);
try
{
StreamReader reader1 = File.OpenText(Path1);
string str = reader1.ReadToEnd();
reader1.Close();
reader1.Dispose();
File.Delete(Path1);
string[] Strarray = str.Split(new char[] { Strings.ChrW(10) });
int abc = Strarray.Length - 2;
int xyz = 0;
while (xyz <= abc)
{
try
{
string[] strarray1 = Strarray[xyz].Split(",".ToCharArray());
string SecName = strarray1[0];
string SecSym = strarray1[1];
int DT = int.Parse(strarray1[2]);
int TM = int.Parse(strarray1[3]);
float O = float.Parse(strarray1[4]);
float H = float.Parse(strarray1[5]);
float L = float.Parse(strarray1[6]);
float C = float.Parse(strarray1[7]);
double V = double.Parse(strarray1[8]);
double OI = double.Parse(strarray1[9]);
BTLReaderClass class2 = new BTLReaderClass();
BTLWriterClass class3 = new BTLWriterClass();
if (! Directory.Exists("C:\\Sample1"))
{
class3.CreateDirectory("C:\\Sample1");
}
else if (! File.E开发者_Python百科xists("C:\\Sample1\\RMaster"))
{
class3.CreateDirectory("C:\\Sample1");
}
class3.OpenDirectory("C:\\Sample1");
if (! class3.get_bSymbolExists(SecSym))
{
class3.AppendISecurity(SecSym, SecName, INTERVAL.Minute60 );
class3.CloseSecurity();
class3.CloseDirectory();
class3.OpenDirectory("C:\\Sample1");
class3.OpenSecurityBySymbol(SecSym);
class3.DataRec(DT, TM, O, H, L, C, (float) V, (float) OI);
class3.CloseSecurity();
class3.CloseDirectory();
}
else if (class3.get_bSymbolExists(SecSym))
{
class2.OpenDirectory("C:\\Sample1");
class2.OpenSecurityBySymbol(SecSym);
class2.SeekToEnd();
class2.Seek(-1);
class2.ReadDay();
int OldTime = class2.iSeTime;
int OldDate = class2.iSeDate;
float OldO = class2.dSeOpen;
float OldH = class2.dSeHigh;
float OldL = class2.dSeLow;
float OldC = class2.dSeClose;
double OldV = class2.dSeVolume;
double OldOI = class2.dSeOpenInterest;
class2.CloseSecurity();
class2.CloseDirectory();
if (OldTime != TM | OldDate != DT)
{
class3.OpenSecurityBySymbol(SecSym);
class3.AppendIData(DT, TM, O, H, L, C, (float) V, (float) OI);
class3.CloseSecurity();
class3.CloseDirectory();
}
else
{
class3.OpenSecurityBySymbol(SecSym);
class3.LastRecord(DT, TM, O, H, L, C, (float) V, (float) OI);
class3.CloseSecurity();
class3.CloseDirectory();
}
}
}
catch (Exception)
{
//MsgBox("Error" & ex1.Message)
}
xyz++;
}
}
catch (Exception)
{
//MsgBox("Error" & ex.Message)
}
}
i am getting an error the error is Access to the path 'C:\test' is denied.
can anyone say me what i need to change in this code.
please help us
Thanks In Advance
精彩评论