This question is answered. Helpful answers available: 0. Correct answers available: 1.


Permlink Replies: 17 - Pages: 2 [ 1 2 | Next ] - Last Post: 8 May 25, 23:01 Last Post By: RobM Threads: [ Previous | Next ]
MarkusD

Posts: 742
Registered: 13-Apr-2006
Tool to find obsolete files in the source folders?
Posted: 8 May 25, 07:24
 
  Click to reply to this thread Reply
Hi Rob (aka the master of jAlbum tools <g>)

would it be possible (for you) to create a tool which searches for files in the source folders of a project which are no longer in use and write the file names to the console?

This would make it possible to create a batch file (in Windows) to delete these files.

We all know that once in a while users (also myself) delete objects outside from jAlbum which leaves files behind which are no longer needed. Its not to save some bytes of disc space but to keep a clean file system. I for myself look into .info files etc. from time to time to search or even edit things outside from jAlbum because is much easier if thousands of files are involved.

As an example.

- Delete the file "..\JAlbum\Samples\Sample Project\Nature\diana-parkhouse-2.jpg" when jAlbum is closed.
- The file "..\JAlbum\Samples\Sample Project\Nature\.jalbum\diana-parkhouse-2.jpg.info" will remain as an orphan file.

The goal of the tool should be to find the file "..\JAlbum\Samples\Sample Project\Nature\.jalbum\diana-parkhouse-2.jpg.info".

Thanks in advance, Markus
RobM

Posts: 3,936
Registered: 4-Aug-2006
Re: Tool to find obsolete files in the source folders?
Posted: 8 May 25, 09:08   in response to: MarkusD in response to: MarkusD
 
  Click to reply to this thread Reply
First, in principle it’s a bad thing to delete files outside of jAlbum. Have you tried searching the root folder of a project with the preference setting ‘Index album objects’ selected?
https://jalbum.net/help/en/jAlbum/Preferences#Search

That will find all files by name or extension.

If that doesn’t work for you I’ll have a look at what’s involved in scripting it.
JeffTucker

Posts: 8,055
Registered: 31-Jan-2006
Re: Tool to find obsolete files in the source folders?
Posted: 8 May 25, 13:16   in response to: RobM in response to: RobM
 
  Click to reply to this thread Reply
RobM wrote:
If that doesn’t work for you I’ll have a look at what’s involved in scripting it.

Shouldn't be too tough to compare the entries in albumfiles.txt to the .info files.

But wading into cache would be a mess. Not sure what Laza does, but I know that in my skins, I make use of the DiskCache() method to stash things there like background music files, font files, background image files, and so on, none of which would appear in the other jAlbum control files (other than appearing as one-liners in the .jap files).
RobM

Posts: 3,936
Registered: 4-Aug-2006
Re: Tool to find obsolete files in the source folders?
Posted: 8 May 25, 14:44   in response to: JeffTucker in response to: JeffTucker
 
  Click to reply to this thread Reply
JeffTucker wrote:
RobM wrote:
If that doesn’t work for you I’ll have a look at what’s involved in scripting it.

Shouldn't be too tough to compare the entries in albumfiles.txt to the .info files.

But wading into cache would be a mess. Not sure what Laza does, but I know that in my skins, I make use of the DiskCache() method to stash things there like background music files, font files, background image files, and so on, none of which would appear in the other jAlbum control files (other than appearing as one-liners in the .jap files).

I’m hoping that the project tree still has an albumObject for the missing files, then I can check if the object’s file exists and if not delete the object, which should delete all of the associated files as well as the entry in albumfiles.txt.

Been out for lunch and now going shopping, so it will have to be tonight at the earliest.
MarkusD

Posts: 742
Registered: 13-Apr-2006
Re: Tool to find obsolete files in the source folders?
Posted: 8 May 25, 18:31   in response to: RobM in response to: RobM
 
  Click to reply to this thread Reply
RobM wrote:
First, in principle it’s a bad thing to delete files outside of jAlbum.
I know. :-)

Have you tried searching the root folder of a project with the preference setting ‘Index album objects’ selected?
https://jalbum.net/help/en/jAlbum/Preferences#Search

