Was wondering if someone could help me Make A Batch File

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Message
Author
anoble1
Posts: 22
Joined: 29 Nov 2012 10:24

Was wondering if someone could help me Make A Batch File

#1 Post by anoble1 » 29 Nov 2012 10:26

Was wondering if someone could help me Make A Batch File That Deletes Files

Not sure if many can help but I am in IT, and run in to a certain program error all the time. The fix is deleting 4 files in their PC.

Example:
1.Delete the UCF folder located at C:\Documents and Settings\Username\Documentum
2.Delete the Java folder located at C:\Cache

3.Delete Temp internet Files
4.Delete Cookies

Any suggestions?

abc0502
Posts: 1007
Joined: 26 Oct 2011 22:38
Location: Egypt

Re: Was wondering if someone could help me Make A Batch File

#2 Post by abc0502 » 29 Nov 2012 13:57

To delete folders and it's content you use

Code: Select all

RMDIR /S /Q "C:\Documents and Settings\Username\Documentum" >nul
RMDIR /S /Q "C:\Cache" >nul

This will remove the directory and it's contents.

"Temp internet Files" for what browsers ?

And What system?

anoble1
Posts: 22
Joined: 29 Nov 2012 10:24

Re: Was wondering if someone could help me Make A Batch File

#3 Post by anoble1 » 29 Nov 2012 14:11

Very nice. How do I grab the username of who is currently logged into the PC?
There could be multiple usernames.

IE 7
Windows XP

abc0502
Posts: 1007
Joined: 26 Oct 2011 22:38
Location: Egypt

Re: Was wondering if someone could help me Make A Batch File

#4 Post by abc0502 » 29 Nov 2012 14:27

Edited:

To grap the username u use try this in your cmd window

Code: Select all

echo %username%

But this location : C:\Documents and Settings\<username>\ is equal to %userprofile%

Code: Select all

@Echo Off

:: Remove Cash and Documentum Folders
RMDIR /S /Q "C:\Documents and Settings\%username%\Documentum\UCF" >nul
RMDIR /S /Q "C:\Cache\JAVA" >nul

:: Remove Internet Temporary Files
Del /F /S /Q "%userprofile%\Local Settings\Temporary Internet Files\*.*" >nul
Del /F /S /Q "C:\Documents and Settings\%username%\Cookies\*.*" >nul

pause

Test it and to make it exist after if finish, remove the "pause"
Last edited by abc0502 on 29 Nov 2012 15:07, edited 3 times in total.

anoble1
Posts: 22
Joined: 29 Nov 2012 10:24

Re: Was wondering if someone could help me Make A Batch File

#5 Post by anoble1 » 29 Nov 2012 15:03

That is awesome. I may have made a mistake in my first comment.

Here is the one I want to delete.

.Delete the UCF folder located at C:\Documents and Settings\Username\Documentum\UCF
Delete the Java folder located at C:\Cache\JAVA

So, I really just wanted to delete the last folder. not the whole profile and everything. Or did I read your post wrong?

Thanks for all the help.

abc0502
Posts: 1007
Joined: 26 Oct 2011 22:38
Location: Egypt

Re: Was wondering if someone could help me Make A Batch File

#6 Post by abc0502 » 29 Nov 2012 15:06

Ok, i changed the code above, it will delete the folder UFC and Java and all of it's content.

anoble1
Posts: 22
Joined: 29 Nov 2012 10:24

Re: Was wondering if someone could help me Make A Batch File

#7 Post by anoble1 » 29 Nov 2012 15:30

@Echo Off

:: Remove Cash and Documentum Folders
RMDIR /S /Q "C:\Documents and Settings\%username%\Documentum\UCF" >nul
RMDIR /S /Q "C:\Cache\JAVA" >nul

:: Remove Internet Temporary Files
Del /F /S /Q "%userprofile%\Local Settings\Temporary Internet Files\*.*" >nul
Del /F /S /Q "C:\Documents and Settings\%username%\Cookies\*.*" >nul

pause


On the Temp internet files, does it need to be like this?
Del /F /S /Q "C:\Documents and Settings\%userprofile%\Local Settings\Temporary Internet Files\*.*" >nul

abc0502
Posts: 1007
Joined: 26 Oct 2011 22:38
Location: Egypt

Re: Was wondering if someone could help me Make A Batch File

#8 Post by abc0502 » 29 Nov 2012 15:44

Edited:
Corrected wrong Path "C:\Documents and Settings\%userprofile%\" to "C:\Documents and Settings\%username%\"

yes it can be but as i said

Code: Select all

C:\Documents and Settings\%username%\

Can be used as

Code: Select all

%userprofile%

as this point to the folder %username% directly, both are the same

I used to do that if i'm going to process folders inside the "C:\Documents and Settings\%username%" path, so i don't write too much :wink:
Last edited by abc0502 on 30 Nov 2012 05:34, edited 1 time in total.

Ed Dyreen
Expert
Posts: 1569
Joined: 16 May 2011 08:21
Location: Flanders(Belgium)
Contact:

Re: Was wondering if someone could help me Make A Batch File

#9 Post by Ed Dyreen » 29 Nov 2012 22:45

'
hi abc0502,

