Delete multiple files from multiple zip archives











up vote
0
down vote

favorite












I have a list of files which I need to delete from multiple years' worth of monthly file archives.
there are about 400+ file names in a text file, and about 5 years of monthly archives, sorted into folders by year.



my script does a double loop, looking for each file in each archive and deleting it, but it's insaaaanely slow.
I'm looking for any suggestions of what I can do to improve my approach. thanks!



set-alias rar "C:Program Files7-Zip7z.exe"

$archives = get-childitem 'D:Archive DataAPP_PwebsiteDocumentexportsExports ArchiveArchive2014exports' -Recurse
write-host $archives
Get-Alias rar

foreach ($archive in $archives ) {

write-host $archive.Mode

$exports = Get-Content C:scriptsScottTrade_cleanup.txt.txt
foreach ($export in $exports){
write-host $export
rar d $archive.FullName $export -r

}

}









share|improve this question


















  • 1




    $exports = Get-Content C:scriptsScottTrade_cleanup.txt.txt could be done outside any loop I think
    – UnhandledExcepSean
    Nov 12 at 17:13










  • ForFiles /p "C:My Folder" /s /d -30 /c "cmd /c del @file"
    – Bryro
    Nov 12 at 17:19






  • 1




    7Z supports a @listfile so hand over the list of files to delete instead of iterating manually, which involves loading 7z.exe over and over again.
    – LotPings
    Nov 12 at 17:19










  • I think i am a little confused. You are trying to delete files inside zip files? Also what version of .net are you running
    – ArcSet
    Nov 12 at 17:23

















up vote
0
down vote

favorite












I have a list of files which I need to delete from multiple years' worth of monthly file archives.
there are about 400+ file names in a text file, and about 5 years of monthly archives, sorted into folders by year.



my script does a double loop, looking for each file in each archive and deleting it, but it's insaaaanely slow.
I'm looking for any suggestions of what I can do to improve my approach. thanks!



set-alias rar "C:Program Files7-Zip7z.exe"

$archives = get-childitem 'D:Archive DataAPP_PwebsiteDocumentexportsExports ArchiveArchive2014exports' -Recurse
write-host $archives
Get-Alias rar

foreach ($archive in $archives ) {

write-host $archive.Mode

$exports = Get-Content C:scriptsScottTrade_cleanup.txt.txt
foreach ($export in $exports){
write-host $export
rar d $archive.FullName $export -r

}

}









share|improve this question


















  • 1




    $exports = Get-Content C:scriptsScottTrade_cleanup.txt.txt could be done outside any loop I think
    – UnhandledExcepSean
    Nov 12 at 17:13










  • ForFiles /p "C:My Folder" /s /d -30 /c "cmd /c del @file"
    – Bryro
    Nov 12 at 17:19






  • 1




    7Z supports a @listfile so hand over the list of files to delete instead of iterating manually, which involves loading 7z.exe over and over again.
    – LotPings
    Nov 12 at 17:19










  • I think i am a little confused. You are trying to delete files inside zip files? Also what version of .net are you running
    – ArcSet
    Nov 12 at 17:23















up vote
0
down vote

favorite









up vote
0
down vote

favorite











I have a list of files which I need to delete from multiple years' worth of monthly file archives.
there are about 400+ file names in a text file, and about 5 years of monthly archives, sorted into folders by year.



my script does a double loop, looking for each file in each archive and deleting it, but it's insaaaanely slow.
I'm looking for any suggestions of what I can do to improve my approach. thanks!



set-alias rar "C:Program Files7-Zip7z.exe"

$archives = get-childitem 'D:Archive DataAPP_PwebsiteDocumentexportsExports ArchiveArchive2014exports' -Recurse
write-host $archives
Get-Alias rar

foreach ($archive in $archives ) {

write-host $archive.Mode

$exports = Get-Content C:scriptsScottTrade_cleanup.txt.txt
foreach ($export in $exports){
write-host $export
rar d $archive.FullName $export -r

}

}









share|improve this question













I have a list of files which I need to delete from multiple years' worth of monthly file archives.
there are about 400+ file names in a text file, and about 5 years of monthly archives, sorted into folders by year.



my script does a double loop, looking for each file in each archive and deleting it, but it's insaaaanely slow.
I'm looking for any suggestions of what I can do to improve my approach. thanks!



set-alias rar "C:Program Files7-Zip7z.exe"

