How to find multi part rar archives, extract them into their directories and remove them if everything successful

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP











up vote
0
down vote

favorite












I have hundreds of folders with multi part archives inside them.



-FOLDER.1
file.rar
file.r00
file.r01
file.r02
-FOLDER.2
file.rar
file.r00
file.r01


I am using the code below to extract them inside their respective folders and to remove them upon successful extraction,



flock -n locked -c "find . -name '*.rar' -execdir unrar e -o- ; -execdir rm ; && find . -name '*.r[:0-9:][:0-9:]' -exec rm ;"


The problem is if something goes wrong, lets say;



  • One of the parts of the archive is corrupted,

  • Files are not uploaded yet

This script deletes the multi parts even though extracting is not successful. How can improve this script so it deletes rar files and parts if extraction is successful.
I spend my whole morning to figure this out but so far no success.







share|improve this question






















  • how do you expect the event "Files are not uploaded yet" to be detected ?
    – RomanPerekhrest
    Feb 8 at 16:14










  • I am depending on successful extraction on that side.
    – user611811
    Feb 8 at 16:20














up vote
0
down vote

favorite












I have hundreds of folders with multi part archives inside them.



-FOLDER.1
file.rar
file.r00
file.r01
file.r02
-FOLDER.2
file.rar
file.r00
file.r01


I am using the code below to extract them inside their respective folders and to remove them upon successful extraction,



flock -n locked -c "find . -name '*.rar' -execdir unrar e -o- ; -execdir rm ; && find . -name '*.r[:0-9:][:0-9:]' -exec rm ;"


The problem is if something goes wrong, lets say;



  • One of the parts of the archive is corrupted,

  • Files are not uploaded yet

This script deletes the multi parts even though extracting is not successful. How can improve this script so it deletes rar files and parts if extraction is successful.
I spend my whole morning to figure this out but so far no success.







share|improve this question






















  • how do you expect the event "Files are not uploaded yet" to be detected ?
    – RomanPerekhrest
    Feb 8 at 16:14










  • I am depending on successful extraction on that side.
    – user611811
    Feb 8 at 16:20












up vote
0
down vote

favorite









up vote
0
down vote

favorite











I have hundreds of folders with multi part archives inside them.



-FOLDER.1
file.rar
file.r00
file.r01
file.r02
-FOLDER.2
file.rar
file.r00
file.r01


I am using the code below to extract them inside their respective folders and to remove them upon successful extraction,



flock -n locked -c "find . -name '*.rar' -execdir unrar e -o- ; -execdir rm ; && find . -name '*.r[:0-9:][:0-9:]' -exec rm ;"


The problem is if something goes wrong, lets say;



  • One of the parts of the archive is corrupted,

  • Files are not uploaded yet

This script deletes the multi parts even though extracting is not successful. How can improve this script so it deletes rar files and parts if extraction is successful.
I spend my whole morning to figure this out but so far no success.







share|improve this question














I have hundreds of folders with multi part archives inside them.



-FOLDER.1
file.rar
file.r00
file.r01
file.r02
-FOLDER.2
file.rar
file.r00
file.r01


I am using the code below to extract them inside their respective folders and to remove them upon successful extraction,



flock -n locked -c "find . -name '*.rar' -execdir unrar e -o- ; -execdir rm ; && find . -name '*.r[:0-9:][:0-9:]' -exec rm ;"


The problem is if something goes wrong, lets say;



  • One of the parts of the archive is corrupted,

  • Files are not uploaded yet

This script deletes the multi parts even though extracting is not successful. How can improve this script so it deletes rar files and parts if extraction is successful.
I spend my whole morning to figure this out but so far no success.









share|improve this question













share|improve this question




share|improve this question








edited Feb 9 at 7:24

























asked Feb 8 at 15:50









user611811

62




62











  • how do you expect the event "Files are not uploaded yet" to be detected ?
    – RomanPerekhrest
    Feb 8 at 16:14










  • I am depending on successful extraction on that side.
    – user611811
    Feb 8 at 16:20
















  • how do you expect the event "Files are not uploaded yet" to be detected ?
    – RomanPerekhrest
    Feb 8 at 16:14










  • I am depending on successful extraction on that side.
    – user611811
    Feb 8 at 16:20















how do you expect the event "Files are not uploaded yet" to be detected ?
– RomanPerekhrest
Feb 8 at 16:14




how do you expect the event "Files are not uploaded yet" to be detected ?
– RomanPerekhrest
Feb 8 at 16:14












I am depending on successful extraction on that side.
– user611811
Feb 8 at 16:20




I am depending on successful extraction on that side.
– user611811
Feb 8 at 16:20










1 Answer
1






active

oldest

votes

















up vote
0
down vote













The rm commands must be dependent on the result of the unrar command where in your example they are all run sequentially whatever happens.



So try something like that instead (on a test directory first!):



flock -n locked -c "find . -name '*.rar' -print0 | xargs -0 -I FILE sh -c "unrar e -o- FILE && rm FILE `basename FILE .rar`.r[:digit:][:digit:]" "


Then the rmpart is executed only if the unrarcommand finished successfully.



You will need extra quotes if your file names have spaces.






share|improve this answer






















  • Sorry but I am strugling to understand this; Extraction went OK, deleted .rar file but the rest stays. How can I delete the rest of the files "test_file.r[:0-9:]" rm: cannot remove './test_file.rar.r[:0-9:]': No such file or directory
    – user611811
    Feb 9 at 7:19











  • I have edited my answer, it should work for all files from .r00 to .r99
    – Patrick Mevzek
    Feb 9 at 14:11










