Files and Folders


Performs various file and folder operations. "Folders" and "directories" are considered the same thing in vTask and the terms are used interchangeably.

The available commands are:

  Read File
  Read File Line
  Write/Create File
  Get File Info
  Copy File
  Move/Rename File
  Delete File
  Compare Files
  Search in File
  Find File
  Count Files/Folders
  Count File Lines
  Change File Size
  Split File
  Create Folder
  Copy Folder
  Move/Rename Folder
  Delete Folder
  Set Current Directory
  Set File Association
  Map Drive
  Map Drive Prompt
  Create Shortcut
  Create Adobe PDF



  Read File
 

Loads the contents of a file into the clipboard or a variable. The "Start Position" and "Stop Position" are the byte offsets to start and stop reading. You can also choose "Start of File" and "End of File" to read the entire contents.

The file contents can be anything, including text or binary data. You can save these contents into a User Variable for usage or manipulation elsewhere in your script.

If the file does not exist, the failure option is activated.


  Read File Line
 

Loads the contents of a text file line into the clipboard or a variable. The line number to read is 1-based. The end of the line delimiter is either a CR (ASCII 13), LF (ASCII 10), or CR + LF.

The Line Number may be a variable such as "%linenum", which allows you to increment the offset value and walk through the file. Also see the Start File Line Loop action which performs the same function, and is easier if you wish to loop through all the lines in a file.

If the file does not exist, the failure option is activated.


  Write/Create File
 

Writes text to a file. If the file does not exist, it is automatically created. If the parent folder(s) and subfolders of the file do not exist, they are also created.

You can start the write command at one of three locations in the file:
To choose the appropriate write location, select the "Append" checkbox inside of the Start Position field.

To create a new empty (blank) file, simply leave the "Data to Write" field empty. A file that is 0 bytes long will be created. To write a valid new line to a file, use {newline} in the text, which is a combination of {linefeed} + {return}. Using only {linefeed} or {return} by itself may cause unprintable boxes to appear in many editors (such as Notepad). Text files require both together for a complete new line.

The "Erase Previous Data First" option deletes all data from the file before writing to it. Without this setting, if a file contains "123456789", and you write "abc" to position #0, the new contents will be "abc456789". This is usually not desired. Erasing previous contents allows the file to be shortened to match the length of the new data.

If you choose a byte offset that is past the end of the file, the write command will succeed, and the new file size will be = (the byte offset + size of data written).

The No Variable Expansion option causes all text to remain in its untranslated state. The result of this is that System Variables such as {year} will remain as "{year}" instead of being substituted for "2010". User Variables will also remain untranslated.


  Get File Info
 

Returns information about a file, folder, or disk. The following items are available:

InformationDescription
Size Size of the file, in bytes
Size (MB) Size of the file, in megabytes
Creation Time Date and time that the file (or folder) was created
Last Modified Time Date and time that the file (or folder) was last modified
Last Accessed Time Date and time that the file (or folder) was last accessed

The above 3 items are the same as shown in Windows File Explorer:





Is File Returns 1 (true) or 0 (false) if the name is of an actual file (and not a folder)
Is Folder Returns 1 (true) or 0 (false) if the name is of a directory
Version (short) Version of the file, if it exists, such as "6.50"
Version (long) Version of the file, if it exists, such as "6.50.0.0"
CRC-32 Calculates the "Cyclic Redundancy Checking" (CRC-32-IEEE 802.3) of file's contents. This can be used as an error-detecting code. It can ensure accurate transmission of a file, or check to see if a file has been changed.
Name: Drive The disk drive of the filename, for example "C:"
Name: Path The folder of the filename, for example "\Program Files\vTask\"
Name: Drive+Path The disk drive and folder of the filename, for example "C:\Program Files\vTask\"

Note that if the file does not exist, or if a relative path or no path is given, the result path will be the current directory.
Name: Base The main name of the filename, for example "vTask"
Name: Drive+Path+Base The full path of the filename, except the extension, for example "C:\Program Files\vTask\vTask"
Name: Extension The type of the filename, for example ".EXE"
Name: Base+Extension The name and type of the filename, for example "vTask.exe"
Document Association The path to the associated EXE program that runs the file
(for example, notepad.exe opens text ".TXT" files)
Attributes (number) Attributes of the physical file in numeric format, such as "8224"
Constants such as FILE_ATTRIBUTE_READONLY can be used to evaluate the attributes
Attributes (string) Attributes of the physical file in string (text) format, such as "Hidden, Read Only, System"
FileDescription Generic description of the program.
Example: "vTask"
Comments Generic comments for the program.
Example: "Programmed by Vista Software, Inc. (www.vtaskstudio.com)"
CompanyName Generic company name of the program.
Example: "Vista Software, Inc."
LegalCopyright Generic copyright string for the program.
Example: "Copyright © 2003-2010 Vista Software, Inc. All Rights Reserved."



  Copy File
 

