Check file availability

If you need help on how to use the program
Post Reply
usefamin
Posts: 4
Joined: 2016-03-18 06:21:30

Check file availability

Post by usefamin »

Hello everyone

I was wondering if there's a script that checks the existence of the files in the folder. By which i mean, a script that simply checks the file is still available in the folder or not.

I move files all the time several times a day and the cataloging becomes obsolete without this feature to me (it's actually why I need a tool to keep track of which files are where now).

Would appreciate any help :)
antp
Site Admin
Posts: 9651
Joined: 2002-05-30 10:13:07
Location: Brussels
Contact:

Post by antp »

There is a FileExists function which takes in parameter a file path (string) and returns true or false depending if it exists or not.
So for example if your files paths are in the appropriate field, the following script run on the list will pop a message when a file does not exist:

Code: Select all

program NewScript;
var
  s: String;
begin
  s := GetField(fieldFilePath);
  if FileExists(s) = False then
  begin
    ShowMessage('File does not exist: ' + s);
  end;
end.
usefamin
Posts: 4
Joined: 2016-03-18 06:21:30

Post by usefamin »

Fantastic. Thank you very much.
I don't suppose there's a way to generate a txt log of those files while we're at it? :P
antp
Site Admin
Posts: 9651
Joined: 2002-05-30 10:13:07
Location: Brussels
Contact:

Post by antp »

You mean instead of displaying the message?
Yes that should be possible, by writing a file to a location like the "Find Duplicate" script does
usefamin
Posts: 4
Joined: 2016-03-18 06:21:30

Post by usefamin »

Yes exactly.

I have very limited knowledge when it comes to this and I'm trying to copy the ResultPath :=

But it gives me a unknown identifier error.

Help please? :S
antp
Site Admin
Posts: 9651
Joined: 2002-05-30 10:13:07
Location: Brussels
Contact:

Post by antp »

What error do you have for which code ?
usefamin
Posts: 4
Joined: 2016-03-18 06:21:30

Re: Check file availability

Post by usefamin »

So sorry to never have replied, my laptop was stolen and now two years later I'm stuck with the same issue.
I think I'm just really unable to comprehend the simple terms and strings.

How do I add a string to to the existing script to make it generate a txt file?

Thank you in advance for any help
antp
Site Admin
Posts: 9651
Joined: 2002-05-30 10:13:07
Location: Brussels
Contact:

Re: Check file availability

Post by antp »

Something like this should do it:

Code: Select all

program CheckFiles;
uses
  StringUtils1;
var
  MovList: TStringList;
  s, CurFile, CurMovie: string;
  ResultPath: string;
begin
  if ResultPath = '' then
  begin
    ResultPath := 'c:\list.txt';
    Input('Check files', 'Store results to:', ResultPath);
  end;
  if ResultPath = '' then
  begin
      Error;
  end;
  CurMovie := GetField(fieldOriginalTitle);
  CurFile := GetField(fieldFilePath);
  s := CurMovie + #9 + CurTitle + #9;
  if FileExists(CurFile) then
    s := s + "Yes"
  else
    s := s + "No";  
  MovList.Add(s);
  MovList.SaveToFile(ResultPath);
end.
(not tested)

It is not very efficient because it rewrites the list on each movie, but I don't really know the functions that soulsnake added in 4.x versions that allow to make it otherwise.
Post Reply