Find "orphaned" files, how to?

English support forum

Moderators: white, Hacker, petermad, Stefan2

Post Reply
bwh
Junior Member
Junior Member
Posts: 12
Joined: 2006-05-30, 08:27 UTC

Find "orphaned" files, how to?

Post by *bwh »

Hello all,

I've been using TC for years now and it just occurred to me that one of you guys can help me solve a problem of mine using TC :)

I have a program that creates pictures and .nfo files for my series and movies. But when I sometimes delete a few of the movies the associated files don't necessarily get deleted.
So I have some "orphaned"
lovely_movie.jpg
lovely_movie.nfo
files even if te lovely_movie.mkv has been deleted.

I know its situational (mkv,avi,mp4,etc), but I'd like to try my luck :)
User avatar
tuska
Power Member
Power Member
Posts: 3755
Joined: 2007-05-21, 12:17 UTC

Post by *tuska »

Hi,
Somewhere in the forum I found this solution (don't know where).

Code:

TOTALCMD#BAR#DATA
cm_SelectCurrentName,cm_ShowOnlySelected,cm_ClearAll

wcmicons.dll,73
Menu "Show" - "Only selected files" |Same name (but different extensions) as the one under the cursor

0
-1

Copy and paste the above code on an empty space on your buttonbar.
Point on one file and press the button.
File names with different extensions are selected.

CTRL+R Reread Source

Kind regards,
Karl
User avatar
milo1012
Power Member
Power Member
Posts: 1158
Joined: 2012-02-02, 19:23 UTC

Re: Find "orphaned" files, how to?

Post by *milo1012 »

2bwh
Are you able to list only the relevant files, i.e. can you use TC's search (Alt+F7), Branch View (Ctrl+B), selected Branch View (Ctrl+Shift+B) etc. to make TC only show

Code: Select all

orphaned_movie.jpg
orphaned_movie.nfo
non_orphaned_movie.jpg
non_orphaned_movie.nfo
non_orphaned_movie.mkv
...
in the file list?
If yes, you could do the following:
1. select (via Numpad+ or menu):

Code: Select all

*.mkv *.mp4 *.avi>*.jpg *.nfo
Now all non-orphaned file pairs/triplets are selected.
All you need to do is to invert the selection (Numpad * or menu), and all orphaned files would be selected.


Explanation:
TC help 'Selecting files' wrote:New: You can now select related files. For example, you would want to select all RAW image files (.cr2), but only if there is a jpg file in the same directory. This can be done with the following selection string:
*.jpg>*.cr2
This also supports more complex naming schemes. For example, if the jpg file is named IMG_1057.JPG and the raw file CRW_1057.CR2, the selection string would have to be:
*.jpg>crw*.cr2
TC plugins: PCREsearch and RegXtract
User avatar
Stefan2
Power Member
Power Member
Posts: 4157
Joined: 2007-09-13, 22:20 UTC
Location: Europa

DOS Batch: Find "orphaned" files, how to?

Post by *Stefan2 »

bwh wrote:...when I sometimes delete a few of the movies
the associated files don't necessarily get deleted.

So I have some "orphaned"
lovely_movie.jpg
lovely_movie.nfo

files even if te lovely_movie.mkv has been deleted.


Here a simple batch for that task.
For each X.jpg,... if Not X.mks existent,... Delete X.jpg
For each X.nfo,... if Not X.mks existent,... Delete X.nfo

Code: Select all

@ECHO OFF
GoTo START

-------------------
Hulk.jpg
Hulk.nfo
Hulk.mkv
-------------------
Spiderwomen 2.jpg
Spiderwomen 2.nfo
-------------------
Die Brücke 3.jpg
Die Brücke 3.nfo
Die Brücke 3.mkv
-------------------
Der Ölprinz 4.jpg
Der Ölprinz 4.nfo
-------------------


:START
REM For each X.jpg, if Not X.mks exists, Delete X.jpg
REM For each X.nfo, if Not X.mks exists, Delete X.nfo

setLocal EnableDelayedExpansion
For /f "delims=" %%F in ('dir /B *.jpg') Do (
    SET BASE=%%~nF
	IF NOT EXIST "!BASE!.mkv" (ECHO DEL "%%F")
)
For /f "delims=" %%F in ('dir /B *.NFO') Do (
    SET BASE=%%~nF
	IF NOT EXIST "!BASE!.mkv" (ECHO DEL "%%F")
)
PAUSE
GoTo :EOF

-------------------
Result:
c:\temp\TCTemp\5>Find-Delete-Orphans.cmd
DEL "Der Ölprinz 4.jpg"
DEL "Spiderwomen 2.jpg"
DEL "Der Ölprinz 4.nfo"
DEL "Spiderwomen 2.nfo"

c:\temp\TCTemp\5>
-------------------




Or...

Collect all Orphans in a text file and utilize than cm_LoadSelectionFromFile=2032;Read file selection from file

Code: Select all

@ECHO OFF 
SET FileList=aaaaaa_Orphans.txt
IF EXIST %FileList% DEL %FileList%

CHCP 1252
setLocal EnableDelayedExpansion
For /f "delims=" %%F in ('dir /B *.jpg') Do (
    SET BASE=%%~nF
   IF NOT EXIST "!BASE!.mkv" (ECHO %%F>> %FileList%)
)
For /f "delims=" %%F in ('dir /B *.NFO') Do (
    SET BASE=%%~nF
   IF NOT EXIST "!BASE!.mkv" (ECHO %%F>> %FileList%)
)
NOTEPAD %FileList%
ECHO In TC use cm_LoadSelectionFromFile=2032;Read file selection from file
ECHO Perhaps followed by cm_ShowOnlySelected ? (See TOTALCMD.INC file for more)
PAUSE 
"aaaaaa_Orphans.txt" contains now:
Der Ölprinz 4.jpg
Spiderwomen 2.jpg
Der Ölprinz 4.nfo
Spiderwomen 2.nfo


Usage:
Execute the batch in your folder with movies.
Paste cm_LoadSelectionFromFile in TC command line, select aaaaaa_Orphans.txt.
Result: all orphaned files are selected now.



- - -

milo1012's selection trick works well too.

I have played around a bit and added another EM_cmd in my usercmd.ini:
[em_MKV]
cmd=SelectfilesU *.mkv *.mp4 *.avi>*.jpg *.nfo

Now select all files in the movie folder first,
next execute em_MKV in TC command line,
and done, only orphaned files are selected (but unrelated files too if there are any :cry: ).



 
Help wrote:14. SELECTFILES file types marks files of the given type, e.g. SELECTFILES *.txt *.doc
Supported modifiers:
D=only folders, B=both, U=unselect,
L=left side, R=right side, T=target panel,
S=Reverts whether just files or files+folders are selected when Shift is pressed during execution.


 
Post Reply