Windows IT Pro is the authoritative and independent resource for windows nt, windows 2000, windows 2003, windows xp. Features a collection of resources and magazines for windows IT professionals.
  
  
  Advanced Search 


November 13, 2006

A Scripting Solution for Cataloging Your File System

NTCatalog. js catalogs an NTBackup Bks for easy recovery
RSS
View this exclusive article with VIP access -- click here to join |
See More Backup and Recovery Articles Here | Reprints | Or sign up for our VIP Monthly Pass!

Download the Code Here

If you create your own .bks file, remember to append a trailing backslash when you specify a folder. If you don't, NTCatalog.js will think that the line refers to a file. For example, if you intend to back up the folder C:\ Program Files, make sure that you type

C:\Program Files  in the .bks file. 

Introducing NTCatalog.js
NTCatalog.js opens a .bks file and creates a CSV file that contains the names of all files selected for backup. The script requires the FileDB.wsc component, so before you can use NTCatalog.js, you need to obtain FileDB.wsc and register it on your computer. You can download FileDB.wsc from the Windows Scripting Solutions Web site at http://www.windowsitpro.com/windowsscripting, InstantDoc ID 93451.

NTCatalog.js requires the CScript host, so you need to start the command line with the CScript keyword if CScript isn't the default host. To configure CScript as your default host, type the following command at a command prompt:

cscript //h:cscript //nologo //s 

The syntax for NTCatalog.js is

[cscript] NTCatalog.j
  s bksfile csvfile [/n] 

where bksfile is the name of the .bks file and csvfile is the name of the CSV file that the script should create. If either filename contains spaces, put the filename in quotes.

By default, the CSV file will be overwritten if it already exists. If you don't want to overwrite an existing file and prefer to generate an error message instead, add the /n option to the command line.

Inside NTCatalog.js
Listing 1, shows an excerpt from NTCatalog.js. The script begins by defining some global variables, then executes the main function, which provides most of the script's functionality. The return value of the main function is the script's exit code.

The main function declares some local variables, then determines whether it was executed with at least two command-line arguments. If there are fewer than two arguments, or if the /? argument is present, the main function executes the usage function, which displays a short usage message and ends the script. Otherwise, the main function uses the scriptHost function to determine the name of the script host executing the script. If the script host isn't cscript.exe, the main function echoes an error message to the screen and ends with a non-zero exit code.

When the script host checks out, the main function creates an instance of the FileSystemObject object and uses it to verify the existence of the .bks file. If the .bks file doesn't exist, or if the /n option was specified on the command line and the output file already exists, the script ends with a non-zero exit code.

Next, the code at callout A creates an instance of the FileDB object. The code then opens the .bks file, as callout B shows. Note that the Open-TextFile method's fourth parameter is true, indicating that the .bks file is a Unicode text file.

At this point, the .bks file has been opened as a TextStream object, and the main function can loop through the file, which it does by using the While statement. As long as the AtEndOfStream property is false (indicating the end of file has not been reached), the loop will continue.

Inside the While loop, the main function reads a line of text and uses the search method at callout C to determine whether the line ends with the string " /exclude" (including the leading space, but not including the quotes). The search method's parameter is a regular expression that specifies the pattern to search for. The search method returns a number indicating the pattern's starting position inside the string. If the pattern isn't found, the search method returns the value -1 in the pos variable. (The trailing "i" after the closing "/" in the regular expression specifies a case-insensitive match.)

   Previous  1  [2]  3  Next 


Top Viewed ArticlesView all articles
CES 2009: Ballmer Announces Windows 7, Windows Live, Live Search Milestones

During his first-ever Consumer Electronics Show (CES) 2009 keynote address last night in Las Vegas, Microsoft CEO Steve Ballmer announced the pending public availability of a feature-complete Windows 7, the final version of Windows Live Essentials, and ...

Command Prompt Tricks

One reader shares his tip for setting up the command prompt to reflect a remote path. ...

Where is Microsoft NetMeeting in Windows XP?

...


Related Articles Using Bzip2 Compression with Cmd.exe and PowerShell

Windows OSs Whitepapers Why SaaS is the Right Solution for Log Management

Related Events Virtualization Forum: Optimizing Storage, Networks, Desktops, and Security

Cloud Computing Forum: Integrating Software, Server and Storage as a Service into Your Enterprise IT Delivery Model

Virtualization Forum: Optimizing Storage, Networks, Desktops, and Security

Check out our list of Free Email Newsletters!

Scripting eBooks Keeping Your Business Safe from Attack: Encryption and Certificate Services

Best Practices for Managing Linux and UNIX Servers

Building an Effective Reporting System

Related Scripting Resources Become a VIP member of the Windows IT Pro community!
Get it all with the VIP CD and VIP access. A $500+ value for only $279!

Subscribe to Windows IT Pro!
Solve your toughest technical problems with our experts and access 10,000 + articles online. 30% off

Monthly Online Pass - Only $5.95!
Get instant access to 10,000+ articles from Windows IT Pro Magazine!

TechNet Virtual Labs
Evaluate and test Microsoft's newest products.


Windows IT Pro Home Register FAQ for Windows WinInfo News
Europe Edition About Us Contact Us/Customer Service Media Kit Affiliates / Licensing  
SQL Server Magazine Office & SharePoint Pro Windows Dev Pro IT Job Hound ITTV
IT Library Technology Resource Directory Connected Home Windows Excavator Windows SuperSite 
 
 Windows IT Pro is a Division of Penton Media Inc.
 Copyright © 2009 Penton Media, Inc., All rights reserved. Terms and Use | Privacy Statement | Reprints and Licensing