$archives = get-childitem 'D:Archive DataAPP_PwebsiteDocumentexportsExports ArchiveArchive2014exports' -Recurse
write-host $archives
Get-Alias rar

foreach ($archive in $archives ) {

write-host $archive.Mode

$exports = Get-Content C:scriptsScottTrade_cleanup.txt.txt
foreach ($export in $exports){
write-host $export
rar d $archive.FullName $export -r

}

}






powershell






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Nov 12 at 17:07









llirik42

102




102








  • 1




    $exports = Get-Content C:scriptsScottTrade_cleanup.txt.txt could be done outside any loop I think
    – UnhandledExcepSean
    Nov 12 at 17:13










  • ForFiles /p "C:My Folder" /s /d -30 /c "cmd /c del @file"
    – Bryro
    Nov 12 at 17:19






  • 1




    7Z supports a @listfile so hand over the list of files to delete instead of iterating manually, which involves loading 7z.exe over and over again.
    – LotPings
    Nov 12 at 17:19










  • I think i am a little confused. You are trying to delete files inside zip files? Also what version of .net are you running
    – ArcSet
    Nov 12 at 17:23
















  • 1




    $exports = Get-Content C:scriptsScottTrade_cleanup.txt.txt could be done outside any loop I think
    – UnhandledExcepSean
    Nov 12 at 17:13










  • ForFiles /p "C:My Folder" /s /d -30 /c "cmd /c del @file"
    – Bryro
    Nov 12 at 17:19






  • 1




    7Z supports a @listfile so hand over the list of files to delete instead of iterating manually, which involves loading 7z.exe over and over again.
    – LotPings
    Nov 12 at 17:19










  • I think i am a little confused. You are trying to delete files inside zip files? Also what version of .net are you running
    – ArcSet
    Nov 12 at 17:23










1




1




$exports = Get-Content C:scriptsScottTrade_cleanup.txt.txt could be done outside any loop I think
– UnhandledExcepSean
Nov 12 at 17:13




$exports = Get-Content C:scriptsScottTrade_cleanup.txt.txt could be done outside any loop I think
– UnhandledExcepSean
Nov 12 at 17:13












ForFiles /p "C:My Folder" /s /d -30 /c "cmd /c del @file"
– Bryro
Nov 12 at 17:19




ForFiles /p "C:My Folder" /s /d -30 /c "cmd /c del @file"
– Bryro
Nov 12 at 17:19




1




1




7Z supports a @listfile so hand over the list of files to delete instead of iterating manually, which involves loading 7z.exe over and over again.
– LotPings
Nov 12 at 17:19




7Z supports a @listfile so hand over the list of files to delete instead of iterating manually, which involves loading 7z.exe over and over again.
– LotPings
Nov 12 at 17:19












I think i am a little confused. You are trying to delete files inside zip files? Also what version of .net are you running
– ArcSet
Nov 12 at 17:23






I think i am a little confused. You are trying to delete files inside zip files? Also what version of .net are you running
– ArcSet
Nov 12 at 17:23














1 Answer
1






active

oldest

votes

















up vote
0
down vote



accepted










So you have a minor performance issue with



$exports = Get-Content C:scriptsScottTrade_cleanup.txt.txt


Move that outside the loops



The big problem is that you are reloading a zip for every file you are seeking to delete. We need to fix this. Take your file that is a list of files, get rid of the inner loop and run this:



rar d $archive.FullName -r @FullListFilePathNameExtension


My first solution was to use the include switch (-i) with the delete, but Windows doesn't support command line over 8k.






share|improve this answer























  • So, if i'm supplying a full list of files to delete for each archive after the -r, then there's really no need for me to read in the list of files into the $exports variable. right?
    – llirik42
    Nov 12 at 17:45










  • @llirik42 Yes, good catch
    – UnhandledExcepSean
    Nov 12 at 17:59










  • this almost works - except powershell seems to be unhappy with the @, and may be reading it as a declaration of an array. set-alias rar "C:Program Files7-Zip7z.exe" $archives = get-childitem 'd:scripts' -Recurse foreach ($archive in $archives ) { rar d $archive.FullName @C:scriptsScottTrade_cleanup.txt } Unrecognized token in source text. At line:7 char:60
    – llirik42
    Nov 12 at 18:02












  • quotes fixed it. I think we're good. thanks a ton!
    – llirik42
    Nov 12 at 18:18










  • @llirik42 it should be like 400 times faster; report back on the improvement if you would please; I'm curious about the gain
    – UnhandledExcepSean
    Nov 12 at 18:21











