|
|
|||||||||
|
|||||||||
| |||||||||
|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
#1
|
||||
|
||||
|
Pascal help please: loop through files in directory
I have made a program that searches a folder for .txt files that only have one character as a name, like "a.txt" or "K.txt". Sounds stupid I know but it is just a test, if i get it to work then i will make it more useful. Anyway, my problem is that if I for instance have the file "a.txt" in the folder then the programs says that I have "a.txt AND "A.txt" wich is very odd
Take a look.Code:
program muuuu;
uses
crt;
var
i : integer;
yesno : boolean;
janej : char;
procedure search;
const
format = '.txt';
var
a,b,c : array [0..255] of char;
filnamn : string;
antal, x : integer;
function exists(filnamn:string):boolean;
var
fil : text;
begin
exists := false;
assign(fil,filnamn);
{$I-}reset(fil);{$I+}
if IOResult = 0 then begin
close(fil);
writeln(filnamn);
exists := true;
end;
end;
begin
antal := 0;
for x := 1 to 255 do begin
a[x] := chr(x);
filnamn := a[x]+format;
if exists(filnamn) then
inc(antal);
end;
writeln('There are ',antal,' files in this folder.');
end;
begin
clrscr;
writeln('Do you want to scan folder?');
readln(janej);
if janej in ['Y','y'] then begin
clrscr;
writeln('The files are as follows:');
search;
end
else
halt;
readln();
end.
|
|
#2
|
||||
|
||||
|
Code:
procedure search;
const
format = '.txt';
var
a,b,c : array [0..255] of char;
filnamn : string;
antal, x : integer;
-- snip --
begin
antal := 0;
for x := 1 to 255 do begin
a[x] := chr(x);
filnamn := a[x]+format;
if exists(filnamn) then
inc(antal);
end;
writeln('There are ',antal,' files in this folder.');
end;
To avoid this, look at an ASCII chart (specifically the numbers beside the characters) and modify your loop so that you're only looking at upper case, or only looking at lower case.
__________________
Web Design Tips - Posting and You If I've been helpful, and/or you're really nice, consider buying something from my Amazon.com wishlist.
|
|
#3
|
||||
|
||||
|
So you are saying its best to make one procedure that only checks for small letters and then one that only checks for big letters? I thought that that wouldnt be needed since for instance 'a' and 'A' do have different ASCII values and thus should not be taken for the same thing?
|
|
#4
|
||||
|
||||
|
Windows isn't case sensitive. On windows a you can call a file a.txt and then you can refer to it either as a.txt or A.TXT or anything in between. Not case sensitive, but the same file.
__________________
~James [Not currently seeking freelance work] Like philosophy or interested in spirituality? Philosophorum. Game Dev Experts Forums Foresight Linux - Because your desktop should be cool! Linux FAQ FedoraFAQ UbuntuGuide |
|
#5
|
||||
|
||||
|
Is that Turbo Pascal (or Borland Pascal)? If so, try using FindFirst and FindNext procedures.
__________________
Up the Irons What Would Jimi Do? Smash amps. Burn guitar. Take the groupies home. "Death Before Dishonour, my Friends!!" - Bruce D ickinson, Iron Maiden Aug 20, 2005 @ OzzFest Down with Sharon Osbourne Puzzle of the Month solved by sizeablegrin, etienne141 and L7Sqr, superior C/C++ programmers of the month |
|
#6
|
||||
|
||||
|
Quote:
As LP reiterated, Windows is not case sensitive. If you were on any unix derivative however, it would be case sensitive. |
|
#7
|
||||
|
||||
|
Aight, thx, and I use Free Pascal.
|
![]() |
| Viewing: Dev Shed Forums > Programming Languages - More > Other Programming Languages > Pascal help please: loop through files in directory |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|