'userName' == 'runAsUserName' neq 'logonUserName'

Code: Select all

%regKeyRead_% $logonUserName, "HKCU\Software\Microsoft\Windows\CurrentVersion\Explorer", "logon User Name"
But probably not a problem for the sake of simplicity so why mention it, I am bored :)
abc0502 wrote:

Code: Select all

C:\Documents and Settings\%userprofile%\
Can be used as

Code: Select all

%userprofile%
That's obviously wrong,

Boombox
Posts: 80
Joined: 18 Oct 2012 05:51

Re: Was wondering if someone could help me Make A Batch File

#10 Post by Boombox » 30 Nov 2012 04:45

.
If you type SET at the command prompt and hit ENTER.
You can see all the variables that are currently active on your system.

The text before the = symbol is your variable name, so...

%SystemRoot% is equal to the path 'c:\windows'

abc0502
Posts: 1007
Joined: 26 Oct 2011 22:38
Location: Egypt

Re: Was wondering if someone could help me Make A Batch File

#11 Post by abc0502 » 30 Nov 2012 05:33

@Ed Dyreen and Boombox
Sorry for that it was a typing error, i meant

Code: Select all

C:\Documents and Settings\%username%

Equal to

Code: Select all

%userprofile%


I wrote that in my 2nd post

Code: Select all

Del /F /S /Q "%userprofile%\Local Settings\Temporary Internet Files\*.*" >nul
Del /F /S /Q "C:\Documents and Settings\%username%\Cookies\*.*" >nul


and didn't notice that i wrote the %userprofile% till you mentioned it. :oops:

I will correct that.

anoble1
Posts: 22
Joined: 29 Nov 2012 10:24

Re: Was wondering if someone could help me Make A Batch File

#12 Post by anoble1 » 30 Nov 2012 07:24

So,

Is there a way to write something that will distinguish between Windows Xp, and Windows 7? Like an IF Statement?
If using Windows XP then use below, ELSE use the Windows 7 file locations?

abc0502
Posts: 1007
Joined: 26 Oct 2011 22:38
Location: Egypt

Re: Was wondering if someone could help me Make A Batch File

#13 Post by abc0502 » 30 Nov 2012 07:40

Yes, but will this location will change "C:\Cache\JAVA" ?
and is this always at the main folder of the user profile "Documentum\UCF" ?

anoble1
Posts: 22
Joined: 29 Nov 2012 10:24

Re: Was wondering if someone could help me Make A Batch File

#14 Post by anoble1 » 30 Nov 2012 07:52

In Windows 7 it will be like C:\Users\Username\Documentum

But, I assume the temp internet files and cookies location will change?

abc0502
Posts: 1007
Joined: 26 Oct 2011 22:38
Location: Egypt

Re: Was wondering if someone could help me Make A Batch File

#15 Post by abc0502 » 30 Nov 2012 08:29

Test this, I only tested XP as I work on it now, in windows 7 i assumed the same when removing the attributes in order to delete protected files.

Code: Select all

@Echo Off

:: Check if OS is XP
ver | find "XP" > nul
if %ERRORLEVEL% == 0 (
      :: Delete Temporary Internet Files
      PUSHD "%userprofile%\Local Settings\Temporary Internet Files"
      For /F "delims=" %%A in ('Dir /B /A:D "*.*"') Do (
         ATTRIB -S -H -A "%%A"
         RMDIR /S /Q "%%A" 2>nul
         ATTRIB +S +H +A "%%A"
         )
      POPD
      
      :: Delete Cookies
      Del /F /Q "%userprofile%\Cookies\*.*" 2>nul
   )

echo %vers% | find "Windows 7" > nul
if %ERRORLEVEL% == 0 (
      :: Delete Temporary Internet Files [ Two Temp location in windows 7 ]
      PUSHD "%userprofile%\AppData\Local\Microsoft\Windows\Temporary Internet Files"
      For /F "delims=" %%A in ('Dir /B /A:D "*.*"') Do (
         ATTRIB -S -H -A "%%A"
         RMDIR /S /Q "%%A" 2>nul
         ATTRIB +S +H +A "%%A"
         )
      POPD
      
      PUSHD "%userprofile%\AppData\Local\Microsoft\Windows\Temporary Internet Files\Low"
      For /F "delims=" %%A in ('Dir /B /A:D "*.*"') Do (
         ATTRIB -S -H -A "%%A"
         RMDIR /S /Q "%%A" 2>nul
         ATTRIB +S +H +A "%%A"
         )
      POPD
      
      :: Delete Cookies
      Del /F /Q "%userprofile%\AppData\Roaming\Microsoft\Windows\Cookies\*.*" 2>nul
   )
   
:: Deleting Other Folders [ They should be in general in the same location ]
RMDIR /S /Q "%userprofile%\Documentum\UCF" >nul
RMDIR /S /Q "C:\Cache\JAVA" >nul

Pause
Exit /B

I will test windows 7 when i come back and update the code if needed.

BTW, when running on 7 try running using Admin rights, and don't forget I DIDN'T TEST IT ON 7

and this "2>nul" to prevent errors to be displayed when there is no files in the cookies folder to delete

Post Reply