Click here to Skip to main content
12,396,461 members (67,136 online)
Rate this:
 
Please Sign up or sign in to vote.
See more: batch
Hi All,
I want to check if folder exits or not using batch file, if exits i want to delete that folder else do nothing.

Path of the folder is : %userprofile%\AppData\LocalLow\Dictionary

Condition is i need to do it by batch file.
Need to delete folder for all the existing users can anybody help me in solving this.
I tried the below code but not working
SET  src_dir="%userprofile%\AppData\LocalLow\Dictionary"
 
IF EXIST %src_dir%\NUL
(
 
rmdir /s /q "%userprofile%\AppData\LocalLow\Dictionary"
) 
ELSE 
(
echo "Not exists"
pause
)
Thanking you in advance
Posted 26-Sep-12 3:53am
Updated 26-Sep-12 4:41am
v3
Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 1

The simplest suggestion is: with just deleting you cannot go wrong. If the directory does not exist, nothing will change.

If you still need a check, this old Microsoft support article explains the matter, as well as many other sources:
http://support.microsoft.com/kb/65994[^].

[EDIT]

You can get full description of all batch command and syntax on your system, if you auto-generate help using this wonderful batch script by Rob van der Woude improved by Johan Parlevliet:
http://www.robvanderwoude.com/allhelp.php[^].

—SA
  Permalink  
v2
Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 2

The pause isn’t really necessary
The whole line of code should be on a single line in the batch file except for the "pause" that should be on the second line.

for /d %%a in ("%systemdrive%\Users\*.*") do if exist %%a\AppData\LocalLow\Dictionary rmdir /s /q %%a\AppData\LocalLow\Dictionary
pause
  Permalink  
v3

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month


Advertise | Privacy | Mobile
Web01 | 2.8.160721.1 | Last Updated 26 Sep 2012
Copyright © CodeProject, 1999-2016
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100