Operating System - Microsoft
1752564 Members
4879 Online
108788 Solutions
New Discussion юеВ

Re: how to write a batch file in windows??

 
SOLVED
Go to solution
Shijo
Frequent Advisor

Re: how to write a batch file in windows??

@Jon
So you r looping it to find all dir and delete one by one. I haven't checked it out but if it works thats awesome. *bows down* But my way is still better simple yet efficient. Even though the thought occured to me to use a loop I didn't know how to do it. Heck this is the first time I see a 'for' command used as dos command(gotta learn more). But since Kabucek does not want anything to be in the folder I think my option works..just a sweet wam bam thank you mam.

Regards,
Shijo
You are only limited by the boundaries that you yoursefl put up.
kabucek
Advisor

Re: how to write a batch file in windows??

what if i don't want to specify directory. just simple write ones the batch file. run it and after that it will delete all files and folder within (include hidden, system, etc.) BUT NOT the bath file!! when it will delete all the files i want to take that batch file to different location and do the same thing.
Shijo
Frequent Advisor

Re: how to write a batch file in windows??

@Jon

Jon the for loop does not work, I think the problem is even though the loop might work the my_folder var still has the name of the intial dir, U need to extract the name of each dir in the loop and put it in var my_folder and I don't know how so some guidance please.

Kabucek what u r trying to do does not make any sense, why do you want to put it in the directory when u still have to specify the name of the directory anyway. Put the dat file in the root directory and just execute with the name of the folder u wanna nuke.

Regards,
Shijo
You are only limited by the boundaries that you yoursefl put up.
Jon Finley
Honored Contributor

Re: how to write a batch file in windows??

Minor change... either ()'s need to be used, or the command goes on one line like below:

del /F *.*
del /F /AH *.*
for /f %%i in ('dir /b /ad') do rmdir %my_folder%\%%i

goto done


**note that it "may" wrap, but the command should be on the same line.

Jon
"Do or do not. There is no try!" - Yoda
Jon Finley
Honored Contributor

Re: how to write a batch file in windows??

Ok..... tested and enhanced:

@echo off
rem .:-------------------------------------
rem .: Delete all files within a folder
rem .:-------------------------------------

for /f %%i in ('cd') do set cur_dir=%%i


set /P my_folder="Please enter folder to delete files within: "

if exist %my_folder% goto do_dfile
goto error

:do_dfile

cd %my_folder%

del /F /Q *.* > nul
del /F /Q /AH *.* > nul

for /f %%i in ('dir /b /ad') do rmdir /S /Q "%my_folder%\%%i" > nul

cd %cur_dir%
goto done

:error
echo Folder was not found.

:done

rem .:-------------------------------------
rem .: End of delete script
rem .:-------------------------------------

Jon
"Do or do not. There is no try!" - Yoda
kabucek
Advisor

Re: how to write a batch file in windows??

Thank you very much for all who are involved in that topic. This is very great from yours side to work on that kind of things. I'm very greatfull for your help!! Thank you very much.
Jon Finley
Honored Contributor

Re: how to write a batch file in windows??

Glad to help, and welcome to the forum.

If you'd like to help other members with questions, and you're interesed in earning points, here's how:
http://forums1.itrc.hp.com/service/forums/helptips.do?#28

Jon
"Do or do not. There is no try!" - Yoda
kabucek
Advisor

Re: how to write a batch file in windows??

@echo off
rem .:-------------------------------------
rem .: Delete all files within a folder
rem .:-------------------------------------

for /f %%i in ('cd') do set cur_dir=%%i


set /P my_folder="Please enter folder to delete files within: "

if exist %my_folder% goto do_dfile
goto error

:do_dfile

cd %my_folder%

del /F /Q *.* > nul
del /F /Q /AH *.* > nul

for /f %%i in ('dir /b /ad') do rmdir /S /Q "%my_folder%\%%i" > nul

cd %cur_dir%
goto done

:error
echo Folder was not found.

:done

rem .:-------------------------------------
rem .: End of delete script
rem .:-------------------------------------



- i've got message:
The system cannot find specified file.. why?????
kabucek
Advisor

Re: how to write a batch file in windows??

ok i know what's wrong but i have question.. hehe again

why it's not deleting new Briefcase file??? any other files are deleted but not that one, why??
Jon Finley
Honored Contributor

Re: how to write a batch file in windows??

If a file is in use, (in windows) it can't be deleted. The "My Briefcase" folder is supposted to be a system folder for file transfer (sync'ing of off-line files).

Windows probably believed that it was in use, or was flagged as a system folder so as not to be deleted.

Try running "attrib" on the folder, or view the folder attributes through Windows Explorer.

Jon
"Do or do not. There is no try!" - Yoda