That will find all files by name or extension.

I'm not sure if this is a misunderstanding. I don't know what to search for.

If that doesn’t work for you I’ll have a look at what’s involved in scripting it.
Maybe I wasn't clear enough about what I'm after.

In my original example there is one file left, the .info file. I couldn't think of how to search for that file, not from within jAlbum nor outside. Only by comparing the files (pictures, videos etc.) which are actively part of the album and the corresponding .info files.

.info files without a „partner“ are obsolete.

Thanks, Markus
MarkusD

Posts: 742
Registered: 13-Apr-2006
Re: Tool to find obsolete files in the source folders?
Posted: 8 May 25, 18:32   in response to: JeffTucker in response to: JeffTucker
 
  Click to reply to this thread Reply
JeffTucker wrote:
RobM wrote:
If that doesn’t work for you I’ll have a look at what’s involved in scripting it.

Shouldn't be too tough to compare the entries in albumfiles.txt to the .info files.

That sound like a good start.

But wading into cache would be a mess. Not sure what Laza does, but I know that in my skins, I make use of the DiskCache() method to stash things there like background music files, font files, background image files, and so on, none of which would appear in the other jAlbum control files (other than appearing as one-liners in the .jap files).
I agree, trying to also find obsolete cache files could end up in a disaster.

Thanks, Markus
MarkusD

Posts: 742
Registered: 13-Apr-2006
Re: Tool to find obsolete files in the source folders?
Posted: 8 May 25, 18:36   in response to: RobM in response to: RobM
 
  Click to reply to this thread Reply
RobM wrote:
JeffTucker wrote:
RobM wrote:
If that doesn’t work for you I’ll have a look at what’s involved in scripting it.

Shouldn't be too tough to compare the entries in albumfiles.txt to the .info files.

But wading into cache would be a mess. Not sure what Laza does, but I know that in my skins, I make use of the DiskCache() method to stash things there like background music files, font files, background image files, and so on, none of which would appear in the other jAlbum control files (other than appearing as one-liners in the .jap files).

I’m hoping that the project tree still has an albumObject for the missing files, then I can check if the object’s file exists and if not delete the object, which should delete all of the associated files as well as the entry in albumfiles.txt.
Just to make that clear, the tool should not delete the files which are obsolete. Or, at least not by default. :-) For a start just a list of the files would be fine. So one has the chance to evaluate if the found files are really obsolete.

Been out for lunch and now going shopping, so it will have to be tonight at the earliest.
There is definitely no hurry in this matter.

Take your time.

Thanks again. Markus
davidekholm

Posts: 3,684
Registered: 18-Oct-2002
Re: Tool to find obsolete files in the source folders?
Posted: 8 May 25, 19:33   in response to: MarkusD in response to: MarkusD
 
  Click to reply to this thread Reply
Is this tool supposed to be used in case you've deleted images OUTSIDE of jAlbum and are left with various jAlbum specific files under the ".jalbum" folder? Such a cleanup-tool can be made, but isn't it better to simply delete files from within jAlbum?
MarkusD

Posts: 742
Registered: 13-Apr-2006
Re: Tool to find obsolete files in the source folders?
Posted: 8 May 25, 19:57   in response to: davidekholm in response to: davidekholm
 
  Click to reply to this thread Reply
davidekholm wrote:
Is this tool supposed to be used in case you've deleted images OUTSIDE of jAlbum and are left with various jAlbum specific files under the ".jalbum" folder?
Exactly.

Such a cleanup-tool can be made, but isn't it better to simply delete files from within jAlbum?
David, we all know that it's better not to delete files outside of jAlbum. But that's the theory, the reality is different. :-)

Some of my albums are more than 20 years old, so I'm pretty sure that I've a lot of old stuff lurking around.

Thanks, Markus
davidekholm

Posts: 3,684
Registered: 18-Oct-2002
Re: Tool to find obsolete files in the source folders?
Posted: 8 May 25, 20:10   in response to: MarkusD in response to: MarkusD
Helpful
  Click to reply to this thread Reply
