Batch file help

Venom

Active member
Feedback
15 (100%)
Credits
707CR
Losing my marbles today and examples on google not quite what I want.
Just need a simple script/batch file to delete a list of FOLDERS and all there contents using a text file for the folder names.

Think I need IF for DO :)

Just trying to finish my dreamcast SD card off tried a few examples but just got in a mess.

So I have a folder say called c:base and in that is lots of folders called 01 02 03 04 05 300 odd of them !!

Then I have a folder which fixes ones which did not work in the base image .. has folders like 02 05 . It only has folders which the game was fixed etc ! This folder needs to completely replace the one in base.

So I would want to create a text file which I could paste the list of folders in that I want to replace e.g

01

114

Then a script that would Delete these folders and contents from cbase from the list it reads from a text file

I'd then simply want to copy all the files and folders from c:updates to cbase so would get all the folders and there is a gdemu.ini file as well !

Its the delete of files which I need most help with as could just copy paste the updated folders and one ini file with file explorer

So the updates folder contains the folders and a single ini

21/11/2020 11:24 <DIR> .

21/11/2020 11:24 <DIR> ..

20/11/2020 12:52 <DIR> 01

20/11/2020 12:52 <DIR> 04

20/11/2020 12:52 <DIR> 114

20/11/2020 12:53 <DIR> 115

20/11/2020 12:53 <DIR> 116

20/11/2020 12:54 <DIR> 128

20/11/2020 12:54 <DIR> 145

20/11/2020 12:54 <DIR> 156

20/11/2020 12:55 <DIR> 214

20/11/2020 12:56 <DIR> 225

20/11/2020 12:56 <DIR> 227

20/11/2020 12:57 <DIR> 230

20/11/2020 12:57 <DIR> 234

20/11/2020 12:57 <DIR> 247

20/11/2020 12:58 <DIR> 263

The folder list I would like to simply put in like this rather than a direct path, then there is a *.ini at end but I can just paste over that !

1
4
114
115
116
128
145
156
214
225
227
230
234
247
263
276
296
313
319
354
372
373
377
392
394
40
50
66
GDEMU.ini

Any help appreciated as losing my marbles !

The fact the bloody SD card I bought is 500mb short for the image has also been frustarting :(

Luckily another card of same size had extra space !!!
 

big10p

Coins detected in pocket!
vacBacker
Feedback
12 (100%)
Credits
5,621CR
Why don't you just copy everything from Update and paste into Base. Explorer should ask if you want to replace files with the same names being copied, and you should be able to click 'yes for all', or something.
 

big10p

Coins detected in pocket!
vacBacker
Feedback
12 (100%)
Credits
5,621CR
But you'd be replacing files with the updated version, so I assume no extra SD space would be required, unless the update files are larger than the base ones.
big10p2020-11-21 12:48:57
 

chunksin

Active member
vacBacker
Feedback
21 (100%)
Credits
733CR
This should work for you in Powershell:

$Target_Folder = 'C:temptest2'

$Source_Folder = 'C:temptest1'

$FolderList = Get-ChildItem -Path $Source_Folder -Directory -Depth 3 | Select-Object Name

write-host 'Deleting ...'

foreach($Folder in $FolderList){

$FolderToDelete = $Target_Folder + $Folder.Name

write-host $FolderToDelete

Remove-Item $FolderToDelete -Recurse -Force -Confirm:$false -erroraction silentlycontinue }

write-host 'Copying ...'

foreach($Folder in $FolderList){

$FolderToCopy = $Source_Folder + $Folder.Name

write-host $FolderToCopy

Move-Item $FolderToCopy $Target_Folder -Force -Confirm:$false -erroraction silentlycontinue }

The target folder is the one on your SD card where you want to remove folders from and the source is the source folder with the replacement folders.

Worth testing but it should be fine!

Chunksin2020-11-21 13:22:10
 

Venom

Active member
Feedback
15 (100%)
Credits
707CR
Brill just going on family walk but will test this evening as update is bigger than original and no wiggle room in a copy and paste cheers.
 

Venom

Active member
Feedback
15 (100%)
Credits
707CR
Hi chunskin neary there !
I could not seem to run as powershell scripy even with run as administor so ran this command tp

set-executionpolicy remotesigned

Its now deleting the folders and all its content :)

Then it copies the new folder over :)

But is not copying over the actual contents of the folder :( I put a couple of text files in there

TBH as long as the folders delete I am happy with a COPY all the files and folders across even if they are in the root 'e:test2'

Any help would be appreciated.

I like this script as its obviously looking at what to delete rather than feeding it a list from a text file, so any further help would be appreciated

I appreciate all the folders are now empty so can sat least now do a clean copy and paste in windows too
 

Venom

Active member
Feedback
15 (100%)
Credits
707CR
Brill deleted all folders and copied them with no problems !
Just one more ask if its a quicky, as I simply don't know powershell.

In the root of the source there is a single file called GDEMU.ini

Its not in a folder its at the root.

Can you do a simple line to delete the old one and replace with the newone ?

I can do it manually more for completeness :)
 

chunksin

Active member
vacBacker
Feedback
21 (100%)
Credits
733CR
I guess you can just copy all of the source folder over if the only thing in the root is that ini file, take out the entire bottom foreach section and simply replace with:

Copy-Item $Source_Folder $Target_Folder -Force -Confirm:$false -erroraction silentlycontinue -recurse
 
Top