Thank you for being a valued part of the CNET community. As of December 1, 2020, the forums are in read-only format. In early 2021, CNET Forums will no longer be available. We are grateful for the participation and advice you have provided to one another over the years.

Thanks,

CNET Support

Resolved Question

Batch file help?

Aug 12, 2014 2:52AM PDT

I kind of been trying to make this batch file. Its not mine, tho i have kind of Frankenstein my way through this. trying different things and what not. the line about the temp files is perfect but the line with the downloads folder, i am running into a problem. I want it to just delete the files in the downloads folder, not the folder itself. see:

@ECHO OFF
CLS
C:
CD \

ECHO WARNING: Do not use the x button to close. Press CTRL+c to abort and press y to close...

ECHO Removing all temp files from C: drive
for /d %%d in ("%userprofile%\..\*.*") do rd "%%d\local settings\temp" /s /q

CLS

ECHO Removing all download files from C: drive
for /d %%d in ("%userprofile%\..\*.*") do rd "%%d\Downloads" /s /q /f

CLS

exit

I need to keep the user profile part so it will work across all users, i just a little stomped on how to change this to make so it will delete just the contents of the download folder. Please and thank you for any help.

Discussion is locked

irishmug18 has chosen the best answer to their question. View answer

Best Answer

- Collapse -
Not an answer.
Aug 14, 2014 3:30AM PDT

However there are many reasons this should fail since even an admin account should fail if the permissions are not just so. As you are the IT staffer I won't go on about that here.

http://stackoverflow.com/questions/97875/rm-rf-equivalent-for-windows covers the takeown command so moving on to the delete. For me I'd do this in a 2 step. That is I'd CD to the folder and then do the rd. That way I won't remove the temp or Downloads folder but just what's in them.
Bob

- Collapse -
Thanks
Aug 14, 2014 3:53AM PDT

Thanks Bob i will try that.

- Collapse -
Safety first.
Aug 14, 2014 4:02AM PDT

Keeping in mind the old adage that "administrator is not God" consider this scenario.

What if I revoked read permission from my folder for administrator? You can guess how badly this would go as the CD command would fail but the RD command would then do it's dirty on the current folder.

As you are an IT admin, I'm short changing you a lot here. But will add that I'd add a 3rd command for safety.

CD \sometempfolderIdon't care about and is safe.
CD to the user folder in question
RD as planned.

The extra CD is our safety because if the CD to the user folder fails, you can imagine the carnage.
Then again, this would be a fine test of your disaster plan.
Bob

- Collapse -
Not A IT admin
Aug 14, 2014 4:07AM PDT

Never said i was a IT admin, nor have i ever said this was for a business, tho i appreciate you assuming that i am that awesome. And appreciate the help instead of just telling me i am wrong. I open to different approaches to this as long as stays in a batch file approach. and not having to depend on a 3rd party program.

- Collapse -
Yes you did.
Aug 14, 2014 4:11AM PDT

"Cause it was requested by my boss"

That means business in my book. I added more because a few good IT staffers coded this up and didn't believe me when I pointed out the flaw. The old "I'm the admin" issue is well worn and can confuse the new IT staffer or programmer. That shiny new layer gets buffed off in just a few weeks.

Anyhow I see a lot of stuff for you to digest now.
Bob

- Collapse -
No business
Aug 14, 2014 4:17AM PDT

Still have a boss but in the normal typical since you are thinking. But yeah i will try this and i really doesn't matter if it was business as you are not responsible for my actions.

- Collapse -
Answer
Two things
Aug 12, 2014 10:00AM PDT

Two things

1: Why? Deleting temp files, be they regular or browser cache, is not a good general practice. Those files are created for a reason, so unless you have an equally good reason for removing them, they should be left alone. Contrary to popular belief, you will DECREASE overall performance rather than increase it by deleting these files. Especially browser cache files.

2: There are probably hundreds of programs out there that will do this for you, so why are you creating your own? I would fully support it if the answer were that you were trying to learn something new, even if the intent is misguided, but I don't get that impression from your post.

2.5: The fact that you say this needs to work across multiple users and the use of a batch script instead of the hundreds of third party tools makes me think this is being done in a workplace environment, in which case there could be potential repercussions from the company IT staff if they catch wind of what you're doing.