Here's a script you can run in jAlbum's system console, or as a tool. It prints all stale .info files in a project:
import se.datadosen.io.*;
 
TreeCollection.of(rootFolder)
  .stream()
  .filter(fld -> fld.folder)
  .forEach(fld) -> {
      var dotJAlbumContents = CachedFile.map(new File(fld.file, ".jalbum"))
      for (Map.Entry<String, File> e : dotJAlbumContents) {
        if (e.key.endsWith(".info") && !e.key.equals(".info")) {
          if (!fld.containsName(IO.baseName(e.key))) {
             println(e.value)
             // e.value.delete() // Uncomment to also delete these stale files
           }
        }
    }
  }
MarkusD

Posts: 742
Registered: 13-Apr-2006
Re: Tool to find obsolete files in the source folders?
Posted: 8 May 25, 20:17   in response to: davidekholm in response to: davidekholm
 
  Click to reply to this thread Reply
Thanks David,

the console gives me:
 
skin property 'use360Player' difference: 'false' vs 'true'
0,008s ==> null


I compiled the album and run the script again. The result in the console:
 
0,008s ==> null


I think I have done something wrong.
davidekholm

Posts: 3,684
Registered: 18-Oct-2002
Re: Tool to find obsolete files in the source folders?
Posted: 8 May 25, 20:19   in response to: MarkusD in response to: MarkusD
 
  Click to reply to this thread Reply
MarkusD wrote:

I compiled the album and run the script again. The result in the console:
 
0,008s ==> null

I think I have done something wrong.


Looks like no stale files then
davidekholm

Posts: 3,684
Registered: 18-Oct-2002
Re: Tool to find obsolete files in the source folders?
Posted: 8 May 25, 20:20   in response to: davidekholm in response to: davidekholm
Helpful
  Click to reply to this thread Reply
Here's an updated version of the script that also list stale cache files. Note that it will also list cache files that have been added by skin scripts:
import se.datadosen.io.*;
 
TreeCollection.of(rootFolder)
  .stream()
  .filter(fld -> fld.folder)
  .forEach(fld) -> {
      var dotJAlbumContents = CachedFile.map(new File(fld.file, ".jalbum"))
      var cacheContents = CachedFile.map(new File(fld.file, ".jalbum/cache"))
      // State .info files
      for (Map.Entry<String, File> e : dotJAlbumContents) {
        if (e.key.endsWith(".info") && !e.key.equals(".info")) {
          if (!fld.containsName(IO.baseName(e.key))) {
             println(e.value)
             // e.value.delete() // Uncomment to also delete these stale files
           }
        }
     }
     // Stale Cache files
     for (Map.Entry<String, File> e : cacheContents) {
        if (!fld.containsName(e.key)) {
           println(e.value)
           // e.value.delete() // Uncomment to also delete these stale files
        }
     }
  }
MarkusD

Posts: 742
Registered: 13-Apr-2006
Re: Tool to find obsolete files in the source folders?
Posted: 8 May 25, 20:25   in response to: davidekholm in response to: davidekholm
 
  Click to reply to this thread Reply
davidekholm wrote:
Looks like no stale files then
You are right, in the sampe album not all pictures have .info files! :-)

Not I got:
 
D:\Eigene Dateien\MDr�ck\Pictures\JAlbum\Samples\Sample Project\Nature\.jalbum\diana-parkhouse-2.jpg.info
0,017s ==> null


I'll try it on one of my own projects.
MarkusD

Posts: 742
Registered: 13-Apr-2006
Re: Tool to find obsolete files in the source folders?
Posted: 8 May 25, 20:34   in response to: davidekholm in response to: davidekholm
 
  Click to reply to this thread Reply
davidekholm wrote:
Here's an updated version of the script that also list stale cache files. Note that it will also list cache files that have been added by skin scripts:

As Jeff said, the cache files are a mine field. By looking at two out of ca. 4,000 stale cache files I saw that these cache files are the "screenshots" for the thumbs of videos. Deleting them would be wrong. :-)
Legend
Forum admins
Helpful Answer
Correct Answer

Point your RSS reader here for a feed of the latest messages in all forums