The perfect solution is to remove from each folder all excepting the smallest file
An adequate solution is to remove from each folder every file above a certain size.
My reason is that I wish to have a SMALL archive of a partition with very unusual characteristics,
and after much investigation I think the problem is the folder structure and NOT the files,
and I suspect the possibility that some DOS commands and Windows API's and third party utilities,
may handle an EMPTY folder differently than a folder with one or more files,
so I expect to preserve the unusual characteristics if I preserve at least one file.
Regards
Alan
How to delete from all folders "certain files"
Moderator: DosItHelp
Re: How to delete from all folders "certain files"
The reasoning isn't clear, but You want to keep the smallest file in every folder in a folder tree?
Test this:
Test this:
Code: Select all
@echo off
for /d /r "d:\base\folder" %%a in (*) do (
pushd "%%a"
for /f "skip=1 delims=" %%b in ('dir /b /os /a-d ') do del "%%b"
popd
)
Re: How to delete from all folders "certain files"
I'm not sure if you've thought of this, (it seems to me to be a quicker way of potentially proving your theory). If you use RoboCopy with the /Create switch it should copy the entire folder structure and include every file, (it will simply create those files at 0 bytes)!
Re: How to delete from all folders "certain files"
@foxidrive
Thanks - that worked well - too well and the train jumped off the rails
I placed the script in R:\Drive_D\VHD and tweaked it to work from the root of P:\.
It had a lot of work to do and after waiting a while I hit Ctrl'C to see what was happening.
Then I let it resume and it started telling me of files it could not delete from R:\Drive_D\VHD because they were in use.
I think that when the script resumed, the pushd and popd may have become unbalanced,
and the files in use were my running script and the *.VHD files that were attached as Virtual Hard Drives - one of which was P:\
All my other experimental files *.VHD files etc in R:\Drive_D\VHD were deleted.
Fortunately there was nothing really important,
AND I am currently Beta testing some fantastic Data Recovery software which has fully recovered 18 files,
and there are only 3 missing files and these I can quickly recreate should I wish.
@Compo
Thanks, BUT I actually suspect the problem is related to the MFT of an NTFS partition having erroneous artifacts
and when a partition image backup is restored those artifacts are resulting strange consequences related to the existing folder structure.
Deleting a file will delete some sort of entry in the MFT, but hopefully the folder artifacts will not be disturbed.
I fear that replacing a deleted file with a zero byte file might cause greater MFT disturbance.
N.B. My current interest is in the nature of the artifacts, not in eradicating them - that comes later
Regards
Alan
Thanks - that worked well - too well and the train jumped off the rails
I placed the script in R:\Drive_D\VHD and tweaked it to work from the root of P:\.
It had a lot of work to do and after waiting a while I hit Ctrl'C to see what was happening.
Then I let it resume and it started telling me of files it could not delete from R:\Drive_D\VHD because they were in use.
I think that when the script resumed, the pushd and popd may have become unbalanced,
and the files in use were my running script and the *.VHD files that were attached as Virtual Hard Drives - one of which was P:\
All my other experimental files *.VHD files etc in R:\Drive_D\VHD were deleted.
Fortunately there was nothing really important,
AND I am currently Beta testing some fantastic Data Recovery software which has fully recovered 18 files,
and there are only 3 missing files and these I can quickly recreate should I wish.
@Compo
Thanks, BUT I actually suspect the problem is related to the MFT of an NTFS partition having erroneous artifacts
and when a partition image backup is restored those artifacts are resulting strange consequences related to the existing folder structure.
Deleting a file will delete some sort of entry in the MFT, but hopefully the folder artifacts will not be disturbed.
I fear that replacing a deleted file with a zero byte file might cause greater MFT disturbance.
N.B. My current interest is in the nature of the artifacts, not in eradicating them - that comes later
Regards
Alan
Re: How to delete from all folders "certain files"
FWIW I've never used control C on a batch file unless I wanted to abort it.
If you need to keep track of progress in a batch file then just add an echo command.
The old maxim is true - files that you don't have backed up are only temporary files.
If you need to keep track of progress in a batch file then just add an echo command.
The old maxim is true - files that you don't have backed up are only temporary files.
Re: How to delete from all folders "certain files"
Help, this gives me a problem :-
It "Walks the directory tree rooted at [drive:]path, executing the FOR statement in each directory of the tree"
AND THEN IT JUMPS TO ANOTHER DRIVE
and continues to execute the delete commands there also.
If possible I would like a "code tweak" that only acts upon the contents of directories and not upon the destinations of Reparse Points.
This demonstrates that CMD.EXE is aware that "Pale Moon" is a reparse point with a destination on drive D:\
but once it has walked into that it thinks that this is a valid target
C:\Users\Alan\AppData\Roaming\Moonchild Productions\Pale Moon\profiles.ini
and the only clue appears to be that Free Space has fallen from
43,100,663,808 bytes free down to
9,659,375,616 bytes free
Regards
Alan
Code: Select all
for /d /r "d:\base\folder" %%a in (*) do (
)
It "Walks the directory tree rooted at [drive:]path, executing the FOR statement in each directory of the tree"
AND THEN IT JUMPS TO ANOTHER DRIVE
and continues to execute the delete commands there also.
If possible I would like a "code tweak" that only acts upon the contents of directories and not upon the destinations of Reparse Points.
This demonstrates that CMD.EXE is aware that "Pale Moon" is a reparse point with a destination on drive D:\
but once it has walked into that it thinks that this is a valid target
C:\Users\Alan\AppData\Roaming\Moonchild Productions\Pale Moon\profiles.ini
and the only clue appears to be that Free Space has fallen from
43,100,663,808 bytes free down to
9,659,375,616 bytes free
Code: Select all
C:\Users\Alan\AppData\Roaming\Moonchild Productions>DIR
Volume in drive C is C_OCZ_System
Volume Serial Number is 6E59-9E7D
Directory of C:\Users\Alan\AppData\Roaming\Moonchild Productions
26/10/2012 22:13 <DIR> .
26/10/2012 22:13 <DIR> ..
26/10/2012 21:53 <JUNCTION> Pale Moon [D:\Junctions\PaleMoon\Alan\Roaming\Pale Moon]
0 File(s) 0 bytes
3 Dir(s) 43,100,663,808 bytes free
C:\Users\Alan\AppData\Roaming\Moonchild Productions>CD PALE MOON
C:\Users\Alan\AppData\Roaming\Moonchild Productions\Pale Moon>DIR
Volume in drive C is C_OCZ_System
Volume Serial Number is 6E59-9E7D
Directory of C:\Users\Alan\AppData\Roaming\Moonchild Productions\Pale Moon
29/05/2012 21:45 <DIR> .
29/05/2012 21:45 <DIR> ..
29/05/2012 21:45 <DIR> Profiles
10/03/2012 18:23 111 profiles.ini
1 File(s) 111 bytes
3 Dir(s) 9,659,375,616 bytes free
C:\Users\Alan\AppData\Roaming\Moonchild Productions\Pale Moon>
Regards
Alan