Your Answer







StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "106"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);

else
createEditor();

);

function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
convertImagesToLinks: false,
noModals: false,
showLowRepImageUploadWarning: true,
reputationToPostImages: null,
bindNavPrevention: true,
postfix: "",
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);



);








 

draft saved


draft discarded


















StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f422843%2fhow-to-find-multi-part-rar-archives-extract-them-into-their-directories-and-rem%23new-answer', 'question_page');

);

Post as a guest






























1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes








up vote
0
down vote













The rm commands must be dependent on the result of the unrar command where in your example they are all run sequentially whatever happens.



So try something like that instead (on a test directory first!):



flock -n locked -c "find . -name '*.rar' -print0 | xargs -0 -I FILE sh -c "unrar e -o- FILE && rm FILE `basename FILE .rar`.r[:digit:][:digit:]" "


Then the rmpart is executed only if the unrarcommand finished successfully.



You will need extra quotes if your file names have spaces.






share|improve this answer






















  • Sorry but I am strugling to understand this; Extraction went OK, deleted .rar file but the rest stays. How can I delete the rest of the files "test_file.r[:0-9:]" rm: cannot remove './test_file.rar.r[:0-9:]': No such file or directory
    – user611811
    Feb 9 at 7:19











  • I have edited my answer, it should work for all files from .r00 to .r99
    – Patrick Mevzek
    Feb 9 at 14:11














up vote
0
down vote













The rm commands must be dependent on the result of the unrar command where in your example they are all run sequentially whatever happens.



So try something like that instead (on a test directory first!):



flock -n locked -c "find . -name '*.rar' -print0 | xargs -0 -I FILE sh -c "unrar e -o- FILE && rm FILE `basename FILE .rar`.r[:digit:][:digit:]" "


Then the rmpart is executed only if the unrarcommand finished successfully.



You will need extra quotes if your file names have spaces.






share|improve this answer






















  • Sorry but I am strugling to understand this; Extraction went OK, deleted .rar file but the rest stays. How can I delete the rest of the files "test_file.r[:0-9:]" rm: cannot remove './test_file.rar.r[:0-9:]': No such file or directory
    – user611811
    Feb 9 at 7:19











  • I have edited my answer, it should work for all files from .r00 to .r99
    – Patrick Mevzek
    Feb 9 at 14:11












up vote
0
down vote










up vote
0
down vote









The rm commands must be dependent on the result of the unrar command where in your example they are all run sequentially whatever happens.



So try something like that instead (on a test directory first!):



flock -n locked -c "find . -name '*.rar' -print0 | xargs -0 -I FILE sh -c "unrar e -o- FILE && rm FILE `basename FILE .rar`.r[:digit:][:digit:]" "


Then the rmpart is executed only if the unrarcommand finished successfully.



You will need extra quotes if your file names have spaces.






share|improve this answer














The rm commands must be dependent on the result of the unrar command where in your example they are all run sequentially whatever happens.



So try something like that instead (on a test directory first!):



flock -n locked -c "find . -name '*.rar' -print0 | xargs -0 -I FILE sh -c "unrar e -o- FILE && rm FILE `basename FILE .rar`.r[:digit:][:digit:]" "


Then the rmpart is executed only if the unrarcommand finished successfully.



You will need extra quotes if your file names have spaces.







share|improve this answer














share|improve this answer



share|improve this answer








edited Feb 9 at 14:11

























answered Feb 8 at 16:47









Patrick Mevzek

2,0131721




2,0131721











  • Sorry but I am strugling to understand this; Extraction went OK, deleted .rar file but the rest stays. How can I delete the rest of the files "test_file.r[:0-9:]" rm: cannot remove './test_file.rar.r[:0-9:]': No such file or directory
    – user611811
    Feb 9 at 7:19











  • I have edited my answer, it should work for all files from .r00 to .r99
    – Patrick Mevzek
    Feb 9 at 14:11
















  • Sorry but I am strugling to understand this; Extraction went OK, deleted .rar file but the rest stays. How can I delete the rest of the files "test_file.r[:0-9:]" rm: cannot remove './test_file.rar.r[:0-9:]': No such file or directory
    – user611811
    Feb 9 at 7:19











  • I have edited my answer, it should work for all files from .r00 to .r99
    – Patrick Mevzek
    Feb 9 at 14:11















Sorry but I am strugling to understand this; Extraction went OK, deleted .rar file but the rest stays. How can I delete the rest of the files "test_file.r[:0-9:]" rm: cannot remove './test_file.rar.r[:0-9:]': No such file or directory
– user611811
Feb 9 at 7:19





Sorry but I am strugling to understand this; Extraction went OK, deleted .rar file but the rest stays. How can I delete the rest of the files "test_file.r[:0-9:]" rm: cannot remove './test_file.rar.r[:0-9:]': No such file or directory
– user611811
Feb 9 at 7:19













I have edited my answer, it should work for all files from .r00 to .r99
– Patrick Mevzek
Feb 9 at 14:11




I have edited my answer, it should work for all files from .r00 to .r99
– Patrick Mevzek
Feb 9 at 14:11












 

draft saved


draft discarded


























 


draft saved


draft discarded














StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f422843%2fhow-to-find-multi-part-rar-archives-extract-them-into-their-directories-and-rem%23new-answer', 'question_page');

);

Post as a guest













































































Popular posts from this blog

How to check contact read email or not when send email to Individual?

Displaying single band from multi-band raster using QGIS

How many registers does an x86_64 CPU actually have?