Performs a simple file copy command. There are various reasons that this command could fail, such as the destination file being locked or open by another program. vTask simply returns the error that the operating system provides in such cases.

Recursion and Wildcards are supported in the source file name. Wildcards (*, ?) allow you to match partial file names, and include a range of files. For example, the file name "data*.*" would match "data1.dat", "data2.dat", and "data.txt".

*Tip:  For further information on wildcard names, see the online reference for wildcards.

Recursion will perform the operation on all the files that are contained in the main source folder, and all sub-folders (child directories) that are under it. Recursion and Wildcards can also be used together.


  Move/Rename File
 

Moving and Renaming a file perform in the same fashion (the final effect is the same). This action is able to move a file to an entirely new subdirectory.

Recursion and Wildcards are described in detail in the Copy File section.


  Delete File
 

Permanently erases a file. There are various reasons that this command could fail, such as the destination file being locked or open by another program. vTask simply returns the error that the operating system provides in such cases.

You can pass multiple file names to be deleted, each separated by a semicolon ";". For example: "file_1.txt; file_2.txt; file_3.txt;"

Recursion and Wildcards are described in detail in the Copy File section.


  Compare Files
 

Evaluates two separate files to determine if they are equal. The following qualities of the files are compared:

If all of the above qualities are the same, the return value is 1. If any of the comparisons are not equal, the return is 0.


  Search in File
 

Scans a file for a specific string or data. The data return is the offset where the string is located. Like all other file commands, this offset is 0-based, therefore "0" would be position #1, and "1" would be #2.

The "Find Which" option is the occurrence to locate, where "1" is the first match, "2" is the second match, etc. Leave blank (or set to "0") to find the first match in the file.

The data to locate can be either a string or binary data. During scanning, the current offset will be displayed in the status bar. Press the stop run key to terminate a large file search.



If the specified string cannot be found, the On Failure option is actived.

*Tip:  You can include the "Search in File" command inside of a "Start Files Loop" block to scan through a group of files or a folder, and create your own search program (grep).



  Find File
 

Searches the hard disks for a file or multiple files. This command simply searches the specified folders and sub-folders for all files that match the search name criteria.

There are three options for the data return:

If no starting folder is provided, the entire current hard drive is searched.


  Count Files/Folders
 

Returns the total count of files or folders.

Recursion and Wildcards are supported in the source file name. Wildcards (*, ?) allow you to match partial file names, and include a range of files. For example, the file name "data*.*" would match "data1.dat", "data2.dat", and "data.txt".

*Tip:  For further information on wildcard names, see the online reference for wildcards.

Recursion will perform the operation on all the files that are contained in the main source folder, and all sub-folders (child directories) that are under it. Recursion and Wildcards can also be used together.

Note: If you intend on frequently using the file/folder count, be sure to store the output in a variable. By design, vTask will re-calculate the file count each time this command is used.


  Count File Lines
 

Returns the number of lines in a text file. The end of the line delimiter is either a CR (ASCII 13), LF (ASCII 10), or CR + LF.

if you are using this action to create a data-driven script, see the Start File Line Loop action which performs a similar function.

If the file does not exist, the failure option is activated.


  Change File Size
 

Alters the size (in bytes) of file. If the file is made smaller than its previous size, the contents of course will be truncated (chopped).

If the file is made larger, the new space past the end of the previous contents will be filled with the character that you set (a single letter or byte). If no character is given, a null character (0) will be used. Please note that using a special character to fill in extra space can take some time if the file is very large (gigabytes). Using a null character will not cause a delay.


  Split File
 

Copies a file into mulitple smaller files (the original file is left unmodified). Each new portion of the original file is named "File.001, File.002", etc. For example, if the original file is "BigFile.ZIP", the new output files will be named "BigFile.ZIP.001", "BigFile.ZIP.002", etc.

A maximum of 999 output files can be created for this operation.

The files can be combined again using the COPY command with the /B switch (binary copy) and the "+" sign. The example below combines the smaller files into a new original file named "NEWFILE.ZIP":

COPY /B file.zip.001 + file.zip.002  NEWFILE.ZIP


This command is useful for breaking large files into a smaller size that can be copied on to a CD-ROM or memory cards. For very large files, the status bar of vTask Studio will indicate the progress of the copy operation.


  Create Folder
 

Creates a new empty folder/directory. This action is able to create multiple levels of new sub-folders, such as C:\NewParentFolder\SubFolder1\SubFolder2, etc. In other words, an entire new directory structure (tree) can be created with a single action - each folder does not need to be created separately.


  Copy Folder
 

The Copy Folder action is able to recursively copy all of the source directory's file contents (the whole tree), including files. If this action fails, the most likely reason is that one or more of the files are currently open (or running) in another program.


  Move/Rename Folder
 

