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
}
}
powershell
add a comment |
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
}
}
powershell
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
add a comment |
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
}
}
powershell
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
powershell
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
add a comment |
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
add a comment |
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.
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
|
show 2 more comments
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.
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
|
show 2 more comments
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.
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
|
show 2 more comments
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.
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.
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
|
show 2 more comments
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
|
show 2 more comments
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
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
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