تجميع ملفات في ملف واحد
#1
سلام الله عليكم

لدي حلقة بحث تتكون من متغيرين اليوم و المسلك
كود :
begin x:=0; fichierTmp.Clear ; if FileExists(ListBox1.Items.Strings[x]+ 'File.' + IntToHex(StrToInt(FormatDateTime('m',cptDate)),00)+ FormatDateTime('dd',cptDate)) then begin for i:= 0 to ListBox1.Count -1 do {fixer la date est varié le chemin} begin fichierTmp.Clear; fichierTmp.LoadFromFile( ListBox1.Items.Strings[i]+ 'File.' + IntToHex(StrToInt(FormatDateTime('m',cptDate)),00)+ FormatDateTime('dd',cptDate)) ; fichierFinal.AddStrings( fichierTmp ) ; end; i:=i+1; end;// else ShowMessage('no existe'); cptDate := cptDate + 1; x:=x+1; end ;

لما لا أجد في الشرط الملف المقصود if FileExists(ListBox1.Items.Strings[x]+ 'File.' + IntToHex(StrToInt(FormatDateTime('m',cptDate)),00)+FormatDateTime('dd',cptDate))
فأنا مطظر لتخطي كامل الحلقة التي تليها و بالتالي أفقد ملفات داخل هذه الحلقة.
كيف لي أن أتفادى هذا المشكل
الحلقة المقصودة هي :
كود :
for i:= 0 to ListBox1.Count -1 do begin fichierTmp.Clear; fichierTmp.LoadFromFile( ListBox1.Items.Strings[i]+ 'File.' + IntToHex(StrToInt(FormatDateTime('m',cptDate)),00)+ FormatDateTime('dd',cptDate)) ; fichierFinal.AddStrings( fichierTmp ) ; end; i:=i+1;
أدبني الدهر فأراني نقص عقلي وإذا ما ازددت علما زادني علما بجهلي
الرد
#2
وعليكم السلام ورحمة الله
كود :
for[COLOR=Green] i:= 0[/COLOR] [COLOR=Red]to[/COLOR][COLOR=Green] ListBox1.Count -1[/COLOR] do .. .. [COLOR=Blue]// i:=i+1;[/COLOR]
بالتوفيق
الرد
#3
سلام الله عليكم

لم أفهم قصدك أخي عبد الجليل
المتغير I هو نفسه المتغير x في حالتي لاحظ معي :
PHP كود :
if FileExists(ListBox1.Items.Strings[x] 
لو فرضنا أن x=0 تعطينا File.txt /:C وهذا الملف غير موجود سيخرج التنفيذ من الحلقة IF و بذلك تخطينا الحلقة الثانية If التي تحتوي على المتغير I و هنا تكمن المشكلة فكل مسلك من
PHP كود :
for  i:= 1 to ListBox1.Count -1 do 
لم نجربه
أدبني الدهر فأراني نقص عقلي وإذا ما ازددت علما زادني علما بجهلي
الرد
#4
السلام عليكم ورحمة الله

الخطأ هنا
إقتباس :fixer la date est varié le chemin
المفروص يكون العكس le chemin est fixe varié la date

هنا
كود :
if FileExists([color=Red]ListBox1.Items.Strings[x][/color]+ 'File.' + .....
المتغير x اخذ قيمة فلا يمكنك كتابة هذا لانه تناقض
كود :
fichierTmp.LoadFromFile( [color=#ff0000]ListBox1.Items.Strings[i][/color]+....
الرد
#5
[FONT="Comic Sans MS"]هذا الكود إشتغل معي شكرا لك اخي
كود :
var cptDate : TDate ;x,i:Integer; fichierTmp, fichierFinal : TStringList ; begin //initialisation du compteur de Date (DateTimePicker1) cptDate := DateTimePicker1.DateTime; //Création des TStringList fichierTmp := TStringList.Create ; fichierFinal := TStringList.Create; //Boucle tant que l'on a pas atteint la Date supérieure (DateTimePicker2) while cptDate < DateTimePicker2.DateTime do begin fichierTmp.Clear ; // on vide le contenu for i:= 0 to ListBox1.Count -1 do begin fichierTmp.Clear; if fileExists(ListBox1.Items.Strings[i]+ ‘File.' + IntToHex(StrToInt(FormatDateTime('m',cptDate)),00)+FormatDateTime('dd',cptDate)) then Begin {fixer la date est varié le chemin} fichierTmp.LoadFromFile( ListBox1.Items.Strings[i]+ ‘File.' + IntToHex(StrToInt(FormatDateTime('m',cptDate)),00)+FormatDateTime('dd',cptDate)) ; //Chargement du fichier fichierFinal.AddStrings( fichierTmp ) ; // Ajout du fichier chargé au fichier final end; end ; cptDate := cptDate + 1; //Incrémentation de la date end ; fichierFinal.SaveToFile( 'C:\fichierFinal.txt' ) ; //Sauvegarde du fichier Final //Libération des ressources fichierTmp.Free; fichierFinal.Free; end;
أدبني الدهر فأراني نقص عقلي وإذا ما ازددت علما زادني علما بجهلي
الرد


التنقل السريع :


يقوم بقرائة الموضوع: بالاضافة الى ( 1 ) ضيف كريم