Moving and Renaming a folder perform in the same fashion (the final effect is the same). As with the other folder actions, multiple levels (directory structures) can be created with a single command. If this action fails, the most likely reason is that one or more of the files are currently open (or running) in another program.


  Delete Folder
 

Erases an entire folder tree (directory structure), including all files, with one command. There is no prompt before the action is performed.

WARNING!   Be especially careful with Delete Folder, since it will remove all folders and sub-folders, even if they contain files - it functions as "deltree". IF DONE INCORRECTLY, THIS COULD MAKE YOUR COMPUTER NON-FUNCTIONAL. There is no undo, so please use with caution!


  Set Current Directory
 

Changes the current working directory to the path that you specify. This is useful for other operations that will be performed in the script in the same directory.

To check the current directory at any time, use the {curdir} system variable.


  Set File Association
 

Changes the program file, description, and icon of a file to a new program application that you specify. An example of a valid entry would be:



Be careful not to overwrite standard/common file extensions, such as TXT, DOC, or BMP. Doing so could possibly cause your files to not open correctly. To check the current association of a file, right click on a file in Windows Explorer and choose "Properties" in the popup menu.


  Map Drive
 

Creates a new drive letter mapping to a shared path that you provide. Various methods are employed for this action, starting with the operating system services for mapping, and ending up with the console mapping functions if there is no success.

The typical share path syntax is:

\\computername\sharename\dir\subdir

such as:

\\sa-cjfrlgsbudj3m\C$\windows\system32


If you encounter difficulties with this command, try using the Map Drive Prompt action listed next. It provides a Windows-supported method of listing shared drives.


  Map Drive Prompt
 

Creates a new drive letter mapping to a shared path, through a Windows prompt. This method is preferable to the Map Drive action, since Windows will provide you with a Browse button to search for shared paths, as well as other options such as "Reconnect at logon".

No values are returned by vTask after this action; Windows performs the drive mapping upon completion.




  Create Shortcut
 

Creates a new shortcut, which points to another program or document.

The only required option is "Program/Document to Link", which is the source of the link. This can either be a program (such as "Notepad.exe"), or a document (such as "Report.doc"). All the other settings are optional, and will be done automatically if omitted. The icon of the source program/document will be used (this is determined by Windows).

To create a link on the Desktop or Start Menu, choose the appropriate "Create in Folder" option. The "(link name folder)" option indicates that you ahve included a full path for the link destination folder inside of the "Link Name".

The created shortcut will appear as:




  Create Adobe PDF
 

Creates a new Adobe PDF file which can be read with Adobe Acrobat. If the parent folder(s) and subfolders of the file do not exist, they are also created.

This action will take any text and turn it into a PDF file. It is possible to generate impressive PDF output with only a single vTask command. The output can be normal-sized paper (profile or landscape), as well as any other size of output, such as mailing labels and envelopes.

You can set the margins, font, font size, and other document properties. Since the input used to create the PDF file is raw text, there are few embedded formatting options that can be applied. However, a page break may be inserted into the text with the {PAGE} or {\P} system variable. No text should follow on the same line as the page break symbol "{PAGE}" - it must be at the end of a line (or on a line by itself).



The page layout settings include:

PDF SettingDescription
Left Margin (inches) The horizontal space between the left side of paper and the beginning of the text. This margin is only for the left side; the right side does not use a margin since no end-of-line wrapping is done by vTask. Leave blank for default (1).
Top Margin (inches) The vertical space between the top of the paper and the beginning of the text. This margin is used for both the top and the bottom of the page, and determines where the page breaks will occur. Leave blank for default (0.75).
Page Width (inches) The horizontal size of the paper.

Leave blank for default (8.5), or enter 11 for Landscape mode.

The maximum page width is 2 meters, or 6 feet (72 inches).
Page Height (inches) The vertical size of the paper.

Leave blank for default (11), or enter 8.5 for Landscape mode.

The maximum page height is 2 meter, or 6 feet (72 inches).
Include Contents
Adds a "Contents" pane on the left in Acrobat Reader to allow easy document navigation. Use the {PAGE} or {\P} system variable to indicate page breaks. When this option is chosen, vTask will use the first text on the page as the Contents entry:



Include Page Numbers
Adds page numbers to the bottom of each page in the document, in the format "Page x of x":



Auto Word Wrap
Automatically breaks lines that are too wide for the page into multiple lines. This is similar to the "Word Wrap" that is available in the Notepad program.



The following is an example without Word Wrap turned on:



NOTE: The maximum size of any line is 500 characters.
Include Line Numbers
Adds line numbers to each text row in the document:



Font / Font Size
Sets the formatting options for the document font.

Since there is no way to signify changing fonts inside of the raw text source, only a single font is applied to the entire document.