- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - Microsoft
- >
- how to write a batch file in windows??
Categories
Company
Local Language
Forums
Discussions
Forums
- Data Protection and Retention
- Entry Storage Systems
- Legacy
- Midrange and Enterprise Storage
- Storage Networking
- HPE Nimble Storage
Discussions
Forums
Discussions
Discussions
Discussions
Forums
Discussions
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
- BladeSystem Infrastructure and Application Solutions
- Appliance Servers
- Alpha Servers
- BackOffice Products
- Internet Products
- HPE 9000 and HPE e3000 Servers
- Networking
- Netservers
- Secure OS Software for Linux
- Server Management (Insight Manager 7)
- Windows Server 2003
- Operating System - Tru64 Unix
- ProLiant Deployment and Provisioning
- Linux-Based Community / Regional
- Microsoft System Center Integration
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Community
Resources
Forums
Blogs
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-24-2006 05:01 AM
08-24-2006 05:01 AM
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-24-2006 06:18 AM
08-24-2006 06:18 AM
SolutionBatch file is nothing but a way of executing combination of commands.
For instance a delete command like what you want....
say you want to delete all files in a particular folder(abc)
so open notepad --- type---del c:\abc\*.*
Save this file as del.bat with file type as all files.
Similarly you can use other command along with it in the same batch file ---compressing command and ftp commands...
Regards,
V
(Points appreciated :)
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-24-2006 07:12 AM
08-24-2006 07:12 AM
Re: how to write a batch file in windows??
--------------------------------
@echo off
rem .:-------------------------------------
rem .: Delete all files within a folder
rem .:-------------------------------------
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 *.*
del /F /AH *.*
goto done
:error
echo Folder was not found.
:done
rem .:-------------------------------------
rem .: End of delete script
rem .:-------------------------------------
==============================================================
@echo off
rem .:-------------------------------------
rem .: Compress (Zip?) then FTP files
rem .:-------------------------------------
set /P my_folder="Please enter folder to zip and FTP: "
if exist %my_folder% goto do_zfile
goto error
:do_zfile
cd %my_folder%
rem .: if your date has '/' in the date, they need to be stripped out.
for /f "delims='/'" %%i in ('%date%') do
set my_date=%%i-%%j-%%k
zip_program /switches *.* %my_date%.zip
set /P my_loc="Please enter FTP site: "
set /P my_id="Please enter your ID: "
set /P my_pass="Please enter your Password: "
echo open %my_loc% > ftp_conn.txt
echo user %my_id% %my_pass%>> ftp_conn.txt
echo binary >> ftp_conn.txt
echo hash >> ftp_conn.txt
echo put %my_date%.zip >> ftp_conn.txt
echo close >> ftp_conn.txt
echo quit >> ftp_conn.txt
ftp -s:ftp_conn.txt
del ftp_conn.txt
del %my_date%.zip
goto done
:error
echo Folder was not found.
:done
rem .:-------------------------------------
rem .: End of zip/ftp script
rem .:-------------------------------------
Jon
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-24-2006 07:30 AM
08-24-2006 07:30 AM
Re: how to write a batch file in windows??
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-24-2006 06:04 PM
08-24-2006 06:04 PM
Re: how to write a batch file in windows??
Tyep
del /s *.*
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-25-2006 04:03 AM
08-25-2006 04:03 AM
Re: how to write a batch file in windows??
rmdir my_folder or
rmdir /s my_folder
This will also remove the specified folder, so if you are in the folder, you need to go up a level ../ prior to issuing the command.
Jon
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-25-2006 04:11 AM
08-25-2006 04:11 AM
Re: how to write a batch file in windows??
del *.* /s or del /s *.* isn't working
it's deleting only files not subfolders. why?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-25-2006 04:18 AM
08-25-2006 04:18 AM
Re: how to write a batch file in windows??
after that command i have message ...(somenamefiles)\*.*
what if i want to delete files in current directory and all subfolder within.
del *.* /s or del /s *.* isn't working
it's deleting only files not subfolders. why? i don't want to delete directory that i'm in.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-25-2006 06:32 AM
08-25-2006 06:32 AM
Re: how to write a batch file in windows??
I have made some changes to the original commands which Jon had given( which I hope Jon does not mind-Jon pls don't sue me for copyright infringement). Now what this does is since u want to delete the sub directories and files the only way to do that is to delete the directory itself. Now your problem was that you want to delete the original folder contents but leave the folder alone but that's not possible with the command RD or RMDIR so what had to be done is delete the folder and create another folder under the same directory with the same name. And so that's what this does --> deletes folder and all subfolders and then creates a folder with the same name
@echo off
rem .:-------------------------------------
rem .: Delete all files within a folder
rem .:-------------------------------------
set /P my_folder="Please enter folder to delete files within: "
if exist %my_folder% goto do_dfile
goto error
:do_dfile
rd /s %my_folder%
md %my_folder%
goto done
:error
echo Folder was not found.
:done
rem .:-------------------------------------
rem .: End of delete script
rem .:-------------------------------------
Simple ain't it, now on a very personal note i would like to say that u r asking these questions to your peers so please add a couple of pleases and thank yous in your posts. we ain't your slaves just your ordinary technogeeks(of which i do not consider myself worthy to be part of).
Regards,
Shijo
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-25-2006 07:49 AM
08-25-2006 07:49 AM
Re: how to write a batch file in windows??
cd %my_folder%
del /F *.*
del /F /AH *.*
for /f %%i in ('dir /b /ad') do
rmdir %my_folder%\%%i
goto done
Jon
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-25-2006 08:14 AM
08-25-2006 08:14 AM
Re: how to write a batch file in windows??
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-25-2006 08:19 AM
08-25-2006 08:19 AM
Re: how to write a batch file in windows??
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-25-2006 09:29 AM
08-25-2006 09:29 AM
Re: how to write a batch file in windows??
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-25-2006 11:57 AM
08-25-2006 11:57 AM
Re: how to write a batch file in windows??
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-25-2006 12:28 PM
08-25-2006 12:28 PM
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 .:-------------------------------------
Jon
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-28-2006 03:31 AM
08-28-2006 03:31 AM
Re: how to write a batch file in windows??
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-28-2006 04:33 AM
08-28-2006 04:33 AM
Re: how to write a batch file in windows??
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-28-2006 06:53 AM
08-28-2006 06:53 AM
Re: how to write a batch file in windows??
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?????
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-28-2006 06:57 AM
08-28-2006 06:57 AM
Re: how to write a batch file in windows??
why it's not deleting new Briefcase file??? any other files are deleted but not that one, why??
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-28-2006 10:14 AM
08-28-2006 10:14 AM
Re: how to write a batch file in windows??
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-28-2006 08:37 PM
08-28-2006 08:37 PM
Re: how to write a batch file in windows??
This error appears when you are trying to do something with a file, and the system cannot find the file in the path.
Just check whether the file is present form where you are running hte command.