- Collapse -
Batch file help
Aug 14, 2014 3:21AM PDT

1: Cause it was requested by my boss

2: want a batch file so i can run in logmein, if i wanted a third party program to do it, i would, and wouldn't need help.

2.5: I appreciate your concern, but your post didn't really answer my question. So if you know how to do what i want to do, please post that next time.

- Collapse -
removing files in batch
Aug 14, 2014 8:16AM PDT

cd to the temp folder.

the command to remove all files in it is;

del *.*

there is also deltree command in some systems which can be used.

- Collapse -
That's because
Aug 14, 2014 9:35AM PDT

That's because I'm not just a human gumball machine that spits out answers because you inserted a quarter and posted a question. I actually take the time to do some basic analysis of the question and potential implications. Such as how this will HURT computer performance and not really gain you anything. Plus there are dozens, maybe hundreds, of programs that already exist to do exactly what you want to do... And they already work, whereas yours doesn't.

What you need to remember is that this is a free forum. You paid exactly nothing to come and post here. Which, coincidentally is exactly how much each and every one of us gets to read and respond to your post. You want someone who will only answer the question you asked, try something like Amazon's Mechanical Turk next time and pay for the privilege. Otherwise, take what you get and be thankful anyone responded at all. Copping an attitude like you have with Bob and me will very quickly ensure that no one bothers responding to anything you may ask in the future.

- Collapse -
Reply deleted.
Aug 15, 2014 3:47AM PDT

The forum filters starred out offensive language, but I deleted the post anyway.

Such replies are not needed in these forums.

Mark

- Collapse -
alright mark
Aug 15, 2014 3:55AM PDT

Alright mark next i will articulate my words better to complain about james being unhelpful and useless in this post.

- Collapse -
JIMMY
Aug 15, 2014 3:57AM PDT

jimmy james whatever not important

- Collapse -
I dunno
Aug 15, 2014 7:15AM PDT

I dunno... I count two or three people all telling you to just get one of the numerous third party tools that already does what you want, off the shelf, so to speak... Put a different way: Multiple people who have a better understanding of the risk/reward breakdown than you are telling you to do things a different way, but despite your being forced to come here because you can't get it working on your own, you seem to think you know better than several people who've been there and done that.

It would be one thing if you were just doing this as a low risk way to teach yourself a little about batch scripting. I would fully support that notion. I would even support it if there were some legitimate need to actually delete those files, but there's not unless you're doing something else very, very wrong. Otherwise, the number of times there is a legitimate need to do anything with those files would not justify the time and effort of building a script to automate it. Just go there in Windows Explorer Ctrl-A, Shift-Delete, done. I could even potentially get behind there being some kind of prohibition on third party software in the workplace. Having to frequently work around such restrictions myself, I have something of a soft spot for people in the same position, but there would still need to be some kind of legitimate need for it to make it worth end-running the IT department... Which there's not. All roads keep leading back to there not being any need for this script to exist and the possibility of it having undesired negative consequences, while low, are still greater than any benefit you would receive from this.

Of course that was all before the OP (presumably) downvoted the one post that pretty much handed them the answer on a silver platter, complete with a bow. The only thing James didn't do was integrate it into the OP's existing code. At that point, I just kind of throw up my hands and say let them figure it out on their own. After they've battered their head against the wall for a while, maybe they'll be willing to check the attitude at the door.

To the OP: Again I say that if you want people to simply hand you the answer, be prepared to pay for that privilege. Everyone here volunteers their time and expertise, so take what you can get and be thankful you get anything at all. If you stop acting like a complete tool you may realize you already have the answer. Also you might realize that your programming skills leave much to be desired, so maybe it's time to tell your boss you aren't up to this particular task. Everything about this says it's an off the books project and the way most workplaces work, your boss won't hesitate to offer you up as the sacrificial lamb/scape goat should he/she be visited by the wrath of someone higher in the food chain.

- Collapse -
Answer
Locking thread...
Aug 15, 2014 9:46AM PDT

I think this thread has lost it's shine and usefulness.

Sorry folks, the party is over.

-Lee