# How can a batch file do this?!



## Octopuss (Aug 23, 2016)

I have a relatively simple batch file that prepares a Windows image with various tweaks and whatnot for unattended installation.
At the beginning, I make it delete the entire contents of a folder the files get initially copied to by doing this:
for /d %%j in (d:\win7\*) do rd /s /q "%%j"
del d:\win7\*.* /q
That's the only way I managed to figure out how to remove all the subfolders and files.

Now: for some super obscure reason I cannot understand, if you edit the batch file and save it while the batch is running, the damn thing wipes the ENTIRE disk clean.
Does anyone more knowledgeable have any idea why the heck does happens?


----------



## blobster21 (Aug 23, 2016)

First time i hear someone editing a running batch file, but since it's possible, why not 

What are the modifications you brought to this script when the recursive erase spread to the entire disk ?


----------



## Octopuss (Aug 23, 2016)

That's the most bizarre thing - I didn't touch the deletion commands at all.


----------



## blobster21 (Aug 23, 2016)

did you see this answer taken from stackoverflow ? :



> The command interpreter remembers the line position it's at in the batch file. As long as you modify the batch file after the current executing line position you'll be fine.
> 
> If you modify it before then it will start doing strange things (repeating commands etc..)


----------



## blobster21 (Aug 23, 2016)

and also



> Actually, what it will do is the parser pointer will stay at the same index in the file, so adding/removing text before the index will shift what's under the instruction pointer. Weird things happen, indeed



that must be the culprit  (that calls for troubles)


----------



## Octopuss (Aug 23, 2016)

I still don't really understand why the damn thing decided to wipe the entire disk rather than, I don't know, re-wiping the folder in question again.
But it was a costy lesson - I lost 3 years worth of registry tweaks I used to apply to Windows images during installation, because for some weird reason the files were wiped so clean I couldn't even find them with recovery tool. Plus I had no backups of anything despite having 4TB space in the NAS.... (yes I am a retard)


----------



## W1zzard (Aug 23, 2016)

Slightly OT but won't rd /s /q do what you want?


----------



## blobster21 (Aug 23, 2016)

somehow the script instructions became unclear after you modified it on the fly, and the former command "mutated" into something more destructive.

As to why your recovery tool couldn't revive the deleted files, i think this recursive deletion gone crazy acted like a cut & paste, where all former files cease to exist on the source drive / partition.

You learned the hard way, sorry for this loss, it happened to all of us at some point


----------



## Octopuss (Aug 23, 2016)

W1zzard said:


> Slightly OT but won't rd /s /q do what you want?


I'll give it a shot once I backup (cough) all my stuff 
I wrote that part ages ago and never got back to it since.... it's most likely not ideal solution.



blobster21 said:


> As to why your recovery tool couldn't revive the deleted files, i think this recursive deletion gone crazy acted like a cut & paste, where all former files cease to exist on the source drive / partition.


That's probably true, because 17GB worth of Skyrim mods became garbage data and got moved into Lightroom's catalogue folders... it's a damn voodoo I'm telling you.


I need to figure out a way to find out what the reg tweaks were. Best I can think of is exporting the entire registry of my father in law's recently installed notebook, and comparing them with default installation. 200MB worth of plain text... FML.


----------



## Boosnie (Jun 5, 2017)

May I ask why one would still install win7 in mid 2017?


----------



## Kursah (Jun 6, 2017)

Boosnie said:


> May I ask why one would still install win7 in mid 2017?



Last post was August 23, 2016. Unless you're going to offer something useful to the thread, please refrain from thread necro-ing. Thanks!


----------

