Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Need to delete a windows folder via script for many computers

Posted on 2012-03-15
5
Medium Priority
?
323 Views
Last Modified: 2012-06-21
Experts,

I have a folder called Test.
The location path is: C:\Program Files\Test.

Inside the Test folder I have a whole bunch of programs that I don't need.

I need to delete this "Test" folder in over 100+ computers and I don't want to do it manually.

My question:
1. Is there a bat file or a script that anyone can share that I can run via the network.
( I have network admin rights)
2. I need to delete the folder and all of its content.  (no need to backup )

Thank you,
R
0
Comment
Question by:RandallVillalobos
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
5 Comments
 
LVL 3

Expert Comment

by:telczj9
ID: 37727602
You could use inside a batch file:

rmdir /q /s \\computer-name\c$\progra~1\test

The line above and just copy it over and over replacing the computer_name.

Flag /q is for quiet
Flag /s is for removing sub-directories

If you have the computer names in a file you save the time of copy/paste with this in a batch file:

@echo off

For %%I in (file_name_with_computer_names.txt) do (
rmdir /q /s \\%%i\c$\progra~1\test
)

Cheers!
0
 

Author Comment

by:RandallVillalobos
ID: 37727842
Hi telczj9,

Thanks for your help!  
I do have a list of all the computer names, but forgive my lack of knowledge.
I am not following the example all the way.

Lets say that my text files is called "ComputersR.txt"  (I'm attaching the text file to verify)

Is the following syntax correct running an exact copy paste?

@echo off

For %%I in (ComputersR.txt) do (
rmdir /q /s \\%%i\c$\progra~1\test
)
ComputersR.txt
0
 
LVL 3

Accepted Solution

by:
telczj9 earned 2000 total points
ID: 37727859
oh! I missed one flag "F" on the for statement:

@echo off

for /f %%I in (ComputersR.txt) do (
echo "Working on: %%i
rmdir /q /s \\%%i\c$\progra~1\test
)

Open in new window


make sure that this batch file is in the same directory as the "ComputersR.txt" file.

Cheers!
0
 

Author Closing Comment

by:RandallVillalobos
ID: 37727869
Awesome telczj9 , I'm going to open up another question based on this script in case you want to see it.
Thanks a bunch
0
 
LVL 3

Expert Comment

by:telczj9
ID: 37727871
note that the syntax:

\\computer_name\C$\....

assumes that the account where you will run the batch file has admin access to all those servers.

I enhance the route below to check if the directory exist then remove it, this should limit unexpected messages....

@echo off

FOR /F %%a in (ComputersR.txt) do (
  echo Working on: %%a
  IF EXIST \\%%a\c$\progra~1\test (
    echo Found target directory
    rmdir /q /s \\%%a\c$\progra~1\test
  ) ELSE (
    echo did not find target directory
  )
)

Open in new window


enjoy.
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Many admins will agree: WSUS is is a nice invention but using it on the client side when updating a newly installed computer is still time consuming as you have to do several reboots and furthermore, the procedure of installing updates, rebooting an…
It’s been over a month into 2017, and there is already a sophisticated Gmail phishing email making it rounds. New techniques and tactics, have given hackers a way to authentically impersonate your contacts.How it Works The attack works by targeti…
Learn several ways to interact with files and get file information from the bash shell. ls lists the contents of a directory: Using the -a flag displays hidden files: Using the -l flag formats the output in a long list: The file command gives us mor…
With the advent of Windows 10, Microsoft is pushing a Get Windows 10 icon into the notification area (system tray) of qualifying computers. There are many reasons for wanting to remove this icon. This two-part Experts Exchange video Micro Tutorial s…

636 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question