Go Back   Tech Support Forum > Microsoft Support > Windows 7 , Windows Vista Support

User Tag List

Batch file or command to delete directories named in a text file

This is a discussion on Batch file or command to delete directories named in a text file within the Windows 7 , Windows Vista Support forums, part of the Tech Support Forum category. I am wondering if anyone can provide the equivalent to this linux script. When run against a text file with


Closed Thread
 
Thread Tools Search this Thread
Old 07-20-2016, 07:01 AM   #1
Registered Member
 
Join Date: Jul 2016
Posts: 3
OS: windows 7



I am wondering if anyone can provide the equivalent to this linux script. When run against a text file with one entry per line being the name of a directory, it deletes the named directories.

On linux, I run this against the text list.
#!/bin/bash
while IFS='' read -r line || [[ -n "$line" ]]; do
rm -R $line
done < "$1"

I am not sure how to make it do the same for Windows. I can do this, but I'm hoping there's a way to delete based on what's in the text file. Also, wouldn't want it to prompt for deletion of each, but to just delete.

@echo on
cd \
cd %USERPROFILE%
dir /D /N 0
pause
for /D %%f in (XX*) do rmdir %%f /s
pause
%comspec% /k
pause


Thank you
Matty77 is offline  
Sponsored Links
Advertisement
 
Old 07-20-2016, 06:27 PM   #2
TSF Enthusiast
 
Join Date: Feb 2007
Location: Big Prairie Mi.
Posts: 1,525
OS: win7-64, BSD and no more 10

My System


It's easiest to clean out the files before removing the directory.
echo Y|del *.* will clean out the files in a directory as long as there are no hidden or system files, you need to remove the attributes of files with the attrib command before the bat will delete the directory.
the echo Y| simply answers yes to any confirmation messages
kendallt is offline  
Old 07-22-2016, 05:00 AM   #3
Registered Member
 
Join Date: Jul 2016
Posts: 3
OS: windows 7



Unfortunately emptying the directories manually isn't an option. This would likely be used for auto deleting 30-50 directories. I just can't find the right command to run the delete based on the contents of a text list as an input.
Matty77 is offline  
Sponsored Links
Advertisement
 
Old 07-23-2016, 08:42 AM   #4
Registered Member
 
Join Date: Apr 2013
Location: France
Posts: 113
OS: Windows 7 Pro x64 SP1



Hey there .o/

Here's how I'd do it :
Code:
for /f "delims=*" %%a in ('type "Insert file name here"') do rd /s /q "%%a"
Note : if running from the command line and not from a batch file, replace "%%a" with "%a".
Lachdanan is offline  
Old 07-25-2016, 09:40 AM   #5
Registered Member
 
Join Date: Jul 2016
Posts: 3
OS: windows 7



Thanks, that is essentially what I ended up with and it works great.
Matty77 is offline  
Closed Thread

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Similar Threads
Thread Thread Starter Forum Replies Last Post
Blue Screens on Boot
Hey guys... I've been trying unsuccessfully to solve some BSODs that have been showing up on a 32 bit Windows Vista Home Premium Dell Inspiron 1545 here. It can boot up in safe mode, but in normal mode it gets to the desktop briefly and then immediately blue screens and restarts. I used...
niko381 BSOD, App Crashes And Hangs 11 06-17-2015 08:08 PM
Programs not opening (inc microsoft word and paint)
Hi folks, I have a problem with my pc (Im not sure if its actually a virus- I think I might have deleted something a while back in the registry trying to fix something else that mightve caused it). I tried reinstalling office but that made no difference. I looked on the microsoft page and...
EddieRooo Windows 7 , Windows Vista Support 17 01-07-2015 05:17 PM
NFTS.sys file error?
Windows 7 64 bit OEM Originally installed OS was Windows XP 32 bit Age of hardware about 2-3 years Most recent installation was about a week ago BSOD's kept happening throughout my PC's life, recently installed Windows 7 and deleted the partitions to help stop the BSOD's but they still...
chikenman31 BSOD, App Crashes And Hangs 5 01-16-2012 03:04 AM
help BSOD
Hi all Recently ive been getting alot of lock ups and bsod with this error. A process or thread crucial to system operation has unexpectedly exited or been terminated. Any help with this would be muchappreciated:pray:
Thesickness BSOD, App Crashes And Hangs 17 07-10-2011 02:55 AM
[SOLVED] BSOD problems.
Vista x64 What was original installed OS on system? None. Custom built. OEM: Full Retail Version Age of system (hardware): 3 years Age of OS installation - have you re-installed the OS? 3 years. Yes. CPU: Intel Core 2 Duo E8400 Wolfdale Video Card: EVGA GEforce 8800 GT...
ajcc323 BSOD, App Crashes And Hangs 25 02-24-2011 04:31 AM

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is on
Smilies are on
[IMG] code is on
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off


Post a Question


» Site Navigation
 > FAQ
  > 10.0.0.2
Powered by vBadvanced CMPS v3.2.3


All times are GMT -7. The time now is 06:40 PM.


Powered by vBulletin® Version 3.8.8
Copyright ©2000 - 2020, vBulletin Solutions, Inc.
vBulletin Security provided by vBSecurity v2.2.2 (Pro) - vBulletin Mods & Addons Copyright © 2020 DragonByte Technologies Ltd.
User Alert System provided by Advanced User Tagging v3.1.0 (Pro) - vBulletin Mods & Addons Copyright © 2020 DragonByte Technologies Ltd.
Copyright 2001 - 2018, Tech Support Forum

Windows 10 - Windows 7 - Windows XP - Windows Vista - Trojan Removal - Spyware Removal - Virus Removal - Networking - Security - Top Web Hosts