Database GUITable of ContentsReplaceRegex
File Utilities
[ReplaceRegex]
[RenameRegex]
[CopyRegex]
[DeleteRegex]
[FileSplit]
[LineCount]
[FileLineFilter]
[HtmlFix2Unix]
[Unix2Dos]
[Dos2Unix]
[FiXML]
[Wget4Xsd]

File Utilities

Bestcode is pleased to provide the following file utilities to make bulk processing of files easier through simple, scriptable command line utilities and powerful regular expression functionality when needed.

File Utilities pack contains Replace, ReplaceRegex, RenameRegex, FileSplit, LineCount, HtmlFix2Unix, FileLineFilterRegex, FiXML, Wget4Xsd, Dos2Unix, Unix2Dos, JpegSize utilities.

Making peoples lives easier

Thanks so much for replace! You saved me FOUR HOURS!!!
- A fellow programmer

File Find/Replace Utility

Replace.exe is a Windows command line utility that searches files in directories to find a given text and replace with another. You can read more about file find/replace utility here. This is a simpler version of ReplaceRegex.

File Find/Replace Using Regular Expressions Utility

ReplaceRegex.exe command line program finds a given string (or a regular expression pattern) in a batch of files, replaces them with another string and places the output files in a separate directory if such directory is specified. The file size must be small enough to fit in available memory.

Command line parameters are:

-srcdir   adirectory    directory of the original files. By default, this is the current directory.

-destdir   adirectory    destination directory to save modified files. By default, this is the current directory. The source files will be over written.

-find     atext        this is the simple text to replace.

-regex     atext       this is the regular expression pattern to replace. You can use capturing groups as () and you can refer to these groups using $1, $2 etc syntax in the replacement text. You can also have escaped characters like \t, \r, \n.

-replace   atext       replace the text that was found with this one. Captured regular expression groups can be used as $1, $2 and so on.

-fname     apattern    the file name pattern to search, for example *.*

-casesens presense of this flag means search is case sensitive.

-quotes   atext is used to represent double quotes in the -find, -regex and -replace parameters. This is to help escaping quotes inside your -find, -regex and -replace parameters.

-tab       atext is used to represent tab (\t) character in the -find and -replace parameters. This is to help escaping tab inside your -find and -replace parameters. Use regular expression escapes for -regex.

-cr       atext is used to represent carriage return (\r) character in the -find and -replace parameters. This is to help escaping carriage return inside your -find and -replace parameters.  Use regular expression escapes for -regex.

-lf       atext is used to represent new line character (\n) in the -find and -replace parameters. This is to help escaping new line inside your find parameters. Use regular expression escapes for -regex.

-r         recursively process sub directories.

You can read more about ReplaceRegex and regular expression find replace use cases in files and usage examples here.


 

Rename Files Using Regular Expressions Utility

RenameRegex.exe command line program renames files whose name matches a regular expression places the output files in a separate directory if such directory is specified.

Command line parameters are:

-srcdir   adirectory     directory of the original files. By default, this is the current directory.

-destdir   adirectory    destination directory to save modified files. By default, this is the current directory. The source files will be over written.

-renameto   atext     New file name. Captured regular expression groups can be used as $1, $2 and so on. For example: $1.txt

-renamefrom   apattern       the file name pattern to find to rename. For example: (report)_[0-9]*.txt

-casesens presense of this flag means search is case sensitive.

-quotes   this flag means the following characters are used instead of double quotes in the -find and -replace parameters. This is to help escaping quotes inside your find replace parameters.

-r         recursively process sub directories.

You can read more about RenameRegex and regular expression file rename use cases and usage examples here.


 

Copy Files Using Regular Expressions File Utility

CopyRegex.exe file copy utility scans (recursively if -r) the source folder (-srcdir) for files whose file path (path and file name) matches a regular expression given by -filepath parameter. The matching files are copied to the destination folder (-destdir). If -diff is given, it means difference only. Then files that already exist in destination location are skipped and are not copied.

Command line parameters are:

-srcdir       <adirectory>  Directory of the files to copy. By default, this is the current directory.

-destdir     <adirectory> Target directory to copy the files to.

-filepath     <apattern>  The file name pattern to find to copy. For example: .*/dir/(report)_[0-9]*.txt

-diff         This flag instructs to copy only the files that do not exist in the target directory.

-casesens     This flag indicates search is case sensitive.

-copyemptydirs This flag indicates empty folders that are being processed shoul
d be copied as well.

-r         Recursively process sub directories.

