PDA

View Full Version : Same filenames in one folder



Guy Danneels
08-07-2007, 05:00 PM
Hello,
I need a way to warn my users that they have two or more files with the same name (different extentions) in a known folder.
Is there an easy way for me as a novice, to write (or get) that code?
Could someone help me on this??

macko
08-07-2007, 07:33 PM
it is possible but i think it would take time to create the command for that.

Guy Danneels
08-08-2007, 03:21 AM
Hi Macko,
I don't know how to write those codes but I think that probably the sollution could be done via a table, loading all the files of the folder (some 120 files) without the extentions, sorting them alfab., and then check them out one by one against the other files in the table. And then just warn the user if a match was found. (It would be nice if the user could know which files...)
Something like that... I suppose...
But I can't find out how to start...
Thanks anyway for your reply.

mz241508
08-08-2007, 05:26 AM
Hey Guy Danneels,

Try the following code i have done for you:

Put the following code in your projects Global Event:

function chkFE(cFilename, cFolder)
result = File.Find(cFolder, "*.*", false, false, nil, nil);
if (result ~= nil) then
file_table = {};
for index, path in result do
spath = String.SplitPath(path);
fname = spath.Filename;
Table.Insert(file_table, Table.Count(file_table)+1, fname);
end
end

filec = Table.Concat(file_table, ";", 1, TABLE_ALL);
firstfind = String.Find(filec, cFilename, 1, false);
secondfind = String.Find(filec, cFilename, firstfind+String.Length(cFilename), false);

if secondfind ~= -1 then
if String.Mid(filec, secondfind, String.Find(filec, ";", secondfind)) == cFilename then
Dialog.Message("WARNING!", "You have two files that has the same filename with different extensions!", MB_OK, MB_ICONEXCLAMATION, MB_DEFBUTTON1);
else
Dialog.Message("WARNING!", "You have multiple files that has the same filename with different extensions!", MB_OK, MB_ICONEXCLAMATION, MB_DEFBUTTON1);
end
end
end

Put the following code where you want to call the function:

-- chkFE(Filename to check, Folder to check in);

chkFE("filename", _DesktopFolder.."\\folder\\");

Hope this is what your looking for. ;)

Guy Danneels
08-08-2007, 06:47 AM
Thanks, mz241508 for your code.
Some few problems: I have to give in each filename in the functioncall, so for each folder... together that's more than 225 times for each user per screen I made... that's far beyond 2500 times...
Other problem: the code warns the user that the same filename was found, even if the files are like: "myFILE.txt" - "alsoFILExx.doc" - "otherFILE.pdf".
It should only warn the user if files are in the same folder like: "myfile.txt" - "myfile.doc" - "myfile.pdf" etc.
Should it be possible that I only have to give in the folder where your code takes it over: reading the files in the folder, put them in a table, and then automaticly checks each filename to find out if there are filenames with the exact same name, but different extentions?
Am I not asking too much? Is it possible?

Guy Danneels
08-09-2007, 01:24 PM
Hello to all of you,
I have searched for days on the forum; nowhere that I could find a solution...
Is there someone who can help me out, please??????

wasim21k
08-10-2007, 03:45 AM
i m not sure but i think file serch would do the job.
i mean try to fine file but with file name and use * in ext.