Can anyone write a batch file to do this, please?
Posted: 09 Feb 2018 17:13
Would it be possible for someone to write a batch file that searches for files in any subfolders of a given folder, and moves any files that are more than one subfolder down, into the first subfolder of it's patch (relative to the batch file)? What I mean is, say you have the following four archived files:
c:\1\a.7z
c:\1\b.7z
c:\1\c.7z
c:\1\d.7z
And you want to un-archive them so that all of the files from each archive is inside a folder named after the archive file, i.e.
c:\1\a\allornoth.tap
c:\1\a\antattack.tap
c:\1\a\aufmonty.z80
c:\1\b\batman3d.tap
c:\1\b\batty.z80
c:\1\b\backtosk.tap
c:\1\b\botp.z80
etc, then of course this is easy to do (I use the Windows version of 7zip, with the "extract all files to */" function), but there is one irritating thing, and that's that sometimes you'll end up with a file being put into a sub folder, or a sub-sub-folder, etc. This is mainly because some archive files always produce a folder for the files, and others don't, plus some files might be two or more folders down in the archive.
So what I'm looking for is a batch file that I can, after I've unarchived the files into one folder, copy into that folder, run and it will scan every folder and subfolder (starting from the folder in which the batch file is placed) and then if it will:
1. Ignore files in the same folder as the batch file,
2. Ignore any files in the immediate subfolders (i.e. the files that are one subfolder down, will be ignored by the batch file)
3. Any file that is two or more subfolders down will be moved into the first subfolder of it's location.
4. Any sub-subfolder (which will now be empty) will now be deleted.
What I mean is, say I have the files:
c:\1\a.7z
c:\1\b.7z
c:\1\c.7z
c:\1\d.7z
and when I unzip them to the same folder, I end up with:
c:\1\a\ALLORNOTH.TAP
c:\1\a\a\ANTATTACK.TAP
c:\1\a\a\AUFMONTY.Z80
c:\1\b\BATMAN3D.TAP
c:\1\b\b\123\BATTY.Z80
c:\1\b\b\48k\BACKTOSK.Z80
c:\1\b\BOTP.Z80
c:\1\b\BRKDWN128.TAP
c:\1\b\128K\HB\BL128.TZX
c:\1\b\BDASH3.TAP
c:\1\b\WITHEDITR\BDASH.TAP
c:\1\c\cassette-games\c\CG3.TAP
c:\1\c\CC128.TAP
c:\1\c\CC.Z80
c:\1\c\CENT_128.TAP
c:\1\c\cassette-games\c\Chess3D.TAP
c:\1\d\cassette-games\d\DEFIANT.Z80
c:\1\d\DEFIANT2.TAP
c:\1\d\DRILLER.Z80
c:\1\d\cassette-games\DCFT.TAP
then if I copy this batch file (that I'm hoping is possible to write) to the c:\1 folder, and run it, then it will move all of the files in the subfolders into their immediate first subfolder, and then delete any sub-subfolders and deeper, so that the end is:
c:\1\a\ALLORNOTH.TAP
c:\1\a\ANTATTACK.TAP
c:\1\a\AUFMONTY.Z80
c:\1\b\BATMAN3D.TAP
c:\1\b\BATTY.Z80
c:\1\b\BACKTOSK.Z80
c:\1\b\BOTP.Z80
c:\1\b\BRKDWN128.TAP
c:\1\b\BL128.TZX
c:\1\b\BDASH3.TAP
c:\1\b\WITHEDITR\BDASH.TAP
c:\1\c\CG3.TAP
c:\1\c\CC128.TAP
c:\1\c\CC.Z80
c:\1\c\CENT_128.TAP
c:\1\c\Chess3D.TAP
c:\1\d\DEFIANT.Z80
c:\1\d\DEFIANT2.TAP
c:\1\d\DRILLER.Z80
c:\1\d\DCFT.TAP
I'm using Windows 7, if that's important. Thanks for any answers.
c:\1\a.7z
c:\1\b.7z
c:\1\c.7z
c:\1\d.7z
And you want to un-archive them so that all of the files from each archive is inside a folder named after the archive file, i.e.
c:\1\a\allornoth.tap
c:\1\a\antattack.tap
c:\1\a\aufmonty.z80
c:\1\b\batman3d.tap
c:\1\b\batty.z80
c:\1\b\backtosk.tap
c:\1\b\botp.z80
etc, then of course this is easy to do (I use the Windows version of 7zip, with the "extract all files to */" function), but there is one irritating thing, and that's that sometimes you'll end up with a file being put into a sub folder, or a sub-sub-folder, etc. This is mainly because some archive files always produce a folder for the files, and others don't, plus some files might be two or more folders down in the archive.
So what I'm looking for is a batch file that I can, after I've unarchived the files into one folder, copy into that folder, run and it will scan every folder and subfolder (starting from the folder in which the batch file is placed) and then if it will:
1. Ignore files in the same folder as the batch file,
2. Ignore any files in the immediate subfolders (i.e. the files that are one subfolder down, will be ignored by the batch file)
3. Any file that is two or more subfolders down will be moved into the first subfolder of it's location.
4. Any sub-subfolder (which will now be empty) will now be deleted.
What I mean is, say I have the files:
c:\1\a.7z
c:\1\b.7z
c:\1\c.7z
c:\1\d.7z
and when I unzip them to the same folder, I end up with:
c:\1\a\ALLORNOTH.TAP
c:\1\a\a\ANTATTACK.TAP
c:\1\a\a\AUFMONTY.Z80
c:\1\b\BATMAN3D.TAP
c:\1\b\b\123\BATTY.Z80
c:\1\b\b\48k\BACKTOSK.Z80
c:\1\b\BOTP.Z80
c:\1\b\BRKDWN128.TAP
c:\1\b\128K\HB\BL128.TZX
c:\1\b\BDASH3.TAP
c:\1\b\WITHEDITR\BDASH.TAP
c:\1\c\cassette-games\c\CG3.TAP
c:\1\c\CC128.TAP
c:\1\c\CC.Z80
c:\1\c\CENT_128.TAP
c:\1\c\cassette-games\c\Chess3D.TAP
c:\1\d\cassette-games\d\DEFIANT.Z80
c:\1\d\DEFIANT2.TAP
c:\1\d\DRILLER.Z80
c:\1\d\cassette-games\DCFT.TAP
then if I copy this batch file (that I'm hoping is possible to write) to the c:\1 folder, and run it, then it will move all of the files in the subfolders into their immediate first subfolder, and then delete any sub-subfolders and deeper, so that the end is:
c:\1\a\ALLORNOTH.TAP
c:\1\a\ANTATTACK.TAP
c:\1\a\AUFMONTY.Z80
c:\1\b\BATMAN3D.TAP
c:\1\b\BATTY.Z80
c:\1\b\BACKTOSK.Z80
c:\1\b\BOTP.Z80
c:\1\b\BRKDWN128.TAP
c:\1\b\BL128.TZX
c:\1\b\BDASH3.TAP
c:\1\b\WITHEDITR\BDASH.TAP
c:\1\c\CG3.TAP
c:\1\c\CC128.TAP
c:\1\c\CC.Z80
c:\1\c\CENT_128.TAP
c:\1\c\Chess3D.TAP
c:\1\d\DEFIANT.Z80
c:\1\d\DEFIANT2.TAP
c:\1\d\DRILLER.Z80
c:\1\d\DCFT.TAP
I'm using Windows 7, if that's important. Thanks for any answers.