-verbose   Print detailed progress messages.

Example usage: (notice the quotes around regular expression)

CopyRegex.exe -srcdir logs -destdir Z:\backuplogs -filepath ".*" -r -diff -verbose

Delete Files Using Regular Expressions Utility

DeleteRegex.exe file delete utility scans (recursively if -r) a folder (-dir) for files whose file path (path and file name) matches a regular expression given by -filepath parameter. The matching files are deleted.

Command line parameters are:

-dir       <adirectory>  Directory of the files to delete. By default, this is the current directory.

-filepath <apattern> The file name pattern to find to delete. For example: .*/dir/(report)_[0-9]*.txt

-casesens     This flag indicates search is case sensitive.

-delemptydirs This flag indicates empty folders that are being processed should be deleted as well.

-r         Recursively process sub directories.

-verbose   Print detailed progress messages.

Example Usage:

DeleteRegex.exe -filepath ".*?\\logs\\.*" -dir . -delemptydirs -r -verbose
 

Split Files Into Smaller Chunks Command Line Program

FileSplit.exe utility is used to break a very large text file into smaller files so that they can be opened in common text editors (such as notepad) and inspected. Most of the time, such very large files are created to contain database exports, or server activity logs. When it is time to locate a piece of information in such big file, everyday editors fall short. FileSplit comes to rescue by producing usable chunks of small files so that you can continue with your work, open them in editors and forward small files over the network.

Command line parameters are:

-fname     filename    the file name to split. For example: webserver.log (You will get files like webserver_1.log, webserver_2.log, ... )

-numlines   anumber     Number of lines in each split file. Default is 10000 lines per file.

You can read more about FileSplit.exe File Splitter Tool and see examples of it in use.


 

Count Lines in Text Files Utility

LineCount.exe utility counts the number of lines in text files in bulk. This is typically useful for programmers who need an estimated number of lines of code for their projects. It may be useful for other estimation purposes as well. LineCount.exe gives the option of recrusively processing sub directories, and ignoring empty lines.

Command line parameters are:

-srcdir     adirectory     directory of the original files. By default, this is the current directory.

-fname     apattern    the file name pattern to count, for example *.txt, or *.java, *.cpp

-noemptyline do not count lines that are empty or only contain space or tab characters.

-verbose print file name and line count for each file.

-r         recursively process sub directories.

Example:

LineCount.exe -srcdir dirname [-r] [-verbose] [-noemptyline]

 

Text File Processing Using Regular Expressions Program

FileLineFilterRegex command line program eliminates text lines from text files based on regular expression patterns.

This program removes all lines which does not match a regular expression from text files places the output files in a separate directory if such directory is specified. The file size must be small enough to fit in available memory.

This utility is useful in a case where you have a large file and you are only interested in a subset of the lines in it. For example, the webserver logs where you only want to see certain user agent, certain ip, or perhaps certain date, time. Another example where we use this an application log where each thread id appears at the beginning of the line. And, for troubleshooting purposes, we only want to see the lines logged by a certain thread. FileLineFilterRegex conveniently removes all other lines for us so that we can focus on what matters for us.

Command line parameters are:

-srcdir   adirectory     directory of the original files. By default, this is the current directory.

-destdir   adirectory    destination directory to save modified files. By default, this is the current directory. The source files will be over written.

-regex     atext       this is the regular expression pattern to match lines to keep. If a line in the source file does not match this pattern, that line will not be copied to the destination file.

-fname     apattern    the file name pattern to search. Default is *.*

-casesens presense of this flag means search is case sensitive.

-quotes   this flag means the following characters are used instead of double quotes in the -find and -replace parameters. This is to help escaping quotes inside your find replace parameters.

-r         recursively process sub directories.

Fixing Invalid XML Characters - XML File Utility

FiXML - Invalid XML characters fixer is a command line tool that removes or replaces invalid XML characters in an XML document. Invalid range of XML characters are defined by XML spec and documents that contain them cannot be parsed in most cases.

Invalid XML characters should not be confused with special XML characters. Special XML characters are those that require escaping such as <, & etc.

The most common invalid XML characters are those control characters below ascii 32. Except a few such as \r, \n, \t, space etc, most of the control characters cannot appear in an XML document. There are also few unicode character ranges that should not appear in XML documents per XML spec.

FiXML helps you convert your XML to valid form. Original file is not touched. Output will be saved to {filename}.fixed.

Usage:

FiXML.exe [-encoding encname] [-replace text] afilename.xml

 