Your Answer






StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");

StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
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: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














 

draft saved


draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53266934%2fdelete-multiple-files-from-multiple-zip-archives%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes








up vote
0
down vote



accepted










So you have a minor performance issue with



$exports = Get-Content C:scriptsScottTrade_cleanup.txt.txt


Move that outside the loops



The big problem is that you are reloading a zip for every file you are seeking to delete. We need to fix this. Take your file that is a list of files, get rid of the inner loop and run this:



rar d $archive.FullName -r @FullListFilePathNameExtension


My first solution was to use the include switch (-i) with the delete, but Windows doesn't support command line over 8k.






share|improve this answer























  • So, if i'm supplying a full list of files to delete for each archive after the -r, then there's really no need for me to read in the list of files into the $exports variable. right?
    – llirik42
    Nov 12 at 17:45










  • @llirik42 Yes, good catch
    – UnhandledExcepSean
    Nov 12 at 17:59










  • this almost works - except powershell seems to be unhappy with the @, and may be reading it as a declaration of an array. set-alias rar "C:Program Files7-Zip7z.exe" $archives = get-childitem 'd:scripts' -Recurse foreach ($archive in $archives ) { rar d $archive.FullName @C:scriptsScottTrade_cleanup.txt } Unrecognized token in source text. At line:7 char:60
    – llirik42
    Nov 12 at 18:02












  • quotes fixed it. I think we're good. thanks a ton!
    – llirik42
    Nov 12 at 18:18










  • @llirik42 it should be like 400 times faster; report back on the improvement if you would please; I'm curious about the gain
    – UnhandledExcepSean
    Nov 12 at 18:21















up vote
0
down vote



accepted










So you have a minor performance issue with



$exports = Get-Content C:scriptsScottTrade_cleanup.txt.txt


Move that outside the loops



The big problem is that you are reloading a zip for every file you are seeking to delete. We need to fix this. Take your file that is a list of files, get rid of the inner loop and run this:



rar d $archive.FullName -r @FullListFilePathNameExtension


My first solution was to use the include switch (-i) with the delete, but Windows doesn't support command line over 8k.






share|improve this answer























  • So, if i'm supplying a full list of files to delete for each archive after the -r, then there's really no need for me to read in the list of files into the $exports variable. right?
    – llirik42
    Nov 12 at 17:45










  • @llirik42 Yes, good catch
    – UnhandledExcepSean
    Nov 12 at 17:59










  • this almost works - except powershell seems to be unhappy with the @, and may be reading it as a declaration of an array. set-alias rar "C:Program Files7-Zip7z.exe" $archives = get-childitem 'd:scripts' -Recurse foreach ($archive in $archives ) { rar d $archive.FullName @C:scriptsScottTrade_cleanup.txt } Unrecognized token in source text. At line:7 char:60
    – llirik42
    Nov 12 at 18:02












  • quotes fixed it. I think we're good. thanks a ton!
    – llirik42
    Nov 12 at 18:18










  • @llirik42 it should be like 400 times faster; report back on the improvement if you would please; I'm curious about the gain
    – UnhandledExcepSean
    Nov 12 at 18:21













up vote
0
down vote



accepted







up vote
0
down vote



accepted






So you have a minor performance issue with



$exports = Get-Content C:scriptsScottTrade_cleanup.txt.txt


Move that outside the loops



The big problem is that you are reloading a zip for every file you are seeking to delete. We need to fix this. Take your file that is a list of files, get rid of the inner loop and run this:



rar d $archive.FullName -r @FullListFilePathNameExtension


My first solution was to use the include switch (-i) with the delete, but Windows doesn't support command line over 8k.






share|improve this answer














So you have a minor performance issue with



$exports = Get-Content C:scriptsScottTrade_cleanup.txt.txt


Move that outside the loops



The big problem is that you are reloading a zip for every file you are seeking to delete. We need to fix this. Take your file that is a list of files, get rid of the inner loop and run this:



rar d $archive.FullName -r @FullListFilePathNameExtension


My first solution was to use the include switch (-i) with the delete, but Windows doesn't support command line over 8k.







share|improve this answer














share|improve this answer



share|improve this answer








