File Type Finder
Author |
Message |
TheXploder
|
Posted: Sat Feb 07, 2004 11:02 am Post subject: File Type Finder |
|
|
I made a program that reads files in a folder and puts them into an array...:
code: |
var streamNumber : int
var size, attribute, fileTime : int
var fullFileName, fileLength : string := ""
var Semicolon : int := 0
var fileNum := 1
var Folder : string := "New Folder"
proc LoadFile
fileLength := ""
streamNumber := Dir.Open (Folder)
assert streamNumber > 0
loop
Dir.GetLong (streamNumber, fullFileName, size, attribute, fileTime)
exit when fullFileName = ""
fileLength := fileLength + fullFileName + ";"
end loop
Dir.Close (streamNumber)
end LoadFile
LoadFile
for i : 1 .. length (fileLength)
if fileLength (i) = ";" and fileLength (i + 1) not= chr (46) then
fullFileName := fileLength (i + 1 .. *)
exit
end if
end for
for i : 1 .. length (fileLength)
if i < length (fileLength) then
if fileLength (i) = ";" and fileLength (i + 1) not= chr (46) then
Semicolon := Semicolon + 1
end if
end if
end for
put "Files Found: ", Semicolon
put "-------------------------"
var fileNames : array 1 .. Semicolon of string
var fileName : array 1 .. Semicolon of string
for i : 1 .. Semicolon
fileNames (i) := ""
fileName (i) := ""
end for
for a : 1 .. length (fullFileName)
if fullFileName (a) = ";" then % Next File
fileNum += 1
else
fileName (fileNum) += fullFileName (a)
end if
end for
for i : 1 .. Semicolon
put fileName (i)
end for
|
anyway I could make that shorter? |
|
|
|
|
|
Sponsor Sponsor
|
|
|
TheXploder
|
Posted: Sat Feb 07, 2004 12:24 pm Post subject: (No subject) |
|
|
Here is an update, this finds .exe files... you could change that to any other file types of course if your going to make a paint program that allows to only view one file type... It's very useful..
Just make the a folder called "New Folder" in the same folder that you save this.. and make a bunch of file types.. and some .exe files, when you run it he'll read all the file names and add them into an array, from that array it reads all the file names and picks out .exe files...
code: |
var streamNumber : int
var size, attribute, fileTime : int
var fullFileName, fileLength : string := ""
var Semicolon : int := 0
var fileNum := 1
var exeFound := 0
var Folder : string := "New Folder"
proc LoadFile
fileLength := ""
streamNumber := Dir.Open (Folder)
assert streamNumber > 0
loop
Dir.GetLong (streamNumber, fullFileName, size, attribute, fileTime)
exit when fullFileName = ""
fileLength := fileLength + fullFileName + ";"
end loop
Dir.Close (streamNumber)
end LoadFile
LoadFile
for i : 1 .. length (fileLength)
if fileLength (i) = ";" and fileLength (i + 1) not= chr (46) then
fullFileName := fileLength (i + 1 .. *)
exit
end if
end for
for i : 1 .. length (fileLength)
if i < length (fileLength) then
if fileLength (i) = ";" and fileLength (i + 1) not= chr (46) then
Semicolon := Semicolon + 1
end if
end if
end for
put "Files Found: ", Semicolon
put "-------------------------"
var fileName : array 1 .. Semicolon of string
var fileType : array 1 .. Semicolon of string
for i : 1 .. Semicolon
fileName (i) := ""
end for
for i : 1 .. Semicolon
fileType (i) := ""
end for
for a : 1 .. length (fullFileName)
if fullFileName (a) = ";" then % Next File
fileNum += 1
else
fileName (fileNum) += fullFileName (a)
end if
end for
put Semicolon
for b : 1 .. Semicolon
for a : 1 .. length (fileName (b))
if fileName (b) (a) = "." then % Next File
fileType (b) := fileName (b) (a .. *)
end if
end for
end for
for i : 1 .. Semicolon
put fileName (i)
end for
put "-----------"
for i : 1 .. Semicolon
if fileType (i) = ".exe" then
exeFound := exeFound + 1
end if
end for
put ".exe Files Found: ",exeFound
|
again if you find a way to shorten this please share.. |
|
|
|
|
|
Delta
|
Posted: Sat Feb 07, 2004 7:40 pm Post subject: (No subject) |
|
|
Ok... I ran it but I got an error...
dynamic array upper bound is less than lower bound
I take it that only happens if no files are found right?... well you should really fix that
ummm... this is a little shorter.... but its only part of it... paste it over everything from put "Files Found:",Semicolon to the end
code: | put "Files Found: ", Semicolon
put "-------------------------"
var fileName, fileType : array 1 .. Semicolon of string
for i : 1 .. Semicolon
fileName (i) := ""
fileType (i) := ""
end for
for a : 1 .. length (fullFileName)
if fullFileName (a) = ";" then % Next File
fileNum += 1
else
fileName (fileNum) += fullFileName (a)
end if
end for
put Semicolon
for b : 1 .. Semicolon
for a : 1 .. length (fileName (b))
if fileName (b) (a) = "." then % Next File
fileType (b) := fileName (b) (a .. *)
end if
end for
put fileName (b)
if fileType (b) = ".exe" then
exeFound := exeFound + 1
end if
end for
put "-----------"
put ".exe Files Found: ",exeFound |
|
|
|
|
|
|
GUI.GetScrollBarWidth : i
|
Posted: Fri Feb 13, 2004 6:19 pm Post subject: (No subject) |
|
|
good prog, u deserve some bits. but i can't give up any of my presoius, so i guess u get none for now |
|
|
|
|
|
Andy
|
Posted: Sat Feb 14, 2004 5:33 pm Post subject: (No subject) |
|
|
OMG... GUI.GetScrollBarWidth :i, you are a moron... dont spam in GD!!! if only i had my bit powers back... |
|
|
|
|
|
|
|