Saturday, November 28, 2009
Remove, Solve And Disable Microsoft Windows Xp Genuine victim errors, Problem And notification With Crack 100% working
First Method
1. Download This File Make Windows Xp Genuine Crack Download
2. Extract This File
3. Open this folder (Verify if your copy is Genuine or not)
4. Open This File To see your Windows is genuine or not (Microsoft Genuine Advantage Diagnostic Tool.exe)
5. if your Windows Xp is to genuine then open this folder (magic regfile)
6. Open dailytipz.reg file and click yes button and then click OK
7. Enjoy your windows is 100% Genuine
Second Method
1. Lauch Windows Task Manager.
2. End wgatray.exe process in Task Manager.
3. Restart Windows XP in Safe Mode.
4. Delete WgaTray.exe from c:\Windows\System32.
5. Delete WgaTray.exe from c:\Windows\System32\dllcache.
6. Lauch RegEdit.
7. Browse to the following location:
HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\
Windows NT\CurrentVersion\Winlogon\Notify
8. Delete the folder ‘WgaLogon’ and all its contents
9. Reboot Windows XP.
Thursday, November 26, 2009
Display CAPS or NUM Lock (Toggle Keys) Status C#
Introduction
A few months ago, I was developing a desktop application for a client. After completing the requirements, I was enhancing the UI specially the main form. In the previous versions of Microsoft Word (before version 2007), there are some labels which are clickable and reflect the changes to the keyboard (details below) and I wanted to add these features to my applications.
HTML documentation of the code has also been included along the source in the zip file. Select the index.html in the HTML folder to view it.
Toggle Keys
There are three LEDs on almost every keyboard, i.e. NUM lock, CAPS lock and SCROLL lock. These LEDS shows the status of the respective keys. As these keys are either in ON state or OFF state, their value is toggled between 1 and 0, so these are called Toggle Keys. The INSERT key is also included in toggle keys, although there is no LED for it but its value is either ON (insert mode) or OFF (overwrite mode), so it is also included in this category.
In my application, I wanted to add the status of NUM lock and CAPS lock. I Googled it and got a solution using Microsoft.VisualBasic.Devices. It was a pretty simple solution but with some limitation. You can only read the status of the keys, no method to set the status of the keys. (I am not going to discuss this here, I might write a separate post for it). The application deadline was very close and I was not able to implement this extra feature as I had planned. Since this feature was not requested by the client, it was delivered with read only options.
Objective
The objective of the post is to get and set the CAPS lock and NUM lock, etc. from the application.
Background
WIN32 API provides a lot of low level functions to access the system hardware. Due to high level of security, these features are not directly available in .NET Framework. To perform low level interaction with hardware, we have to call the WIN32 API methods in .NET using some special syntax.
For this purpose, System.Runtime.InteropServices namespace must be included.
Following the C language style, we have to declare the function so that we could use the method in the code.
NameSpace
using System.Runtime.InteropServices;
Declaration
[DllImport("APIname.dll")]
internal static extern returnType
MethodName (argument(s)); Usage
You can use this method as any other local method:
int nvar = Win32APIMethodName(); WIN32 API Methods Used
Two methods of WIN32 API have been used to achieve the desired results.
[DllImport("user32.dll")]
internal static extern short GetKeyState(int keyCode); The GetKeyState method returns the status of the key specified through the key code argument. Return value will be 0 if off and 1 if on.
Parameter
keyCode: Specifies a virtual-key code for the key to be checked. The code must be a value in the range 1 to 254. For a complete list, see Virtual-Key Codes.
Please check MSDN for a complete description.
[DllImport("user32.dll")]
static extern void keybd_event(byte bVk, byte bScan, uint dwFlags, int dwExtraInfo); This function is useful to simulate Key presses to the window with focus.
Parameters
bVk: Specifies a virtual-key code. The code must be a value in the range 1 to 254. For a complete list, see Virtual-Key Codes.
bScan: Specifies a hardware scan code for the key.
dwFlags: Specifies various aspects of function operation. Normally KEYEVENTF_EXTENDEDKEY or KEYEVENTF_KEYUP are used. If specified, the key is being released. If not specified, the key is being depressed.
dwExtraInfo: Specifies an additional value associated with the key stroke.
Please check MSDN for complete description.
Note: In the test application, instead of the Virtual key Codes, we will be using System.Keys enumeration where required.
Creating a Test Application
Create a new Windows Application Project in C#. From Menus & Toolbar section of the control box, add a Status Strip on your form. Add three labels to the status strip. Name them as lblINS, lblNUM and lblCAPS respectively. It is better to set their width to 40.
Set the DoubleClickEnabled property of these labels to true.
Set the AutoSize property of these labels to false.
Generate the DoubleClick event for these labels to handle the double click action, e.g.
private void lblNUM_DoubleClick(object sender, EventArgs e)
{
PressKeyboardButton(Keys.NumLock);
UpdateNUMLock();
} Form Events
Set the KeyPreview property of the form to true. This will help to pass the keys pressed on the child controls to the parent control (form) (for better understanding of the property, build the attached test application with this property set to false).
In the design view, double click the form to generate its Form_Load event and call the method UpdateKeys. It will read the current status of the keys and update the form accordingly.
private void Form1_Load(object sender, EventArgs e)
{
// read the current status of the specified keys
UpdateKeys();
} Generate the Form1_KeyUp event of the form to handle the key press event (this event is raised when a key is pressed and then released).
private void Form1_KeyUp(object sender, KeyEventArgs e)
{
if (e.KeyData == Keys.Insert)
{
UpdateInsert();
}
else if (e.KeyData == Keys.NumLock)
{
UpdateNUMLock();
}
else if (e.KeyData == Keys.CapsLock)
{
UpdateCAPSLock();
}
} Utility Methods
PressKeyboardButton
This method takes the key code as parameter and simulates a key press event by sending a Key-Down message to the operating system followed by a Key-Up message.
private void PressKeyboardButton(Keys keyCode)
{
const int KEYEVENTF_EXTENDEDKEY = 0x1;
const int KEYEVENTF_KEYUP = 0x2;
keybd_event((byte)keyCode, 0x45, KEYEVENTF_EXTENDEDKEY, 0);
keybd_event((byte)keyCode, 0x45, KEYEVENTF_EXTENDEDKEY | KEYEVENTF_KEYUP, 0);
} UpdateNUMLock
It reads the status of the NUM lock using GetKeyState and updates the form accordingly.
this.Refresh() has been called at the end to ensure the form update by sending a Redraw request.
private void UpdateNUMLock()
{
bool NumLock = (GetKeyState((int)Keys.NumLock)) != 0;
if (NumLock)
{
lblNUM.Text = "NUM";
}
else
{
lblNUM.Text = String.Empty;
}
this.Refresh();
} Similarly, the other methods for CAPS lock and INSERT can also be implemented.
Conclusion
Your application will be able to reflect the status of the toggle keys. Also you can update the status of these keys from your application by double clicking the labels in the status strip.
Although I have been reading the articles and blogs for a long time, now I decided to make my contribution by sharing my knowledge and experience. I would love to get your feedback on this and do not forget to rate the post if you like it.
Wednesday, November 25, 2009
Exporting a DataGridView to Excel in .NET 2.0 (C# code)
Hi everyone! In this article I would be telling you how to export the contents of a .NET 2.0 DataGridView control to an excel file. This is a requirement often in many projects as users may want to save some data generated in applications for future reference. And as most other things .NET makes it really easy for the programmers.
Background
Most Microsoft Office products such as Word, Outlook etc are available to a .NET programmer as classes. Similarly Excel is also available as an Application class. To use it
1. Add a reference to the ‘Microsoft Office 11.0 Object Library’ to your project from COM components.
2. Create an object of the ApplicationClass in the Excel namespace
Collapse
Excel.ApplicationClass ExcelApp = new Excel.ApplicationClass();
Excel application calls an excel file as a WorkBook. To export data to an excel file we need to create a new workbook in the application that is just created. Also more than one workbook can be opened in the application at a time (there is a collection called WorkBooks in the Excel application object). Only one of them will be the ActiveWorkBook (which can be access by the ActiveWorkBook property of the object). All the workbook related operations done to the application object will be directed to the ActiveWorkBook. We will need only one workbook. So that, by default, will be the ActiveWorkBook.
Using the Code
3. Add a new workbook to the object of the Application class. The parameter to the Add method below is the name of the workbook. We are going to provide the name later (while saving the workbok). So Type.Missing can be used here. ExcelApp.Application.Workbooks.Add(Type.Missing);
This is the stage where you can set general properties of the workbook. For example we can set the width of all the columns of the Workbook if you are not happy with the default column width.
4. Change properties of the Workbook
Collapse
ExcelApp.Columns.ColumnWidth = 30;
Next step is to copy the contents of the DataGridView to the Excel workbook. The cells of the WorkBook in the Excel application object can be accessed like a matrix. But one thing that you have to be careful about is that here the row and column numbering starts from 1. If you start from 0 you will get some weird exceptions. Iterate through each cell of the DataGridView object and copy the contents to the cells of the Excel Application Object (which goes to its active work book).
5. Copy the contents of the DataGridView object to the cells of the Excel Application object. In the code below ReportDataGrodView is the name of my DataGridView object.
Collapse
for (int i = 0; i <>
{
DataGridViewRow row = ReportDataGridView.Rows[i];
for(int j=0; j<>
{
ExcelApp.Cells[i+1, j+1] = row.Cells[j].ToString();
}
}
Then we have to save the workbook. There are 3 functions provided for that. Save, SaveAs and SaveCopyAs. I am using SaveCopyAs since I know that this is a new file generated and it cannot exist before. Probe on the other functions if you have a different requirement.
6. Save the workbook at any suitable location. In the code below FileName is a string representing full path to the name of the file. This can be obtained from a SaveFileDialog if you want.
Collapse
ExcelApp.ActiveWorkbook.SaveCopyAs(FileName);
ExcelApp.ActiveWorkbook.Saved = true;
Finally you have to close the Excel Application to free up the resources.
Exit the Excel Application and free up the resources
Collapse
ExcelApp.Quit();
Summary
I have given below the summary of the seven steps required.
1. Add a reference to the ‘Microsoft Office 11.0 Object Library’ to your project from COM components.
2. Create an object of the ApplicationClass in the Excel namespace
Collapse
Excel.ApplicationClass ExcelApp = new Excel.ApplicationClass();
3. Add a new workbook to the object of the Application class. The parameter to the Add method below is the name of the workbook. We are going to provide the name later (while saving the file). So Type.Missing can be used here.
Collapse
ExcelApp.Application.Workbooks.Add(Type.Missing);
4. Change properties of the Workbook
Collapse
ExcelApp.Columns.ColumnWidth = 30;
5. Copy the contents of the DataGridView object to the cells of the Excel Application object. In the code below ReportDataGrodView is the name of my DataGridView object.
Collapse
for (int i = 0; i <>
{
DataGridViewRow row = ReportDataGridView.Rows[i];
for(int j=0; j<>
{
ExcelApp.Cells[i+1, j+1] = row.Cells[j].ToString();
}
}
6. Save the workbook at any suitable location. In the code below FileName is a string representing full path to the name of the file. This can be obtained from a SaveFileDialog if you want.
Collapse
ExcelApp.ActiveWorkbook.SaveCopyAs(FileName);
ExcelApp.ActiveWorkbook.Saved = true;
7. Exit the Excel Application and free up the resources
Collapse
ExcelApp.Quit();
Monday, November 23, 2009
Auto-Save to PDF ASP.NET C#
server side (reporting server), hence the ASP.NET.
save a report on the server side, you can call Reporting Services'
web services to generate the report, render it in desired format and save
it.
I just write a peice of code to allow user to request a report to be send to
a given email address as an attachment. Here is the simplified code (note,
you need to add web reference to the reporting services' web services):
private void GetReportByEmail()
{
//Validate txtEmail for inputting
if (txtEmail.Text.ToUpper().StartsWith("XX"))
{
lblPrompt.Text="You must enter a valid email address!";
lblPrompt.Visible=true;
return;
}
if (txtEmail.Text.IndexOf("@")<3) text="You must enter a valid email address!" visible="true;" rs="new" url="http://localhost/ReportServer/ReportService.asmx" credentials="System.Net.CredentialCache.DefaultCredentials;" report="/WDTimeSheets/TimeSheetEmp/PayrollSummary" historyid="null;" deviceinfo="null;" pmts="new" pmt="new" name="EmployeeID" value="lblEmpID.Text;" pmt="new" name="FromDate" value="DateTime.Parse(ddlFrom.SelectedValue).ToString(" pmt="new" name="ToDate" value="DateTime.Parse(txtTo.Text).ToString(" credentials="null;" showhide="null;" encoding="null;" mimetype="null;" pmtused="null;" warnings="null;" streamids="null;" reportdata="rs.Render(report," class="hilite4">PDF",historyID,deviceInfo,pmts,credentials,showHide,
out encoding,out mimetype,out pmtUsed,out warnings,out streamIDs);
}
catch(System.Web.Services.Protocols.SoapException ex)
{
lblPrompt.Text=ex.Message;
lblPrompt.Visible=true;
return;
}
//Save PDF report to a temp location
string
folder=System.Configuration.ConfigurationSettings.AppSettings["TempDataFolder"];
if (Directory.Exists(folder))
{
//Get a random file name
string f="PayRollSummary_" + DateTime.Today.ToString("yyyy-MM-dd") + "_"
+ lblEmpID.Text;
string fileName=folder + "\\" + f + ".pdf";
//Save the report (PDF) in a configured location
try
{
if (File.Exists(fileName)) File.Delete(fileName);
FileStream fs=File.OpenWrite(fileName);
fs.Write(reportData,0,reportData.Length);
fs.Close();
}
catch(System.IO.IOException ex)
{
lblPrompt.Text=ex.Message;
lblPrompt.Visible=true;
return;
}
//Send PDF file with email
EmailReport(fileName); //Method is omitted
}
else
{
lblPrompt.Text="Web server configuration error: emailing operation was
cancelled.";
lblPrompt.Visible=true;
}
}
Retreive current user permissions in SQL Server 2005
Retreive current user permissions in SQL Server 2005
If you want to retrieve the permissions available for the currently logged in user then you can use the function called fn_my_permissions in SQL Server 2005. Following are examples of its usage:
Use AdventureWorks
Go
—Return Caller’s permission on the current server
SELECT * FROM fn_my_permissions(NULL, ‘SERVER’);
Go
—Return Caller’s permission on the current database
SELECT * FROM fn_my_permissions(NULL, ‘DATABASE’);
Go
SELECT * FROM fn_my_permissions(‘Sales.vIndividualCustomer’, ‘OBJECT’);
Go
Friday, November 20, 2009
Download File with ProgressBar ASP.NET
Add this using statement to the top of the form.
using System.Net;
private void btnStartDownload_Click(object sender, EventArgs e)
{
WebClient client = new WebClient();
client.DownloadProgressChanged += new DownloadProgressChangedEventHandler(client_DownloadProgressChanged);
client.DownloadFileCompleted += new AsyncCompletedEventHandler(client_DownloadFileCompleted);
// Starts the download
client.DownloadFileAsync(new Uri("SomeURLToFile"), "SomePlaceOnLocalHardDrive");
btnStartDownload.Text = "Download In Process";
btnStartDownload.Enabled = false;
}
In the previous code, we are creating two event handlers to handle when
the Progress of the file download changes, and when the download
completes.
We also use the DownloadFileAsync method so that the download(which could be lengthy) does not freeze the main GUI.
Next, we need to do the code to calculate the percentage of the download complete so that we can assign it to the ProgressBar.
void client_DownloadProgressChanged(object sender, DownloadProgressChangedEventArgs e)
{
double bytesIn = double.Parse(e.BytesReceived.ToString());
double totalBytes = double.Parse(e.TotalBytesToReceive.ToString());
double percentage = bytesIn / totalBytes * 100;
progressBar1.Value = int.Parse(Math.Truncate(percentage).ToString());
}
In this code, we use the BytesReceived and TotalBytesToReceive properties of the DownloadProgressChangedEventArgs object.
Next, we need to do the code for the event when the download completes.
void client_DownloadFileCompleted(object sender, AsyncCompletedEventArgs e)
{
MessageBox.Show("Download Completed");
btnStartDownload.Text = "Start Download";
btnStartDownload.Enabled = true;
}
Dynamically Creat Menu C#
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Data.Odbc;
namespace Reports
{
public partial class Reports : Form
{
OdbcDataReader od;
Connect c = new Connect();
string[] menuitem=new string[20];
MenuStrip menu = new MenuStrip();
int id = 0;
public Reports()
{
InitializeComponent();
}
private void Reports_Load(object sender, EventArgs e)
{
c.cmd().CommandText = "select distinct r.undermenu,r.undername from rptlist as r ,user_auth as u where r.menuname=u.repotname and u.uid='02' and u.prm='1' ";
c.cmd().Connection = c.cn();
od = c.cmd().ExecuteReader();
while (od.Read())
{
string s = od["undermenu"].ToString();
// menuStrip1.Items.Add(s);
//menuStrip1.Items.Add(s);
menuitem.SetValue(s, id);
id++;
}
od.Close();
for (int i =0; i< id ; i++)
{
ToolStripMenuItem item = new ToolStripMenuItem(menuitem[i].ToString());
// string menuname = menuStrip1.Items[i].Text.ToString();
c.cmd().CommandText = "select r.menuname from rptlist as r ,user_auth as u where r.menuname=u.repotname and u.uid='02' and r.undermenu like '" + menuitem[i].ToString() + "'and u.prm='1' order by r.undermenu,r.menuname";
c.cmd().Connection = c.cn();
od = c.cmd().ExecuteReader();
while (od.Read())
{
string sa = od["menuname"].ToString();
// menuStrip1.Items.Add(s);
item.DropDownItems.Add(sa.ToString(),null,new System.EventHandler(menuitem_click));
menu.Items.Add(item);
// item.Click += new EventHandler (this.menuitem_click);
}
od.Close();
}
this.Controls.Add(menu);
}
Connection Class C# .Net
using System;
using System.Collections.Generic;
using System.Text;
using System.Data.Odbc;
namespace Reports
{
class Connect
{
OdbcConnection con = new OdbcConnection("dsn=local");
OdbcCommand cm = new OdbcCommand();
OdbcDataReader od;
OdbcDataAdapter odz = new OdbcDataAdapter();
public OdbcConnection cn()
{
if (con.State.ToString() == "Open")
{
}
else if (con.State.ToString() == "Closed" || con.State.ToString() == "Broken")
{
con.Open();
}
return con;
}
public OdbcCommand cmd()
{
return cm;
}
public OdbcDataReader odr()
{
return od;
}
public OdbcDataAdapter oda()
{
return odz;
}
}
}
Tuesday, November 17, 2009
Monday, November 16, 2009
Thursday, November 12, 2009
World Cup 2011 Match Schedule
World Cup 2011
| Feb-2011 | |
| Sat 19 | 1st match - Bangladesh v India Shere Bangla National Stadium, Mirpur |
| Sun 20 | 2nd match - Sri Lanka v Canada MA Chidambaram Stadium, Chennai |
| Sun 20 | 3rd match - New Zealand v Kenya Venue TBC |
| Mon 21 | 4th match - Australia v Zimbabwe Sardar Patel Stadium, Ahmedabad |
| Tue 22 | 5th match - England v Netherlands Vidarbha Cricket Association Stadium, Nagpur |
| Wed 23 | 6th match - Pakistan v Kenya Venue TBC |
| Thu 24 | 7th match - South Africa v West Indies Feroz Shah Kotla, New Delhi |
| Fri 25 | 8th match - Australia v New Zealand Vidarbha Cricket Association Stadium, Nagpur |
| Fri 25 | 9th match - Bangladesh v Ireland Shere Bangla National Stadium, Mirpur |
| Sat 26 | 10th match - Sri Lanka v Pakistan Venue TBC |
| Sun 27 | 11th match - India v England Eden Gardens, Kolkata |
| Mon 28 | 13th match - Canada v Zimbabwe Vidarbha Cricket Association Ground (old), Nagpur |
| Mon 28 | 12th match - West Indies v Netherlands Feroz Shah Kotla, New Delhi |
| Mar-2011 | |
| Tue 01 | 14th match - Sri Lanka v Kenya Venue TBC |
| Wed 02 | 15th match - England v Ireland M. Chinnaswamy Stadium, Bangalore |
| Thu 03 | 16th match - South Africa v Netherlands Punjab Cricket Association Stadium, Chandigarh |
| Thu 03 | 17th match - Pakistan v Canada Venue TBC |
| Fri 04 | 19th match - Bangladesh v West Indies Shere Bangla National Stadium, Mirpur |
| Fri 04 | 18th match - New Zealand v Zimbabwe Sardar Patel Stadium, Ahmedabad |
| Sat 05 | 20th match - Sri Lanka v Australia Venue TBC |
| Sun 06 | 21st match - India v Ireland M. Chinnaswamy Stadium, Bangalore |
| Sun 06 | 22nd match - South Africa v England MA Chidambaram Stadium, Chennai |
| Mon 07 | 23rd match - Canada v Kenya Feroz Shah Kotla, New Delhi |
| Tue 08 | 24th match - Pakistan v New Zealand Pallekele, Kandy |
| Wed 09 | 25th match - India v Netherlands Feroz Shah Kotla, New Delhi |
| Thu 10 | 26th match - Sri Lanka v Zimbabwe Pallekele, Kandy |
| Fri 11 | 27th match - West Indies v Ireland Punjab Cricket Association Stadium, Chandigarh |
| Fri 11 | 28th match - Bangladesh v England Chittagong Divisional Stadium, Chittagong |
| Sat 12 | 29th match - India v South Africa Vidarbha Cricket Association Stadium, Nagpur |
| Sun 13 | 30th match - New Zealand v Canada Wankhede Stadium, Mumbai |
| Sun 13 | 31st match - Australia v Kenya M. Chinnaswamy Stadium, Bangalore |
| Mon 14 | 33rd match - Bangladesh v Netherlands Chittagong Divisional Stadium, Chittagong |
| Mon 14 | 32nd match - Pakistan v Zimbabwe Pallekele, Kandy |
| Tue 15 | 34th match - South Africa v Ireland Eden Gardens, Kolkata |
| Wed 16 | 35th match - Australia v Canada M. Chinnaswamy Stadium, Bangalore |
| Thu 17 | 36th match - England v West Indies MA Chidambaram Stadium, Chennai |
| Fri 18 | 38th match - Ireland v Netherlands Eden Gardens, Kolkata |
| Fri 18 | 37th match - Sri Lanka v New Zealand Wankhede Stadium, Mumbai |
| Sat 19 | 39th match - Pakistan v Australia R.Premadasa Stadium, Colombo |
| Sat 19 | 40th match - Bangladesh v South Africa Shere Bangla National Stadium, Mirpur |
| Sun 20 | 41st match - Zimbabwe v Kenya Eden Gardens, Kolkata |
| Sun 20 | 42nd match - India v West Indies MA Chidambaram Stadium, Chennai |
| Wed 23 | 1st Quarter Final - TBD v TBD Shere Bangla National Stadium, Mirpur |
| Thu 24 | 2nd Quarter Final - TBD v TBD R.Premadasa Stadium, Colombo |
| Fri 25 | 3rd Quarter Final - TBD v TBD Shere Bangla National Stadium, Mirpur |
| Sat 26 | 4th Quarter Final - TBD v TBD Sardar Patel Stadium, Ahmedabad |
| Tue 29 | 1st Semi Final - TBD v tbd R.Premadasa Stadium, Colombo |
| Wed 30 | 2nd Semi Final - TBD v TBD Punjab Cricket Association Stadium, Chandigarh |
| Apr-2011 | |
| Sat 02 | The Final - TBD v TBD Wankhede Stadium, Mumbai |
Wednesday, September 9, 2009
ASP.NET Ajax Calendar Extender and Validation ...
ASP.NET Ajax toolkit has a CalendarExtender control which is very cool as you can associate the CalendarExtender to a a TextBox and also to a Button/ImageButton so that you can popup the calendar.
Below is the code to get started with CalendarExtender:
runat="server"
width="300pt" />
Width="16" Height="16"
runat="server"
ImageUrl="~/images/calender.bmp"
CausesValidation="False" />
runat="server"
TargetControlID="TextBox1"
PopupButtonID="btnCalenderPopup"
Format="dd/MM/yyyy" />
And here is the output:


Wait! What’s that grayed text in the textbox that says - Enter the Date of Birth (dd/mm/yyyy)
Certainly that’s not the part of CalendarExtender :) , but part of ASP.NET Ajax Toolkit 8) . We can use the TextBoxWatermarkExtender which can display watermarked (grayed) texts on controls. Below is the code for our CalendarExtender :
runat="server"
TargetControlID="TextBox1"
WatermarkCssClass="watermarked"
WatermarkText="Enter the Date of Birth (dd/mm/yyyy)" />
And below is the CSS style that’s used with this watermark extender :
.watermarked
{
color: #C0C0C0;
font-style: italic;
}
All looks good now and the user is happy the way Calendar pops up, choosing the date and also the fact that he can type in the date in the textbox in the desired format. Now comes the problem - Date Validation! - How are we going to validate the entered date? - I had to validate that the date entered is not more than today’s date.
There are two ways to do it :
1) Using Javascript (with our CalendarExtender)
2) Using RangeValidators for our textbox
Using Javascript:
The CalendarExtender has a property called OnClientDateSelectionChanged which can be set to a piece of javascript which can do the job for us. Below is the code:
runat="server"
TargetControlID="TextBox1"
PopupButtonID="btnCalenderPopup"
OnClientDateSelectionChanged="checkMyDate"
Format="dd/MM/yyyy" />
and below is the javascript:
Using RangeValidator:
Since we use a TextBox control to display our date once we choose from the calendar or to manually input the date, RangeValidators can be used to check whether the date is within a given range (minimum & maximum). Below is the code for RangeValidator :
runat="server"
ControlToValidate="TextBox1"
ErrorMessage="*Please enter proper date"
Type="Date" Display="Dynamic" />
And in your page load event we can set our maximum and minimum date values :
RangeValidator1.MinimumValue
= new DateTime(1600, 01, 01).ToString("dd/MM/yyyy");
RangeValidator1.MaximumValue
= DateTime.Now.ToString("dd/MM/yyyy");
With these two methods you can easily validate the date. And yes, using both would sometimes lead you to race conditions where choosing a date from the calendar might be an invalid date and the RangeValidators would immediately come to the focus
Tuesday, September 8, 2009
Cricket Match Schedule 2010
Months | Versus | Matches | Fixtures & Result |
January | England in South Africa | 4 tests + 5 ODI + T20 | Eng in SA 2010 |
February-March | England in Bangladesh | 2 tests + 3 ODIs | Eng in Bdesh 2010 |
April | T20 WC in West Indies | Twenty20 World cup | World T20 2010 |
May | Bangladesh in England | 2 Test + 3 ODI | Bdesh in Eng 2010 |
June | Australia in England | 5 ODI Series | Aus in Eng 2010 |
July-August | West Indies in England | 4 Test + 5 ODI | WI in Eng 2010 |
Nov-Dec | England in Australia | Ashes 2011 | Ashes 2010 |
January | India in Bangladesh | 2 Test + Triseries | India in Bdesh 2010 |
February-March | South Africa in India | 3 Test + 5 ODI | SA in Ind 2010 |
April | Asia Cup | ODI Tournament | Asia Cup 2010 |
April | T20 WC in West Indies | Twenty20 World Cup | World T20 2010 |
May | India in Zimbabwe | 3 ODI Series | Ind in Zim 2010 |
July | India in Sri Lanka | Triseries | Ind v NZ v SL |
October | Australia in India | 7 ODI Series | Aus in Ind 2010 |
November | New Zealand in India | 3 Test + 5 ODI | NZ in Ind 2010 |
January | Pakistan in Australia | 3 Test + 5 ODI + T20 | Pak in Aus 2010 |
February | West Indies in Australia | 5 ODI + T20 | WI in Aus 2010 |
March-April | Australia in New Zealand | 3 Test + 5 ODI + 2 T20s | Aus in NZ 2010 |
April | T20 World Cup in WI | Twenty20 World Cup | World T20 2010 |
June | Australia in England | 5 ODI Series | Aus in Eng 2010 |
July | Bangladesh in Australia | 2 Tests | Bdesh in Aus 2010 |
September | Australia in Pakistan | 3 Tests | Aus in Pak 2010 |
October | Australia in India | 7 ODI series | Aus in Ind 2010 |
November | England in Australia | 5 Test Series | Ashes 2010-11 |
January | Pakistan in Australia | 3 Test + 5 ODI + T20 | Pak in Aus 2010 |
April | Asia Cup | ODI Tournament | Asia Cup 2010 |
April | T20 World cup in West Indies | Twenty20 World Cup | World T20 2010 |
August | Bangladesh in Pakistan | 2 Test + 3 ODI | Bdesh in Pak 2010 |
September | Australia in Pakistan | 3 Test Series | Aus in Pak 2010 |
Oct-Nov | South Africa in Pakistan | 3 Test + 5 ODI | SA in Pak 2010 |
February | Bangladesh in New Zealand | 1 Test, 3 ODI, 2 T20 | Bdesh in NZ 2010 |
March-April | Australia in New Zealand | Test + ODI + T20 | Aus in NZ 2010 |
April | T20 World cup in West Indies | Twenty20 World Cup | WC T20 2010 |
July | New Zealand in Sri Lanka | Triseries | Ind v NZ v SL |
October | New Zealand in Bangladesh | 2 Test + 3 ODI | NZ in Bdesh 2010 |
November | New Zealand in India | 3 Test + 5 ODI | NZ in Ind 2010 |
January | Srilanka in Bangladesh | Triseries | Ind v SL v Bdesh |
April | Asia Cup | ODI Tournament | Asia Cup 2010 |
April | T20 World cup in West Indies | Twenty20 World Cup | WC T20 2010 |
July | India & New Zealand in Sri Lanka | Tri Series | Ind v NZ v SL |
Nov-Dec | West Indies in Sri Lanka | 3 Test + 5 ODI | WI in SL 2010 |
January | England in South Africa | 4 Test + 5 ODI | Eng in SA 2010 |
February-March | South Africa in India | 3 Test + 5 ODI | SA in Ind 2010 |
April | T20 World cup in WI | Twenty20 World Cup | WC T20 2010 |
May-June | South Africa in West Indies | 4 Test + 5 ODI | SA in WI 2010 |
September | Zimbabwe in South Africa | ODI Series | Zim in SA 2010 |
Oct-Nov | South Africa in Pakistan | 3 Test + 5 ODI | SA in Pak 2010 |
February | West Indies in Australia | 5 ODI + T20 | WI in Aus 2010 |
March | Zimbabwe in West Indies | ODI Series | Zim in WI 2010 |
April | T20 World cup in West Indies | Twenty20 World Cup | WC T20 2010 |
May-June | South Africa in West Indies | 4 Test + 5 ODI | SA in WI 2010 |
July - August | West Indies tour of England | 4 Test + 5 ODI | WI in Eng 2010 |
Nov-Dec | West Indies in Sri Lanka | 3 Test + 5 ODI | WI in SL 2010 |
January | SL & Ind in Bdesh | ODI Triseries | Ind v SL v Bdesh |
January | India in Bangladesh | 2 Tests | Ind in Bdesh 2010 |
February | Bangladesh tour of New Zealand | Test + ODI + T20 | Bdesh in NZ 2010 |
March | England in Bdesh | Test + ODI | Eng in Bdesh 2010 |
April | Asia Cup | ODI Tournament | Asia cup 2010 |
April | T20 World cup in West Indies | Twenty20 World cup | World T20 2010 |
May | Bangladesh in England | 2 Test + 3 ODI | Bdesh in Eng 2010 |
July | Bangladesh in Australia | 2 Tests | Bdesh in Aus 2010 |
August | Bangladesh in Pakistan | 2 Test + 3 ODI | Bdesh in Pak 2010 |
October | New Zealand in Bangladesh | 2 Test + 3 ODI | NZ in Bdesh 2010 |
Tuesday, July 28, 2009
Create Dynamic Text Boxes in Asp.Net C#
C# Code : -
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
public partial class jjjj : System.Web.UI.Page
{
int tl = 0;
private static int i = 0;
protected void Page_Load(object sender, EventArgs e)
{
}
public int NumberOfControls
{
get
{
if (ViewState["Count"] == null)
{
return 0;
}
return (int)ViewState["Count"];
}
set
{
ViewState["Count"] = value++;
}
}
private void ReadTextBoxes()
{
string strValue;
strValue = string.Empty;
int n = NumberOfControls;
for (int i = 1; i <= NumberOfControls; i++)
{
string boxName = "TextBoxID" + (i + 1).ToString();
Panel panl = Table1.FindControl(boxName) as Panel;
strValue += panl.ToString() + "\n";
//TextBox tb = Table1.FindControl(boxName) as TextBox;
//strValue += tb.Text + "\n";
}
Response.Write(strValue);
}
private void CreateTextBoxes()
{
for (int counter = 1; counter <= NumberOfControls; counter++)
{
Panel panl = new Panel();
panl.Width = 150;
panl.Height = 20;
panl.BorderWidth = 1;
Label lbpanel = new Label();
//TextBox tb = new TextBox();
//tb.Width = 150;
//tb.Height = 18;
//tb.TextMode = TextBoxMode.SingleLine;
if (counter == 1)
{
panl.ID = "TextBoxID" + (counter).ToString();
lbpanel.ID = "Label" + counter.ToString();
lbpanel.Text = ListBox1.SelectedValue.ToString();
Table table = new Table();
if (tl <= 30)
{
// Table Table1 = new Table();
table.ID = "tl" + tl.ToString();
for (int rows = 0; rows < 2; rows++)
{
TableRow tr = new TableRow();
int td = 0;
//for (int td = 0; td < 10; td++) ;
while (td <= 10)
{
TableCell tc = new TableCell();
TableCell tc1 = new TableCell();
TextBox tb = new TextBox();
tb.ID = "texb" + i.ToString();
tc.Controls.Add(tb);
tr.Cells.Add(tc);
i++;
td++;
}
//table2.Rows.Add(tr);
table.Rows.Add(tr);
panl.Controls.Add(table);
//table.Rows.Add(tr);
}
tl++;
}
}
else
{
panl.ID = "TextBoxID" + (counter + 1).ToString();
lbpanel.ID = "Label" + counter.ToString();
lbpanel.Text = ListBox1.SelectedValue.ToString();
Table table = new Table();
if (tl <= 30)
{
// Table Table1 = new Table();
table.ID = "tl" + tl.ToString();
for (int rows = 0; rows < 2; rows++)
{
TableRow tr = new TableRow();
int td = 0;
//for (int td = 0; td < 10; td++) ;
while (td <= 10)
{
TableCell tc = new TableCell();
TableCell tc1 = new TableCell();
TextBox tb = new TextBox();
tb.ID = "texb" + i.ToString();
tc.Controls.Add(tb);
tr.Cells.Add(tc);
i++;
td++;
}
//table2.Rows.Add(tr);
table.Rows.Add(tr);
panl.Controls.Add(lbpanel);
panl.Controls.Add(table);
//table.Rows.Add(tr);
}
tl++;
}
}
//tb.Text = "Enter Title " + counter;
TableRow FirstRow = new TableRow();
TableCell FirstCell = new TableCell();
//TextBox YourTextBox = new TextBox();
FirstCell.Controls.Add(panl);
FirstRow.Cells.Add(FirstCell);
Table1.Rows.Add(FirstRow);
}
}
protected override void CreateChildControls()
{
if (Page.IsPostBack)
{
NumberOfControls += 0;
CreateTextBoxes();
}
else
{
CreateTextBoxes();
NumberOfControls = 1;
}
}
protected void Button1_Click(object sender, EventArgs e)
{
if (ListBox1.SelectedValue !=null)
{
NumberOfControls += 1;
}
else
{
}
}
}
Thursday, July 16, 2009
Batch Files
Advanced II PreliminaryRead This First!
BU.batAutomatic Backups
DATEFILE.batNames a File withthe Current Date(Includes DATE-DIR.bat)
CTTP.batTransfer Files Quickly
EDZIP.bat(Improved)A Space-Saver System
EXPUNGE.batDeleted-File Security
PA.batA Path Master
REMIND.batA Note Reminder
TIMER.batLogs Task Start & StopDates and Times
ZTB.batZips Files to the `B' Drive
ZTE.batZip-File to Executable
PRELIMINARY
Here are more examples of advanced batch files. As with the first Advanced Batch File Examples, the title remarks should suffice so you'll understand their operation, although some may be preceded by a syntax example. In addition, some lines have notes to the side. These explanatory notes are not part of the file. Do not type them in. As well, the most complicated examples have explanations following the file itself. Before reading this section, see Batch File Basics for further information and techniques regarding DOS batch files.
Note that because this is an advanced page and that you should have read the previous batch file pages at this site, not every little thing will be explained.
Once again, the "DR" command is a batch file that runs the Color Directory program I use. You may substitute DOS' "DIR" command with its switches set to your preferences. Also, it is assumed that you are placing all batch files into the "C:\BATCH" directory and that it is in your path.
Finally, be aware that Doctor DOS will not be responsible for any problems resulting from the use or mis-use of anything presented here.
An advisory to non-Canadians: Some characters shown in some batchfiles here may not be able to be reproduced on your system unlessthe Country Code is changed or you type them in as ASCII characters.Consult your text editor/word processor manual to see how to do the latter.
EXCEPT FOR THE BATCH FILES THEMSELVES,INFORMATION ON THESE BATCH FILE PAGESMAY NOT BE REPRODUCED WITHOUT PERMISSIONFROM THE AUTHOR ©THE BATCH FILES ARE FOR PERSONAL USE ONLY.THEY MAY NOT BE SOLD OR OTHERWISE DISTRIBUTED.
THE BATCH FILES
AN AUTOMATIC BACKUP ROUTINE
This is a simple backup batch file that will archive files residing in a given directory into a single .zip file and place that .zip file into a BACKUP directory. As a bonus, the .zip file will automatically be given a name made from the current date. Improvements are given afterwards that will allow the file to be run automatically on a weekday of choice upon boot up, and also to delete old archive files back before a specified previous time.
Date operations will be handled by an update to the DOS "SET" command called "XSET". It reduces the code required to get the date into an environment variable to just one line, so no extra files are required, as was the case with CTULD.bat in the first Advanced Batch Files. An explanation follows each part and an XSET link will be given at the end.
Those of you with the %DATE% variable built into your version of DOS may eliminate the XSET lines that are used to get the date into the environment and rework the remainder of file to take this into account.
It will be assumed that you are backing up all files from a directory named "DATA" to a directory named "BACKUP", that you are using PKZIP, which is located in a "PKZIP" directory under a "UTIL" directory, and that you have placed XSET into the DOS directory - all of which are located on the `C' drive. It is also assumed that you boot the computer each morning.
You must first create the C:\BACKUP directory yourself. Once it's created, it will be available for this purpose and it will eventually contain a series of.zip archive files in chronological order. From any of these you may recreate your data files as they were at the start of any given date. You may change any or all of these directories to suit your setup or purpose. If you prefer to use another compression program, change the "PKZIP" reference & directory to match the program you plan to use.
BU.bat
:: BU.bat
:: Archives All Files from the C:\DATA directory into a .ZIP file
:: The .zip File is Placed into the C:\BACKUP directory.
::
@ECHO OFF
C:\DOS\XSET CUR-DATE DATE YY-MM-DD
C:\UTIL\PKZIP\PKZIP C:\BACKUP\%CUR-DATE%.ZIP C:\DATA\*.*
:END
SET CUR-DATE=
________
Explanation
This file starts by using XSET to place the current date into the environment as a variable called "CUR-DATE". It is in the form of a two-digit year, two-digit month, and two-digit day (YY-MM-DD). Next, PKZIP is used to compress copies of all the files in the DATA directory into one zip file called (date).zip. So if you are working on files and it is January 22nd, 2007, the backup file will be called "07-01-22.zip". Finally, the "CUR-DATE" variable is reset to remove it from memory. That's it! Simple, huh?
An Improvement
Now, it would be handy if this operation could be done automatically on say, every Monday morning upon bootup. This would give a backup of the previous week's files every Monday. Here's that version:
:: BU.bat (Improved)
:: Archives All Files from the C:\DATA directory into a .ZIP file
:: The .zip File is Placed into the C:\BACKUP directory.
:: This is Done Every Monday Morning Upon Bootup
::
@ECHO OFF
C:\DOS\XSET DAY DAYOFWEEK
IF NOT "%DAY%" == "1" GOTO END
:BACKUP
C:\DOS\XSET CUR-DATE DATE YY-MM-DD
C:\UTIL\PKZIP\PKZIP C:\BACKUP\%CUR-DATE%.ZIP C:\DATA\*.*
:END
SET CUR-DATE=
SET DAY=
________
Explanation
In this version, XSET is used to place the day of the week into the environment variable "DAY". XSET uses the numbers "0 - 7" to represent the days of the week "Sunday - Saturday". Thus, Monday is Day Number 1. Our batch file above tests to see if it's Monday, by seeing if the variable equals `1'. If it does not, the batch file ends. If it does, the test line is ignored and the file moves on to BACKUP where the backup is performed as in the first version of the batch file. In either case, any variables made are set to equal nothing to remove them from memory. This is done via DOS' "SET" command, which is capable of doing the job, and also be faster at it than XSET because it's an internal DOS command.
For this file to work automatically, place a command near the end of your AUTOEXEC.bat to run the "BU.bat" file. Upon bootup on Monday mornings, the previous week's DATA files will be backed up into a compressed archive. If you go this route, be sure to use the "CALL" command so that DOS will return to the AUTOEXEC.bat afterwards so as to finish it. The syntax is: CALL C:\BATCH\BU.BAT.
A Further Improvement
This is all fine & dandy until you have to reboot during the day on which the backup has been performed. With the above example, the backup routine would run again but would include any changed files from the current week's Monday. That would spoil the "snapshot" of the previous week's files as seen at the end of that week. The solution is to have the batch file ask if the previous week's backup file already exists before doing the backup routine:
:: BU.bat (Improvement 2)
:: Archives All Files from the C:\DATA directory into a .ZIP file
:: The .zip File is Placed into the C:\BACKUP directory.
:: This is Done Every Monday Morning Upon First Bootup Only
::
@ECHO OFF
C:\DOS\XSET DAY DAYOFWEEK
IF NOT "%DAY%" == "1" GOTO END
:BACKUP
C:\DOS\XSET CUR-DATE DATE YY-MM-DD
IF EXIST C:\BACKUP\%CUR-DATE%.ZIP GOTO FILE
C:\UTIL\PKZIP\PKZIP C:\BACKUP\%CUR-DATE%.ZIP C:\DATA\*.*
GOTO END
:FILE
ECHO.
ECHO %CUR-DATE%.ZIP File Already Exists!
ECHO No Additional Backup Performed.
ECHO.
:END
SET CUR-DATE=
SET DAY=
________
A Final Improvement
It would now be nice if old backups could be deleted automatically so they don't accumulate and use space on your hard drive unnecessarily. Let's say that any backup older than about three months is not necessary to keep. This would mean that there would be approximately a dozen backups in the archive at any one time from after about the first three months that this setup is first implemented.
:: BU.bat (Improvement 3)
:: Archives All Files from the C:\DATA directory into a .ZIP file
:: The .zip File is Placed into the C:\BACKUP directory.
:: This is Done Every Monday Morning Upon Bootup
:: Deletes Backup Files Older than 90 Days.
::
@ECHO OFF
C:\DOS\XSET DAY DAYOFWEEK
IF NOT "%DAY%" == "1" GOTO END
:BACKUP
C:\DOS\XSET CUR-DATE DATE YY-MM-DD
IF EXIST C:\BACKUP\%CUR-DATE%.ZIP GOTO FILE
C:\UTIL\PKZIP\PKZIP C:\BACKUP\%CUR-DATE%.ZIP C:\DATA\*.*
XXCOPY C:\BACKUP\*.ZIP /DB#90 /RSY /PD0 /ED
GOTO END
:FILE
ECHO.
ECHO %CUR-DATE%.ZIP File Already Exists!
ECHO No Additional Backup Performed.
ECHO.
:END
SET DAY=
SET CUR-DATE=
________
Explanation
This file is the same as the previous except for the "XXCOPY" command. This is an update of the DOS "XCOPY" command. With the switches shown, it selects files with a date on, or before, 90 days from the present (/DB#90), allows for those files to be removed from the source directory (C:\BACKUP) with the prompt answered "YES" (/RSY), hides any additional prompt display (/PD0), and preserves the directory should it be, or become, empty (/ED). (Switches make for powerful program and DOS usage. See here for a DOS Switches Discussion.)
XSET may be obtained from -xset.tripod.com.XXCOPY may be obtained from -XXCOPY.com.
The CLEARING HOUSE
This batch file is one of several similar ones I use to do routine file work. I employ my DOWNLOAD, UPLOAD or TEMP directory for this purpose. Batch files have been written that will allow the moving or copying of all, or specified, files in a directory to, or from, any of those three directories. Thus those directories become clearing houses for these files because they are just passing through from a source directory to a target directory.
This is handy when you want to move files from one directory to another and don't want the tedium of file managers like Windoze Extorturer, (Windows Explorer), nor wish to have to type all the path and directory names for the source and target. Six files are required should you wish to use all three directories, as do I. I will show only one of them, but you may modify this file to complete the sextet.
I use three directories because I sometimes have other files sitting in one or more due to on-going work, so having three means more of a chance one or more will be empty. In actuality, this is not even a problem, because i have written very specific versions of these batch files for my own use. These leave alone the files already in the directory I choose to use as the Clearing House while the other work goes on around them.
I won't get into these right now. Perhaps I'll add one of them at a later date so you may see how those work. I also use hard drive directories rather than RAM drive ones so that I can leave these files there and come back to them several days later, if needed. If they were on a RAM drive, I might forget about them, reboot, and lose them.
Here is one of my basic "Clearing House" batch files:
CTTP.batSyntax: CTTP, or CTTP (file name or names)
:: CTTP.bat
:: Copies All or Specified Files to the C:\TEMP Directory
:: Wildcard Selections are Allowed
:: Prompts to Overwrite when Necessary
::
@ECHO OFF
IF "%1" == "" GOTO COPY-ALL If there is no file specified,
IF NOT "%1" == "" GOTO COPY-SPEC All files will be copied.
Otherwise, the Specified Files
will be copied.
:COPY-ALL
ECHO. Inserts a Blank Line on Screen
XCOPY *.* C:\TEMP /-Y Copies All Files, with Prompting
GOTO END for Overwrite
:COPY-SPEC
XCOPY %1 C:\TEMP:\ /-Y > NUL See Text, Below
SHIFT
IF "%1" == "" GOTO END
GOTO COPY-SPEC
END:
ECHO.
DR C:\TEMP Display the TEMP Directory
________
For the "COPY-ALL" section, the chosen file(s) are copied to the C:\TEMP directory with all prompts in place so you may monitor the operation. Blank lines are inserted on screen to keep this information separated.
In the "COPY-SPEC" section, the first file given on the command line will be copied. The SHIFT command then moves the file names you gave down by one position. That is, file 2 becomes `1', `3' becomes `2', and so on. If there is no file left to move into Position `1', the batch file is directed to the end. Otherwise, it is told to go back to COPY-SPEC where the next file is copied. Then SHIFT is executed again. As long as files are being moved into Position `1', the batch file will continue to copy. When none are left, the file will be directed to the end where a directory listing confirms the operation.
Now write a second file by copying this. Rearrange the copy commands to copy *from* the TEMP directory to the current one. Use `.' to represent the current directory. Call the new file "CFTP" for "Copy From Temp".
Usage
In use, go to the source directory and issue the CTTP command. Then go to the target directory and issue CFTP. All the files will have been transferred. To make this less painless, make shortcuts to the source & target directories. If you are sure you don't need the TEMP directory copies, delete them. If you don't need *any* copies except for those in the final target directory, substitute "MOVE" for "XCOPY" in the previous two batch files. You will also have to move "/-Y" so as to place this just after each "MOVE" command. For some reason Microsoft changed the syntax to not allow switches for the "MOVE" command to be at the end of the line. Instead, they must directly follow the command. Don't forget to have a space between the command and any switches. (DR-DOS (dee-are dos) users need to eliminate any `/-Y' because DR-DOS does not use this switch.)
Now rewrite all those files but substitute "Download" and "Upload" for "Temp". You now have three clearing house directories. If you do both to and from, use both copy and move, and use all three directories, a total of twelve batch files will result.
Usage Enhancements
I have this set up in combination with many direct-access batch files for my most used directories. Thus, with one command I access the directory of choice, then issue another command to move or copy the files to one of the "clearing house" directories. A third command takes me to the target directory and the final command moves or copies the files from the clearing directory to the target directory. To speed "Move" operations, use a RAM drive TEMP directory. Since they are being moved, you don't need to worry about saving any additional copies, so RAM drive reboot losses are not a factor unless power was to be lost during the operation.
To speed operations further, I have a many of these batch files keyed to shortcut keys, so it's often only a matter of pressing four keys/key combinations to get some mighty fast and painless files chores done. It can often be finished before something like Windoze Extorturer can even be opened!
UPDATE: Since I first wrote the clearing house batch files, I composed a batch file that allows direct copy or move operations and skips the "middle man" step. It requires a change-directory program or batch-file shortcuts to the target directory in order to work. I use -Directory Maven for most of this purpose. TRAN.bat (Transfer bat) is too advanced for this section but may seen on the Advanced Batch Files III page.
USING DATES IN FILE and DIRECTORY NAMES
DATEFILE.bat
:: DATEFILE.bat
:: Makes a Text File with the Current Date as the Name
::
C:\BATCH\DOS\XSET CUR-DATE DATE YY-MM-DD See Text for
REM > %CUR-DATE%.TXT XSET Information
This will make a zero-byte file which name will be in the format of "Year-Month-Day". That keeps similar files in chronological order. You may then load it into an editor and add text. Here's a version that does both:
DATEFILE.bat (Improved)
:: DATEFILE.bat (Improved)
:: Makes a Text File with the Current Date as the Name
:: Loads it into DOS EDIT
::
C:\BATCH\DOS\XSET CUR-DATE DATE YY-MM-DD
C:\BATCH\DOS\EDIT %CUR-DATE%.TXT
This assumes you are using DOS EDIT and it is in the "DOS" directory. XSET is an update to the DOS "SET" command. It is assumed here that it too, is in the "DOS" directory. Get that program at the XSET website.
Those of you with the %DATE% variable built into your version of DOS may eliminate the XSET lines that are used to get the date into the environment and rework the remainder of file to take this into account.
Here's a way to rename an existing file with the current date.
DATEFILE.bat (Alternate)
:: DATEFILE.bat (Alternate)
:: Renames a Text File with the Current Date as the Name
:: The File Extension is Kept
::
:: Syntax: DATEFILE (file name and extension)
::
C:\BATCH\DOS\XSET CUR-DATE DATE YY-MM-DD
REN %1.* %CUR-DATE%.*
Want to make a directory with the current date as its name?
DATE-DIR.bat
:: DATE-DIR.bat
:: Makes a Directory with the Current Date as the Name
::
C:\BATCH\DOS\XSET CUR-DATE DATE YY-MM-DD
MD %CUR-DATE%
________
This renames a directory with the current date as its name
DATE-DIR.bat (Alternate)
:: DATE-DIR.bat (Alternate)
:: Makes a Directory with the Current Date as the Name
:: May not be Used with Directories having an Extension in the Name
::
:: Syntax: DATE-DIR (file name and extension)
::
::
C:\BATCH\DOS\XSET CUR-DATE DATE YY-MM-DD
MOVE %1 %CUR-DATE%
A SPACE-SAVER SYSTEM
Here's the scenario: Your hard drive is running low on room and you can't afford, or don't want to bother getting, a new one. You'd like to keep some files in a compressed archive but hate the idea of having to uncompress a given file to edit it, and then having to restore an updated version back into the compressed archive.
This batch file will allow you to retrieve a document from a .zip file, edit it, and then return the modified version to the .zip file. The example will be geared for plain text files, but you may substitute a word processor so that this batch file could retrieve, say a WordPerfect file, load it into that program, and then return it to the .zip file upon exit. You may also use the second version of this batch file as a simple viewer for files in that .zip archive.
For this example, it will be assumed that your compression program is PKZIP and it is in a subdirectory of C:\UTIL, and that you are using DOS EDIT. Any text editor will work provided you can specify a file to load right from the command line. Be aware, any file you load with this setup must be in the .zip file & directory shown, although you could modify this example to take into account different .zip files residing in different directories. Alternatively, you could write a series of these batch files, each for a specific .zip file.
It will be also be assumed that your documents are archived in DOCS.zip and that is in the C:\DOCUMENT directory.
EDZIP.bat
:: EDZIP.bat
:: Allows a File to be Retrieved from a .zip Archive for Editing.
::
@ECHO OFF
IF "%1" == "" GOTO NOFILE
IF NOT EXIST C:\DOCUMENT\ED-TEMP\NUL MD C:\DOCUMENT\ED-TEMP
C:
CD\DOCUMENTS\ED-TEMP
C:\UTIL\PKZIP\PKUNZIP C:\DOCUMENT\DOCS.ZIP %1
C:\DOS\EDIT %1
C:\UTIL\PKZIP\PKZIP -m- C:\DOCUMENT\DOCS.ZIP %1
GOTO END
:NOFILE
ECHO.
ECHO No File Given for Editing
ECHO.
:END
________
Explanation
First, the batch file checks to make sure you typed a file name at the command line. Then it checks to see if there is an ED-TEMP directory and creates one if there is not. Next, it moves you to this directory for the editing job. This directory is necessary because if the same file name as you are about to expand existed in the DOCUMENT directory, PKUNZIP would want to overwrite it. It does ask before doing so, but this is an unnecessary step. Editing within an empty directory prevents this step.
Next, the file is expanded (retrieved from the archive) and loaded into EDIT. After exiting EDIT, control returns to this batch file and the file is reinserted into DOCS.zip where it overwrites the previous version. Note the " -m- " switch. This moves the expanded file into the zip archive, effectively removing it from the directory. This is to prevent expanded files from cluttering the directory and taking up space should you forget to delete it after editing. Here, this deletion is taken care of for you. Be sure that switch is in lower case. The trailing minus sign is there to prevent PKZIP from deleting the directory should it be empty after the file is moved. (In actuality, the directory should be empty because it is only supposed to be used as a temporary editing location.)
To speed this process, set PKZIP's workspace to be on a RAM drive by adding a "SET" line before any PK work in the batch file. This might be something like "SET PKTMP=F:\TEMP". (Substitute your RAM drive's letter for the `F' shown here.) As well, if you place EDIT on the RAM drive and point the batch file's EDIT lines there, you'll have the fastest speed of operations possible.
An Improvement
Now what happens if you mistype the file name or you don't remember the name? Here's an improved version that will take that into consideration:
EDZIP.bat (Improved)
:: EDZIP.bat (Improved)
:: Allows a File to be Retrieved from a .zip Archive for Editing.
:: Allows Viewing of the .zip Archive
::
@ECHO OFF
IF "%1" == "" GOTO VIEW
:EDITING
IF NOT EXIST C:\DOCUMENT\ED-TEMP\NUL MD C:\DOCUMENT\ED-TEMP
C:
CD\DOCUMENTS\ED-TEMP
C:\UTIL\PKZIP\PKUNZIP C:\DOCUMENT\DOCS.ZIP %1
IF ERRORLEVEL 11 IF NOT ERRORLEVEL 12 GOTO NOFILE
C:\DOS\EDIT %1
C:\UTIL\PKZIP\PKZIP -m- C:\DOCUMENT\DOCS.ZIP %1
:VIEW
C:\UTIL\PKZIP\PKZIP -vbnm C:\DOCUMENT\DOCS.ZIP
GOTO END
:NOFILE
ECHO.
ECHO File "%1" was not Found in DOCS.zip
ECHO Batch File Terminated
ECHO.
:END
________
Explanation
In this version, if no file name is typed at the command line, DOCS.zip's contents are viewed as a brief listing, sorted by name, and displayed a page at a time via the " -vbnm " switch. (The `m' stands for "more".) If you wish to edit one of the files, you may then run the batch file again and add one of the file names at the command line. If the name you type does not exist, PKUNZIP's errorlevels are used to determine this. Then a message is displayed and the batch file ends. After a successful edit, the contents of DOCS.zip are displayed a page at a time for conformation.
Another Improvement
It would be handy that if when you type a name that does not exist, you had the option to create that file and add it to the .zip archive. This means that you would not have to add it manually and also means that this one batch file can now serve a triple purpose. These purposes are to be able to view the DOCS.zip contents, edit an existing file in that archive, and to be able to place new files into the archive. Here's that version:
EDZIP.bat (Improvement 2)
:: EDZIP.bat (Improvement 2) Requires DOS 6 or Newer.
:: Allows a File to be Retrieved from a .zip Archive for Editing.
:: Allows Creation of a New File and Addition of it to the Archive.
:: Allows Viewing of the .zip Archive
::
@ECHO OFF
IF "%1" == "" GOTO VIEW
:EDITING
IF NOT EXIST C:\DOCUMENT\ED-TEMP\NUL MD C:\DOCUMENT\ED-TEMP
C:
CD\DOCUMENTS\ED-TEMP
C:\UTIL\PKZIP\PKUNZIP C:\DOCUMENT\DOCS.ZIP %1
IF ERRORLEVEL 11 IF NOT ERRORLEVEL 12 GOTO NOFILE
C:\DOS\EDIT %1
C:\UTIL\PKZIP\PKZIP -m- C:\DOCUMENT\DOCS.ZIP %1
:VIEW
C:\UTIL\PKZIP\PKUNZIP -vbnm C:\DOCUMENT\DOCS.ZIP
GOTO END
:NOFILE
ECHO.
ECHO File "%1" was not Found in DOCS.zip
ECHO.
ECHO Do you Wish to Create this File?
ECHO If so, Press `C'
ECHO If Not, Press "ESCAPE" to End
CHOICE /C:C<- /N > NUL
IF ERRORLEVEL 2 GOTO END
IF ERRORLEVEL 1 GOTO CREATE
GOTO END
:CREATE
C:\DOS\EDIT %1
C:\UTIL\PKZIP\PKZIP -m- C:\DOCUMENT\DOCS.ZIP %1
C:\UTIL\PKZIP\PKUNZIP -vbnm C:\DOCUMENT\DOCS.ZIP
:END
________
(Note that `<- ' represents the "Escape" character. To create it, press ^P (Control-P) in DOS Edit, then the "Escape" key. Other text editors allow one to create the "Escape" character by pressing ^V first.)
Explanation
In this final version, PKUNZIP tries to extract from DOCS.zip the file you gave at the command line. If it finds it, the file is extracted, edited, and reinserted into the archive as before. If the file name is not found, the option is given via the DOS "CHOICE" command to create this new file. If that option is selected, the file is created and then added to DOCS.zip. As a bonus, if the DOCS.zip file does not exist, it too will be created. Thus, you may start using this batch file as soon as you create the C:\DOCUMENT directory because it will do the rest. As before, the contents of DOCS.zip is shown a page at a time for conformation.
DELETED FILE SECURITY
This batch file allows a deleted file's contents to be made unrecoverable by DOS UNDELETE and by many commercial undelete programs. It is not perfect because there are other ways to recover the file. However, the casual snoop will not be able to view or recover the deleted file's contents.
EXPUNGE.bat
:: EXPUNGE.bat
:: Expunges Files
:: UNDELETE Cannot Recover Them
::
@ECHO OFF
IF "%1" == "*TASKS*" GOTO TASKS
ECHO.
ECHO These files will be Expunged:
ECHO.
ECHO %1 %2 %3 %4 %5 %6 %7 %8 %9
ECHO.
ECHO Continue? Y? N?
ECHO.
CHOICE > NUL
IF ERRORLEVEL 2 GOTO END
IF ERRORLEVEL 1 GOTO DEL-ALL
GOTO END
:DEL-ALL
FOR %%F IN (%1) DO CALL C:\BATCH\EXPUNGE.BAT *TASKS* %%F
SHIFT
IF "%1" == "" GOTO END
GOTO DEL-ALL
:TASKS
REM > %2
DEL %2 > NUL
ECHO.
ECHO %2 Expunged!
ECHO.
:END
Explanation
Ignore the opening "IF" statement for a moment. Next are displayed up to nine of the files you have selected for expunging. You may type more names, but only the first nine appear on the screen. It then asks if you want to continue. This is done via the DOS "CHOICE" command. Pressing `n', ends the batch file. Pressing `y' continues on to the "DEL-ALL" section. The CHOICE command's output is directed to NUL to prevent its prompts from showing on the screen.
In "DEL-ALL", the DOS "FOR-IN-DO" (FOR) command is used. It essentially says: "FOR each Item listed INside the Brackets, DO call the EXPUNGE batch file". However, it is given a first parameter of "*TASKS*", while the second parameter will now be the first file to be expunged. "%%F" represents that first file name you typed because it will in turn represent each file name designated by "%1".
This time, when EXPUNGE.bat is run, the first "IF" statement is true and control passes to the "TASKS" section. There, the DOS "REM" (Remark) command is used to create a new file with no information in it, but using the same name as the one you typed at the command line. This overwrites your file's name with this new one, which incidently contains no information. That is, it is zero bytes in size. Then, this new file is deleted.
Having completed the procedure, control returns to the "FOR" statement. Since there was only one parameter (%1) in there, "FOR" is finished and the SHIFT line is executed. SHIFT is used to move the file names you typed at the command line to one lower position with regards to the percent-number replaceable parameters. Thus, the second file name you typed is moved to position number one (%1). Since %1 is equal to something, this makes the next "IF" statement false, so the batch file does not go to the end. Instead, the succeeding line is read and that sends the batch file back to the "DEL-ALL" section where it reads the "FOR" line once again.
Here, because of SHIFT, there is a new number one (%1) file. It is actually the second file name you typed, but SHIFT has moved it into position number one (%1). So the process is repeated with this second file name (now in position one) passed to the TASKS section where it is expunged. This procedure continues until all files have been removed.
Usage
Simply type "EXPUNGE filename.ext filename.ext...". The file names will be shown on the screen and you will be given a chance to abort the operation by pressing `n'. If you have the file names correct, press `y' and they will be expunged one at a time, with confirmation messages placed on the screen to reflect this.
If the file is subsequently undeleted and then viewed, it will show blank. You may run this command as many times as you like. The blank files will be replaced with blank files again. I have not tested to see if multiple runnings gain any additional security or not. I doubt it does if a capable file recovery program is used. Some of the deleted file's data is likely to remain untouched and thus may be viewed. If you require a higher level of security, use a commercial file "WIPE" utility.
A PATH MASTER
Have you ever wanted to temporarily add to your path, but couldn't be bothered to rewrite your AUTOEXEC.bat and then run it or reboot? Here's a way to quickly add one or more directories to your path statement right from the command line. Afterwards, another batch file will be presented that allows the default path to be restored.
PA.bat
:: PA.bat
:: Adds an Additional Directory to Current Path
:: Prevents Duplicate Directories from being Added
::
@ECHO OFF
IF "%1" == "" GOTO NO-DIR
IF NOT EXIST %1\NUL GOTO INVALID
SET FIND "PATH" FIND "%1" /I > NUL
IF ERRORLEVEL 1 GOTO PATH-ADD
IF ERRORLEVEL 0 GOTO DUPLICATE
:PATH-ADD
SET FIND "DEFAULT" > NUL
IF ERRORLEVEL 2 GOTO END
IF ERRORLEVEL 1 GOTO DEFAULT
IF ERRORLEVEL 0 GOTO PATH-2
:PATH-2
PATH=%1;%PATH%
CLS
ECHO.
ECHO New Path=
ECHO.
ECHO %PATH%
ECHO.
GOTO PR-PROMPT
:DEFAULT
SET DEFAULT-PATH=%PATH%
PATH=%1;%PATH%
CLS
ECHO.
ECHO.
ECHO New Path=
ECHO.
ECHO %PATH%
ECHO.
:PR-PROMPT
ECHO.
ECHO.
ECHO +++++++++++++++++
ECHO "PR" Restores the
ECHO Default Path
ECHO +++++++++++++++++
ECHO.
GOTO END
:NO-DIR
CLS
ECHO.
ECHO.
ECHO -----------------------
ECHO No Directory Specified.
ECHO Please Try Again!
ECHO -----------------------
ECHO.
GOTO END
:INVALID
CLS
ECHO.
ECHO.
ECHO ------------------------
ECHO Directory Does Not Exist
ECHO Please Try Again!
ECHO ----------------------
ECHO.
GOTO END
:DUPLICATE
SET DIRECTORY=%1
CLS
ECHO.
ECHO.
ECHO Directory %DIRECTORY% Already in Path
ECHO.
ECHO %PATH%
ECHO.
:END
SET DIRECTORY=
Explanation
First, some "IF" statements check to see if a directory was not included at the command line and if one was, if it does not exist. If either of these are true, the batch file branches to appropriate sections that display messages to the user. Messages created by this batch file will be indented from the left margin to aid in readability. In both cases, the "%1" replaceable will be changed to the name you typed at the command line. The "NUL" is a hidden DOS device that occurs in every directory. If it does not exist, then neither does the directory. This method of directory existence checking doesn't work in all versions of DOS. If it's a problem with your version, eliminate it and the section to which it branches. Alternatively, if you wish to use another method of directory existence checking, then substitute it here. As an example, DR-DOS has the "DIREXIST" condition of its "IF" command.
Next, the DOS "SET" command line is used to see if the directory name typed at the command line is already included in the path. It does that by piping the output of SET to the DOS "FIND" command. SET, by itself, displays the current environment variables. FIND is then directed to look for the PATH statement line. That is turn is piped again through a second FIND command that looks for the directory name. The "/I" switch tells FIND to ignore the case of what you typed. This allows you to type a directory name in upper, lower, or mixed case. The "/I" switch is not needed for FIND to locate "PATH" because DOS always displays the PATH variable in upper case. The result of the "FIND" line is tested though DOS Error Levels. The explanation of Error Levels is beyond the scope of this article, but see Exit Codes at this website. Just understand that the results dictate where the batch file goes next.
So, if the directory is found in the path statement, the batch file is directed to branch to a section that displays a message saying the directory is already included. If this, or either of the previous branches occur, the batch file is directed to end.
Now the real work starts. If all is well, the batch file goes to the "PATH-ADD" section. SET and FIND commands are used again to locate an environment variable called, in full, "DEFAULT-PATH". This would have been created if this batch file had previously been run and the path had been altered from the default. (This is explained farther on.)
The DOS "IF ERRORLEVEL" testing method is used again to direct the batch file to the appropriate section based on whether FIND has found the "DEFAULT-PATH" environment variable or not, and whether any detrimental error has occurred. In the latter case, the batch file ends.
If it branches to "DEFAULT-PATH", it's because this is the first time the batch file was run since the last bootup, or since the last PR.bat (Path Restore) was issued. (See farther on for PR.bat.) Here, the "DEFAULT-PATH" environment variable is set. It remembers the path as set in the AUTOEXEC.bat or by the user if it happened to have been set manually at the command line at a previous time.
Next, the actual path is changed to include the directory you gave at the command line. Your new directory will be placed first. This is handy because you are likely only adding this directory so you can do some immediate work and it will be removed soon thereafter. Having it first in the path statement, means that you won't have to wait while DOS searches through all the other directories until it reaches this added directory. Thus, its commands will be executed more quickly than if it had been placed last.
The batch file ends by placing two messages on the screen. One tells you the new path, and thus confirms your addition; the other is one that reminds you that the default path can be restored by entering "PR". The "DEFAULT-PATH" environment variable remains in memory to enable this. Should you reboot, or lose power and have to restart, the default path will automatically be reset via the AUTOEXEC.bat's "PATH" statement.
Now, if this batch file has already been run and you want to add another directory to the path, it will branch to "PATH-2". Here the previously-set PATH variable is updated with the addition of a second directory. Your previous addition will still be there because this batch file has already changed the path statement to include the last addition. This second directory addition will simply be placed in front of that. You may continue to add directories via this method up to the 127-character path statement limit, but it's not recommended because of the long searches that might ensue.
The batch file continues as before by displaying the various messages and then ends.
One other thing the file does is to check to see if the directory is already in the path. Placing it there again would lengthen the search time and bring one closer to the 127-character limit. The "DUPLICATE" section prevents that. It would have been branched to earlier on if the test to see if the given directory was already in the existing path statement proved true.
Presented now is the Batch FileTo Restore the Default Prompt.
PR.bat
:: PR.bat
:: Restores the Default Path
::
@ECHO OFF
IF "%DEFAULT-PATH%" == "" GOTO PATH-OK
SET PATH=%DEFAULT-PATH%
CLS
ECHO.
ECHO.
ECHO Default Path Restored!
ECHO.
ECHO %PATH%
ECHO.
GOTO END
:PATH-OK
CLS
ECHO.
ECHO.
ECHO -------------------------
ECHO Default Path Already Set
ECHO ----------------------
ECHO.
ECHO %PATH%
ECHO.
:END
SET DEFAULT-PATH=
Explanation
This starts by checking to see if the "DEFAULT-PATH" environment variable has been set. If it has not, it means PA.bat has not been run, the computer has been rebooted since it was, or PR.bat has already been run. It then branches to "PATH-OK" and displays a message stating the default path has already been set and shows that path. The batch file then ends.
If, however, the "DEFAULT-PATH" environment variable has been set, the batch file moves on to reset the path to its original version. A message says this has been done, the original path is displayed, and the file ends by resetting the environment variable to equal nothing to remove it from memory.
Usage of both Batch Files
All one needs to do is to issue the "PA" batch file name, a space and the new directory that you wish to add to the path statement. So if you needed to add the Utilities directory on drive `D', it would be "PA D:\UTIL". You may add more directories one at a time via this method, or you may add multiple directories with one command: "PA D:\UTIL;E:\TEST", and so on. Just be sure to place a semi-colon between each directory name and to specify full paths with drive letters, colons, and backslashes. Do not place a space between names you are adding and don't type a semicolon after the last name because the batch file does that for you. At any time, to reset to the default path, issue "PR".
You may wish to think about using the "Path Add" and "Path Restore" commands in a batch file that starts another program. That way the program will be in the path while it's running, but be removed immediately afterward.
Note that if you do not include a proper drive syntax, a new (invalid) directory will be added by mistake. Error checking could be included in PA.bat, but it would complicate and lengthen the batch file severely. This is because a lot of mistyped possibilities would have to be covered. Therefore, just be sure that you peruse the new path as displayed after the batch file ends to be sure the addition has a valid drive letter, colon, and backslash. If it's wrong, issue "PR" and then retype the "PA" batch file name with the corrected directory name you wish to add.
ADDING a NOTE to YOUR PROMPT
Having a command line method of typing notes is shown with NOTE.bat in Advanced Batch Files III. However, at times, it might be nice to have an on-screen reminder. This batch file allows a short note to be placed in the prompt so that every time the prompt is displayed, the note will be visible.
REMIND.bat
:: REMIND.bat
:: Places Short Notes into the Command Prompt
::
@ECHO OFF
IF NOT "%USER-TEXT%" == "" GOTO UPDATE
SET DEFAULT PROMPT=%PROMPT%
ECHO @SET PROMPT=%%DEFAULT PROMPT%% > C:\BATCH\RESET.BAT
GOTO REMIND-TEXT
:UPDATE
SET PROMPT=%DEFAULT PROMPT%
:REMIND-TEXT
ECHO.
C:\DOS\XSET /PROMPT " Enter Text to be Reminded: " USER-TEXT
ECHO.
PROMPT=$_ %USER-TEXT% $_%PROMPT%
:END
________
Explanation
The file begins by checking to see if the "USER-TEXT" variable has been set. If this is the first time the file has been run since the last boot-up, it will not have been set. So the batch file goes to the next line which preserves the current default prompt as "DEFAULT PROMPT".
Next, the file creates another batch file that will be used to reset the prompt and erase the note. The single line is simply redirected to "RESET.bat". Its only purpose is to restore your regular (default) prompt, thus erasing any note you created previously. If there is no note, then running it only "restores" what is already on the screen and no change will result.
Note the double percent signs in that line. They are required for all redirected percent signs. Single ones will be erased during a redirection. So in order to have them survive the redirection, an additional one is required for each original percent sign.
Now the "REMIND-TEXT" section is executed. Blank lines are added before and after the on-screen request for text. That request is placed there by XSET, an update to the DOS "SET" command. Note the quotation marks and spaces. The quote marks are necessary for XSET to do this task. However, I placed the spaces. This is so the request for the reminder text stands out on the command line.
XSET then takes the user's input and places it into an environment variable called "USER-TEXT". This, in turn, is used as part of a new prompt. The new prompt first drops down a line via the `$_'. It then places your note on the screen preceded by leading spaces. Finally, it places your regular (default) prompt on the line underneath, again via using `$_'. Thus, your note will have a blank row above and leading spaces on its line. These are to move the note away from text above and the left margin to make it stand out when the screen is full of text.
Should the batch file be run again, the initial "IF" statement will direct the batch file to the "UPDATE" section. There, the prompt is reset to the default, erasing the previous note. The batch file then runs as before, except placing a new note into the prompt.
Usage
Simply type "REMIND" at any DOS prompt. Then add your text. Press "ENTER" and a new prompt appears with your text above it. To change the note, repeat this, but input different text. To erase the note and restore the prompt, enter "RESET".
Restrictions
This is a simple batch file, and as such, there are restrictions. First, you may only type a single line. It may be edited with the Cursor Keys, and HOME, END, etc. keys, but as soon as you hit "ENTER", it will be set and the new prompt will appear.
Since it is using the DOS "PROMPT" command, the total line length must not exceed the maximum allowed prompt length. That includes the default prompt which appears along with the note. This is a minimum of 127 characters, total, but some versions of DOS will allow longer prompts. If you exceed whatever length is allowed, the prompt will not display properly. However, "RESET" will always restore it to the default.
Another restriction is that rebooting will erase the note, as will any programs or batch file that resets the prompt. So be careful if you have an important note.
XSET may be obtained from -xset.tripod.com.
A TASK TIMER
So you have to work on a project and are being paid, or have to bill, by the hour. You need to know the time spent in the computer program used in the project so you have been writing down your start & stop times. Unfortunately, you've been distracted before or during a few of the sessions and have lost track of some of the times. Here's a simple way to have the start & stop time logged each time you enter & leave the program:
It will be assumed that you are using NEOPAINT for a graphics project and that it is in a subdirectory of C:\GRAPHICS.
TIMER.bat
:: TIMER.bat
:: Logs Start and Stop Times of NEOPAINT
::
@ECHO OFF
C:
CD\GRAPHICS\NEOPAINT
IF EXIST NP-LOG.TXT GOTO LOG
:CREATE
ECHO NEOPAINT LOG > NP-LOG.TXT
ECHO. >> NP-LOG.TXT
:LOG
ECHO Neopaint was started: >> NP-LOG.TXT
ECHO. DATE FIND "Current" >> NP-LOG.TXT
ECHO. TIME FIND "Current" >> NP-LOG.TXT
NEOPAINT
ECHO. >> NP-LOG.TXT
ECHO Neopaint was stopped: >> NP-LOG.TXT
ECHO. DATE FIND "Current" >> NP-LOG.TXT
ECHO. TIME FIND "Current" >> NP-LOG.TXT
ECHO - - - - - - - - >> NP-LOG.TXT
ECHO. >> NP-LOG.TXT
MORE < NP-LOG.TXT
Explanation
This file starts by switching to the NEOPAINT directory and then by creating the log text file should one not exist. This step places a title a bit in from the left margin to center it more over the date & time lines. After that, it makes use of the DOS "DATE" and "TIME" commands. As explained with CTULD.bat in Advanced Batch Files, a RETURN keystroke can be sent to the DATE (or TIME) command and then piped to the FIND command. This presses ENTER for you and locates the line with the current DATE (or TIME).
(Users of this batch file should be aware thatit was based on MS-DOS. Those using other DOSmanufacturers or using DOS under Windows willhave to alter the batch file to match whattheir DATE commands output.)
For this batch file, the output is passed to a log file to document when NEOPAINT was started, and again after exiting the program, to document when it was stopped. Of course, NEOPAINT is also started by this batch file. We continue by having the batch file place a dashed and a blank line at the end of each session as a separator for the next session's log dates & times.
Finally, the log file is displayed on screen to confirm the log operation. The DOS "MORE" command displays the information a screen at a time. If the file grows to be large and you wish to see only the last page of entries, then substitute this line:
TYPE NP-LOG.TXT
An Improvement
This will work just fine, but the date & time lines will also contain the phrase "The Current Date (Time) is". We could get rid of this and single out the dates and times, as was done in CTULD.bat, but that is a longer process and requires a number of additional files be created. However, using XSET, as seen farther back on this page in BU.bat, will reduce the process to just a few lines. The same technique is used in the improved NOTE.bat as seen in Advanced Batch Files III page.
TIMER.bat
:: TIMER.bat (Improved)
:: Logs Start and Stop Times of NEOPAINT
::
@ECHO OFF
C:
CD\GRAPHICS\NEOPAINT
IF EXIST NP-LOG.TXT GOTO LOG
:CREATE
ECHO NEOPAINT LOG > NP-LOG.TXT
ECHO. >> NP-LOG.TXT
:LOG
C:\DOS\XSET CUR-DATE DATE
C:\DOS\XSET CUR-TIME TIME
ECHO Neopaint was started: >> NP-LOG.TXT
ECHO Date: %CUR-DATE% >> NP-LOG.TXT
ECHO Time: %CUR-TIME% >> NP-LOG.TXT
NEOPAINT
ECHO. >> NP-LOG.TXT
C:\DOS\XSET CUR-DATE DATE
C:\DOS\XSET CUR-TIME TIME
ECHO Neopaint was Stopped: >> NP-LOG.TXT
ECHO Date: %CUR-DATE% >> NP-LOG.TXT
ECHO Time: %CUR-TIME% >> NP-LOG.TXT
ECHO - - - - - - - - >> NP-LOG.TXT
ECHO. >> NP-LOG.TXT
MORE < NP-LOG.TXT
Explanation
This version uses XSET to place into the DOS environment the dates and times the program was started and stopped. Using this method gives a cleaner looking log. Typically, it will display as:
NEOPAINT LOG
Neopaint was started:
Date: 10-11-03
Time: 10:33:53
Neopaint was Stopped:
Date: 10-11-03
Time: 10:33:57
_ _ _ _ _ _ _ _
The rest of the file runs as in the first version. Realise this method of logging program times does not take into account if you leave the program running and then take a games break, nor if you run the program during your project for another purpose. While DOS batch files can't monitor when you are goofing off, they can be used to log just your project. Simply name the batch file something like NP-WORK.bat and only use that batch file to start NEOPAINT when you are working on your project. For other times, start NEOPAINT as you ordinarily would.XSET may be obtained from -xset.tripod.com.
A BACKUP-to-FLOPPY ROUTINE
I often do web page work at my place of business and wish to take the files home, partly as a backup, but also so that I will have my web pages available on my home computer. The files are small enough to easily fit on a floppy, but I prefer to compress them anyway. This is because a compressed file transfers faster to a floppy disc. However, the main reason is that I have a number of batch files that unzip specific .zip files, sort them, and send them to the appropriate directories on my home computer. The .zip file is then deleted. This second operation is all done in one step. I may present that batch file here in the future, but it is quite complicated.
Here is one of the batch files I use on files sent to my work computer's UPLOAD directory. It compresses them and sends the .zip file to my `B' floppy drive. The version presented here will allow creation of the `B' drive .zip file from all or selected files in any directory. Note that you can substitute a USB flash-drive letter and remove the `&' to zip to that drive.
It will be assumed that you are using PKZIP which is located in a "PKZIP" directory under a "UTIL" directory on the `C' drive.
ZTB.batSyntax: ZTB (..zip file name) (optional file names to be compressed)
:: ZTB.bat
:: Makes a Specified .zip File on the B Drive From
:: All or Up to 5 Specified Files
:: Keeps Directory Information
:: Spans Discs as Necessary
::
@ECHO OFF
IF "%1" == "" GOTO NO-FILE
IF "%2" == "" GOTO ZIP-ALL
IF NOT "%2" == "" GOTO ZIP-SPEC
:ZIP-SPEC
SET PKTMP=C:\TEMP
C:\UTIL\PKZIP\PKZIP -& -rp b:\%1 %2 %3 %4 %5 %6
GOTO END
:ZIP-ALL
SET PKTMP=C:\TEMP
C:\UTIL\PKZIP\PKZIP -& -rp b:\%1 *.*
GOTO END
:NO-FILE
ECHO.
ECHO No ZIP File Name Specified!
:END
ECHO.
CALL C:\BATCH\DR B:
SET PKTMP=
________
Explanation
This starts out with three "IF" lines. The first determines if you have specified a .zip file name. If not, a prompt appears stating the same. The next two determine if you have placed one or more files names after the .zip name. If you have not, the batch file jumps to the "ZIP-ALL" label and all files in the directory and below will be compressed.
If file names are given, the file goes to the "ZIP-SPEC" label which is for specific file names. This line is actually not needed because the file will automatically go to "ZIP-SPEC" if the first two "IF" statements are false. It's included here for clarity.
Each of the PKZIP sections first sets a TEMP directory in which PKZIP is to work. If you have a RAM drive, point this line to it for faster execution of the ZIP process. Next, the actual compression is done. Both sections are set to span discs via the "-&" switch, should the .zip file be too large for one floppy. As well, subdirectory path information and any files contained therein will be kept during compression via the "-rp" switch. That stands for "recurse" and "path". When the file is later uncompressed, the directory & file structure will be recreated in the directory in which the unzipping occurs.
If you don't want this, you may remove the "-rp" switch. This will only compress the files in the current directory. On the other hand, if you do wish to have the files in the directory and its subdirectories be placed all in one directory, simply use "-r" by itself. When you uncompress a .zip file done in this manner, all files from the originally-selected parent directory and its sub directories will be placed into one directory.
Alternatively, If you want the choice during uncompression, use "-rp" during compression and include "-d" during uncompression to create the subdirectories with their appropriate files, or do not use "-d" to have all the files placed into the same directory.
Be aware, these switches must be lower case. Using upper case letters often means alternative uses. As an example, using "-rP", will recurse the files; plus their *original* directories will be created regardless of in which directory the file is unzipped. That is, that directory structure will be preserved.
Getting back to the explanation of the example batch file, in the "ZIP-SPEC" section, PKZIP can handle up to five names as given on the command line. Add more percent numbers (up tp `%9') if you plan to list more file names in your typical usage.
Finally, the TEMP variable is removed from memory and a directory listing of the `B' drive conforms the operation. As with other examples, you may substitute the DOS "DIR" command for my "DR" batch file.
Usage
Simply change to the desired directory and issue "ZTB (.zip file name)". So if you have .htm files, the command might be "ZTB HTM". You will then see PKZIP do its work and then see a directory listing showing a file called "B:\HTM".
For my actual usage, I have this file modified to deal with .htm files exclusively. I then have a series of batch files based on this that make specific-to-purpose .zip files. As an example, I have one that will compress the .htm files that deal with this DOS website. Thus, a file called "DOS.zip" is created. I also have a more sophisticated version that zips only changed files to my UPLOAD directory. This is in preparation to send any new versions of my webpage files to my server. That batch file version will also zip them to my `B' drive floppy to take home with me as an off-site backup.
A SELF-EXTRACTING COMPRESSION ROUTINE
You want to give some files to a friend, so to save time & space, you give her a .zip file. Or, you want to take some files to your friend's house and put them on her computer. For the reasons above, you take a .zip file. However, in order to uncompress the files, she will have to have PKZIP or an equivalent on her computer, plus know where it is and how to use it. It is much better to have a file that can unzip itself.
Here is a batch file to do that for you. This assumes that you have PKZIP which is located in a "PKZIP" directory under a "UTIL" directory, and that both directories are located on the `C' drive.
ZTE.batSyntax: ZTE (optional .zip file name)
:: ZTE.bat
:: Makes an Executable from All or Specified .zip Files
:: in the Current Directory
::
@ECHO OFF
IF "%1" == "" GOTO EXE-ALL
IF NOT "%1" == "" GOTO EXE-SPEC
:EXE-ALL
SET PKTMP=C:\TEMP
FOR %%Z IN (*.ZIP) DO C:\UTIL\PKZIP\ZIP2EXE %%Z
GOTO END
:EXE-SPEC
SET PKTMP=C:\TEMP
C:\UTIL\PKZIP\ZIP2EXE .\%1.ZIP
:END
ECHO.
CALL C:\BATCH\DR.BAT
SET PKTMP=
________
Explanation
This starts out with two "IF" lines. If no zip file is specified on the command line by you, then .exe files will be made from all.zip files in the current directory - one for each .zip file. If a .zip file name is specified, then only it will have an .exe file produced. This is done by having DOS check to see if a parameter was typed or not and then having the batch file go to the appropriate PKZIP section.
In both sections, a TEMP directory is set in which PK may do its work. If you have a RAM drive set up, be sure to point PK to that TEMP directory. The operation operates much faster on a RAM drive. Both sections also use PKWARE's "ZIP2EXE" feature. In the "EXE-ALL" section, a DOS FOR-IN-DO (FOR) command is used. It means that "FOR each .zip File listed INside the Brackets, DO the following command". Since a wild-card name was used (*.zip), the action is taken on each .zip file in the current directory. DOS directs PKZIP to make an .exe file with the same name as each .zip file it finds.
If a file name is given, the batch file goes to the "EXE-SPEC" label. DOS then directs PKZIP to make an .exe file from the zip file name you typed at the command line.
The file finishes by removing PK's TEMP directory specification from memory and then giving a directory listing to show the success of the operation.
Usage
After making a zip file in any directory, go to that directory and simply type "ZTE" and an .exe file will appear. If there is more than one .zip file and you only want one of them to have an .exe version, type "ZTE (file name)". Do not type the ".zip" extension; the batch file does it for you.