edited Nov 12 at 17:37

























answered Nov 12 at 17:28









UnhandledExcepSean

9,48522040




9,48522040












  • So, if i'm supplying a full list of files to delete for each archive after the -r, then there's really no need for me to read in the list of files into the $exports variable. right?
    – llirik42
    Nov 12 at 17:45










  • @llirik42 Yes, good catch
    – UnhandledExcepSean
    Nov 12 at 17:59










  • this almost works - except powershell seems to be unhappy with the @, and may be reading it as a declaration of an array. set-alias rar "C:Program Files7-Zip7z.exe" $archives = get-childitem 'd:scripts' -Recurse foreach ($archive in $archives ) { rar d $archive.FullName @C:scriptsScottTrade_cleanup.txt } Unrecognized token in source text. At line:7 char:60
    – llirik42
    Nov 12 at 18:02












  • quotes fixed it. I think we're good. thanks a ton!
    – llirik42
    Nov 12 at 18:18










  • @llirik42 it should be like 400 times faster; report back on the improvement if you would please; I'm curious about the gain
    – UnhandledExcepSean
    Nov 12 at 18:21


















  • So, if i'm supplying a full list of files to delete for each archive after the -r, then there's really no need for me to read in the list of files into the $exports variable. right?
    – llirik42
    Nov 12 at 17:45










  • @llirik42 Yes, good catch
    – UnhandledExcepSean
    Nov 12 at 17:59










  • this almost works - except powershell seems to be unhappy with the @, and may be reading it as a declaration of an array. set-alias rar "C:Program Files7-Zip7z.exe" $archives = get-childitem 'd:scripts' -Recurse foreach ($archive in $archives ) { rar d $archive.FullName @C:scriptsScottTrade_cleanup.txt } Unrecognized token in source text. At line:7 char:60
    – llirik42
    Nov 12 at 18:02












  • quotes fixed it. I think we're good. thanks a ton!
    – llirik42
    Nov 12 at 18:18










  • @llirik42 it should be like 400 times faster; report back on the improvement if you would please; I'm curious about the gain
    – UnhandledExcepSean
    Nov 12 at 18:21
















So, if i'm supplying a full list of files to delete for each archive after the -r, then there's really no need for me to read in the list of files into the $exports variable. right?
– llirik42
Nov 12 at 17:45




So, if i'm supplying a full list of files to delete for each archive after the -r, then there's really no need for me to read in the list of files into the $exports variable. right?
– llirik42
Nov 12 at 17:45












@llirik42 Yes, good catch
– UnhandledExcepSean
Nov 12 at 17:59




@llirik42 Yes, good catch
– UnhandledExcepSean
Nov 12 at 17:59












this almost works - except powershell seems to be unhappy with the @, and may be reading it as a declaration of an array. set-alias rar "C:Program Files7-Zip7z.exe" $archives = get-childitem 'd:scripts' -Recurse foreach ($archive in $archives ) { rar d $archive.FullName @C:scriptsScottTrade_cleanup.txt } Unrecognized token in source text. At line:7 char:60
– llirik42
Nov 12 at 18:02






this almost works - except powershell seems to be unhappy with the @, and may be reading it as a declaration of an array. set-alias rar "C:Program Files7-Zip7z.exe" $archives = get-childitem 'd:scripts' -Recurse foreach ($archive in $archives ) { rar d $archive.FullName @C:scriptsScottTrade_cleanup.txt } Unrecognized token in source text. At line:7 char:60
– llirik42
Nov 12 at 18:02














quotes fixed it. I think we're good. thanks a ton!
– llirik42
Nov 12 at 18:18




quotes fixed it. I think we're good. thanks a ton!
– llirik42
Nov 12 at 18:18












@llirik42 it should be like 400 times faster; report back on the improvement if you would please; I'm curious about the gain
– UnhandledExcepSean
Nov 12 at 18:21




@llirik42 it should be like 400 times faster; report back on the improvement if you would please; I'm curious about the gain
– UnhandledExcepSean
Nov 12 at 18:21


















 

draft saved


draft discarded



















































 


draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53266934%2fdelete-multiple-files-from-multiple-zip-archives%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

How to change which sound is reproduced for terminal bell?

Title Spacing in Bjornstrup Chapter, Removing Chapter Number From Contents

Can I use Tabulator js library in my java Spring + Thymeleaf project?