Convert Html to Unix Friendy Format File Utility

HtmlFix2Unix utility is used to convert case insensitive html links to case sensitive versions by lowercasing, or uppercasing them so that the html files can be used on a Unix like case sensitive system.

We needed this tool to convert our Math Parser API documentation. The html documents were generated on Windows by Visual Studio and they contained html links, images and JavaScript that was not case sensitive. For example, html could point to an image <img src=Abc.jpg> where as on disk, the image name was actually abc.jpg. This kind of increpency made it impossible to place this documenation on our Linux servers. So we developed HtmlFix2Unix to convert relevant portions of our html to lowercase.

You can read more about HtmlFix2Unix here.

XML Schema Download Utility

Wget4Xsd.exe - XML Schema Download tool is an http utility that downloads a tree of XML Schema (XSD) files to a local directory with one command. XML schema files can include, import, redefine other XSD files to define a XML Schema model. In many cases, the users feel the need to download XML Schemas and use them locally. This typically requires the user to download the main file, then open it and find which files the schema includes, imports, redefines. Then create necessary directory structure manually. Then download the included files into those directories, open each one and repeat the above process for each file. This manual process can get error prone very quickly. Maybe 2-3 files are manageable. But when you have 10 - 20 files, or 1000 files, manual approach is not scalable.

We at Bestcode felt the need to create a utility that will automate the above process. Wget4xsd is a time saver which will let you provide the XSD url (-url) to download and a directory (-dir) to save the files into. Wget4xsd downloads the xsd found at the given url, parses it and discovers include, import, and redefine schema locations. Then it creates the local directory structures to save the files as needed and eventually traverses the entire XSD file tree and saves a local copy ready to use. This is very similar to the well know wget command to download http / html / ftp resources. Wget4Xsd understands the XML Schema structure and downloads necessary pieces.

Usage:

Wget4Xsd.exe -url xmlSchemaUrl and -dir dirName

You can read more about Wget4Xsd here.

Dos2Unix File Conversion Utility

Dos2Unix command line program converts carriage return, line feed pairs (\r\n) to line feeds (\n) and places the output files in a separate directory if such directory is specified. The file size must be small enough to fit in available memory.

Command line parameters are:

-srcdir   adirectory     directory of the original files. By default, this is the current directory.

-destdir   adirectory    destination directory to save modified files. By default, this is the current directory. The source files will be over written.

-fname     apattern    the file name pattern to search, for example *.*

-r         recursively process sub directories.

Unix2Dos File Conversion Utility

Unix2Dos command line program converts line feeds (\n) to carriage return, line feed pairs (\r\n) and places the output files in a separate directory if such directory is specified. The file size must be small enough to fit in available memory.

Command line parameters are:

-srcdir   adirectory     directory of the original files. By default, this is the current directory.

-destdir   adirectory    destination directory to save modified files. By default, this is the current directory. The source files will be over written.

-fname     apattern    the file name pattern to search, for example *.*

-r         recursively process sub directories.

Unix2Dos and Dos2Unix file utilities converts line breaks in your text files to the correct format required by your destination operating system for best compatibity between DOS (Windows) and Unix (Linux) operating systems.

Bulk Resize Jpeg Images - Jpeg File Utility

Jpegsize.exe is a command line Windows utility that resizes JPEG images in a given directory. If no parameter is specified, it creates images that are 800 pixels wide, and adjusts height accordingly to keep aspect ratio. This application is useful when you have digital photos with great detail, and you wish to have smaller versions to e-mail friends, post online etc. Using jpegsize, you can easily create smaller versions of ALL of your photos in a directory with a simple command. Read more about JpegSize image resizer here.

Want to use as part of your Application? Royalty Free License

You may redistribute this software as part of your application as long as it is used as a component within your application to satisfy application functionality and it is not distributed as a competitor to the Bestcode software.

Here is the license for Bestcode File utilities.

Purchasing Bestcode File Utilities Pack

You can pay with credit card and download Bestcode File Utilties Pack immediately from our online store for only $19.95. Licensing is per user.

File Utilities pack contains Replace, ReplaceRegex, RenameRegex, FileSplit, HtmlFix2Unix, FileLineFilterRegex, FiXML, Wget4Xsd, Dos2Unix, Unix2Dos, JpegSize utilities.

Online Order Form

System Requirements: Windows with .NET Framework 1.1 or higher.

For technical questions please contact support@bestcode.com

A screen shot of file utilities:

File Utilities

 

webmaster@bestcode.com