Results 1 to 2 of 2

Thread: bash script: check for deleted files

  1. #1
    Join Date
    Jul 2006
    Location
    Tschörmany
    Beans
    111
    Distro
    Kubuntu 12.04 Precise Pangolin

    bash script: check for deleted files

    Hey folks. I could use some help with a (bash) script, trying to check for deleted files.

    Problem background:
    I have an extensive video library on disk. All legaly recorded from television with mythtv. I wrote a script to generate an XML file from that library, contaning info on all video files with file size, duration, audio languages, audio- & videocodecs, bitrates, etc.

    To update this XML file, the script currently just throws the old version away and generates a new XML file from scratch, iterating through all directories and all files again, and probably only a couple have changed.

    Having only very little programing experience, the best I could come up with a little help of google was the idea to:
    • Loop through all files with find, put the output of find into an array, store the array into a "storagefile". This file would document all files in the XML at the first run. Then proceed as normal with the first run, generate the XML file.
    • For the next run, only files newer than the date of the first run would need to be added to the XML.
    • However old files, that are now deleted would have to be removed from the XML file. To do so, I would reload the "storagefile" into an array, loop through that array and check if the files are still present on disk. I case a file was in the array, but no longer on disk, it's <video> ... </video> entry would need to be removed from the XML file.


    This however sounds rather complicated to me. Am I missing something? Are there easier options for what I want? Does anyone have some code sniplets for similiar problems, and wants to share with me?

    Thanks in advance for any pointers,

    best regards
    Ares Drake
    Last edited by Ares Drake; September 27th, 2012 at 07:09 PM. Reason: I can't type :-)
    HowTo: Ask Questions the smart way | keep on rockin'...

    GEEK CODE Version: 3.1: GJ/MD d s a- C++ ULS++ P L+++ E---- W++ N* ?o K- w--- ?O M-- V-- PS+>$ PE++>$ Y+ PGP++ t-- 5- X R tv b+ ?DI D+ G++ e+++ h-- r++ y+

  2. #2
    Join Date
    Aug 2011
    Location
    47°9′S 126°43W
    Beans
    2,172
    Distro
    Ubuntu 16.04 Xenial Xerus

    Re: bash script: check for deleted files

    Quote Originally Posted by Ares Drake View Post
    Hey folks. I could use some help with a (bash) script, trying to check for deleted files.

    Problem background:
    I have an extensive video library on disk. All legaly recorded from television with mythtv. I wrote a script to generate an XML file from that library, contaning info on all video files with file size, duration, audio languages, audio- & videocodecs, bitrates, etc.

    To update this XML file, the script currently just throws the old version away and generates a new XML file from scratch, iterating through all directories and all files again, and probably only a couple have changed.
    Having only very little programing experience, the best I could come up with a little help of google was the idea to:
    • Loop through all files with find, put the output of find into an array, store the array into a "storagefile". This file would document all files in the XML at the first run. Then proceed as normal with the first run, generate the XML file.
    • For the next run, only files newer than the date of the first run would need to be added to the XML.
    • However old files, that are now deleted would have to be removed from the XML file. To do so, I would reload the "storagefile" into an array, loop through that array and check if the files are still present on disk. I case a file was in the array, but no longer on disk, it's <video> ... </video> entry would need to be removed from the XML file.


    This however sounds rather complicated to me. Am I missing something? Are there easier options for what I want? Does anyone have some code sniplets for similiar problems, and wants to share with me?

    Thanks in advance for any pointers,

    best regards
    Ares Drake
    If I were to do the same, I would keep an XML stub for each file in the same directory of that file (ie foo.mp4 would have a foo.xml) (or in a "shadow" directory structure elsewhere, or in any file structure/naming convention that makes it simple to go from video to xml and vice-versa).

    Then to rebuild:
    - for each xml, if there is no video, remove the xml
    - for each video, if there is no xml or if the xml is older, rebuild the xml
    - collect all the xml and build the final xml from them.

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •