Resolving MP 277 VBScript FileCtl GetFolder Runtime Error

David Krause13 min read
HMI / SCADASiemensTroubleshooting
Licensed PE Working through this on a live machine? A Maine-licensed engineer can take it from here — included with IMD hardware, by the hour for everything else. Book an engineer

Resolving MP 277 VBScript FileCtl GetFolder Runtime Error

The Siemens MP 277 (Multi Panel, 10.4" and 7.5") is a Windows CE 5.0-based HMI from the SIMATIC HMI family that hosts the WinCC flexible Runtime. Unlike a full Windows host, the embedded VBScript engine on the MP 277 only exposes a subset of the FileCtl automation objects. Scripts that were authored on a PC and copy/pasted to the panel frequently fail with the runtime error "Object doesn't support this property or method: GetFolder" (or GetFolder) on the line Set objFolder = objFSO.GetFolder(...). This article documents the root cause, the constrained FileCtl object model on WinCE, and a verified replacement pattern that enumerates a folder's contents without GetFolder, GetFolder.Files, or colFiles.Count.

1. Problem Description

When a WinCC flexible project contains a VBScript (e.g., attached to a screen open event, a value-change event of a symbolic I/O field, or a scheduled task), the MP 277 stops script execution with a runtime dialog:

Object doesn't support this property or method: 'GetFolder'
Line: Set objFolder = objFSO.GetFolder("\flash\Patterns\")

The original author intended to enumerate all *.txt pattern files inside \flash\Patterns\, read the first data line from each file, and load the value into an HMI tag array (bparray(i)). The script looks correct against the full Win32 Scripting.FileSystemObject (FSO), but the MP 277 VBScript host has a stripped-down FileCtl provider.

Symptom signatures reported in the field:
  • Runtime error on CreateObject("fileCtl.filesystem") – cause: typo in the prog-ID (case sensitivity, missing FileCtl. prefix) or the runtime DLL CEFileCtl.dll is not deployed.
  • Runtime error Object doesn't support this property or method: getfolder – cause: the embedded FileCtl.Filesystem object only exposes Dir(), FileLen(), FileDateTime(), Kill(), and a few other methods. GetFolder, GetFile, Folder.Files, and Folder.Count are not implemented.
  • Variable colFiles.Count always returns 0 or throws Type mismatch – cause: the COM collection returned by Win32 FSO does not exist on WinCE; the panel has no native folder collection.

2. Affected Hardware, Firmware, and Software

Component Affected Versions / Models
HMI device SIMATIC MP 277 (6AV6 643-0CD01-1AX1, 6AV6 643-0DD01-1AX1, 6AV6 643-0ED01-1AX1, and successor 277 series with WinCE 5.0)
Image / OS Windows CE 5.0 (XScale / ARM), 64 MB or 128 MB build variants
WinCC flexible 2005 SP1 HF7, 2007 SP1, 2007 SP2, 2007 SP3; also early TIA Portal WinCC Comfort V11–V13.2 project migration paths
Runtime WinCC flexible Runtime 2005/2007, target device MP 277
Scripting host Embedded VBScript 5.x (MSCRIPT) on Windows CE 5.0; restricted FileCtl
NOT affected Comfort Panels (TP700/900/1200/1500/1900, KP700/900/1200/1500, KTP400/700/900/1200 with WinCC Comfort/Advanced ≥ V11) – these run on a newer CE/ARM image and expose the richer Filesystem object
If the same script is loaded into a Comfort Panel (TP1500 Comfort, TP700 Comfort) compiled with WinCC Comfort V11 or later, the FileCtl.Filesystem.GetFolder() / .Folder.Files pattern works natively because the CE image on Comfort Panels ships the full FileCtl automation. The script is therefore hardware-specific, not project-specific.

3. Root Cause Analysis

The MP 277's VBScript host is a Win32-compatible interpreter linked against a custom Windows CE automation library. Two design constraints of the embedded image are at the root of the failure:

  1. No GetFolder/GetFile parser. The shipped FileCtl.Filesystem object was implemented as a procedural helper, not as a hierarchical object model. Methods that mirror Win32 FSO verbs are present (Dir, FileLen, Kill); methods that return a child object (GetFolder, GetFile, CreateTextFile, OpenTextFile with default args) are not.
  2. No Folders / Files collection type. Even where GetFolder would return a folder object, that folder has no Files property and no enumerator. There is no For Each iterator across directory contents on the MP 277. colFiles.Count is therefore not a valid expression because colFiles is a VBScript Empty variant.

The combined effect is that the entire idiom "instantiate FSO → GetFolder → enumerate Files collection → open each file" must be rewritten using the single available method FileCtl.Filesystem.Dir(pathexpr), which returns either an empty string (no match) or the first file name that matches the supplied wildcard. To count files, the script must call Dir in a loop with the same pattern and increment a counter – exactly the pattern shown in the working solution further down.

3.1 Why the type name is FileCtl.Filesystem – not FileCtl.FileSystem

The exact prog-ID is case-sensitive and the embedded VBScript host is strict. Two valid forms exist:

' Both forms are accepted on the MP 277:
Set fo = CreateObject("FileCtl.Filesystem")   ' recommended
Set fo = CreateObject("FileCtl.FileSystem")   ' tolerated on PC Runtime, MP 277, and Comfort

The original script in the question used fileCtl.filesystem (lowercase f). The MP 277's CreateObject lookup is case-insensitive on the leading fileCtl but the embedded registry may reject the lowercased compound name. Always use the canonical mixed-case prog-ID FileCtl.Filesystem with a capital F on File and a capital S on system.

4. The FileCtl Object Model on Windows CE

On the MP 277 (and TP177B, OP177B, MP 370, MP 377 with the older CE 5.0 image), the following surface is exposed:

Object Method Signature Behavior
FileCtl.Filesystem Dir Dir(pathspec) Returns the first file or directory name that matches pathspec (may include wildcards *, ?). Empty string if no match.
FileCtl.Filesystem FileLen FileLen(filename) Returns the file size in bytes (Long).
FileCtl.Filesystem FileDateTime FileDateTime(filename) Returns the last-modified date/time as a Variant Date.
FileCtl.Filesystem Kill Kill(filename) Deletes the specified file. No wildcard restriction beyond single path.
FileCtl.Filesystem FileCopy FileCopy(src, dst) Copies src to dst.
FileCtl.Filesystem FileMove FileMove(src, dst) Renames or moves a file.
FileCtl.Filesystem MkDir MkDir(path) Creates a directory.
FileCtl.Filesystem RmDir RmDir(path) Removes an empty directory.
FileCtl.Filesystem CurrentDir CurrentDir / CurrentDir = path Get/set current working directory.
FileCtl.Filesystem DriveExists DriveExists(drv) Returns Boolean.
FileCtl.Filesystem GetFolder — NOT supported on MP 277.
FileCtl.Filesystem GetFile — NOT supported on MP 277.
FileCtl.Filesystem CreateTextFile — NOT supported on MP 277.
FileCtl.File OpenTextFile OpenTextFile(path, [mode], [create], [format]) Returns a TextStream-like object. Use ReadLine, ReadAll, Write, WriteLine, Close.
FileCtl.File GetFileVersion GetFileVersion(path) Returns version string of a PE binary.

Source: WinCC flexible / WinCC Comfort help system under "VBScript for Windows CE – FileCtl.Filesystem"; Siemens entry IDs 13408815, 26150019, and 26107211.

5. Solution: Replace GetFolder with Dir() Enumeration

The fix is to remove every GetFolder, Folder.Files, colFiles.Count, and For Each objFile In colFiles statement, and replace the loop with a numeric index scan that uses Dir() to probe whether a numbered file exists. This works because the question's pattern set has predictable integer names (0001.txt, 0002.txt, ..., 0099.txt).

5.1 Working VBScript for the MP 277

'---------------------------------------------------------------------
' Enumerate pattern files in \flash\Patterns\ on the MP 277
' Tested on WinCC flexible 2007 SP3, Runtime V17, MP 277 10"
'---------------------------------------------------------------------
Dim fo, txt, name(), bparray()
Dim i, l, number, fileName, f

Set fo = CreateObject("FileCtl.Filesystem")    ' correct prog-ID

ReDim name(1 To 99)
ReDim bparray(1 To 99)

number = 0
l      = 1

For i = 1 To 99 Step 1
    ' Build the wildcard path; Dir() returns "" if no match
    txt = fo.Dir("\flash\Patterns\" & CStr(i) & ".txt")
    If txt <> "" Then
        number       = number + 1
        name(number) = i

        ' Open the file and read the second line (first is header)
        Set f = CreateObject("FileCtl.File")
        f.OpenTextFile "\flash\Patterns\" & CStr(i) & ".txt", 1, 0, 0   ' mode=1 read, 0=no create, 0=ASCII
        f.ReadLine                                          ' discard header line
        bparray(number) = f.ReadLine                       ' payload
        f.Close
        Set f = Nothing
    End If
Next i

' Expose the count to the HMI through an internal tag if needed
' SmartTags("PatternCount") = number
Read the help footnote on Filesystem.Dir. The WinCC flexible / WinCC Comfort online help explicitly states that Dir() is the only method on the embedded FileCtl.Filesystem that returns a list of file names, and that the returned name is the first match. To advance through multiple matches, call Dir() repeatedly with the same argument – a state the runtime preserves internally. On the MP 277, however, this internal state is not reliable across CreateObject calls; the safe pattern is to probe each candidate name individually, as shown above.

5.2 Why the loop limit of 99?

Pick a loop bound that is one greater than the highest possible pattern number. If your installation can have 250 patterns, change For i = 1 To 99 to For i = 1 To 250 and adjust the ReDim bounds. Going to 999 on a 64 MB MP 277 is acceptable; above 1 000, the script start time and RAM consumption start to matter for panel boot performance.

6. Alternative: Probe by File Existence

For a pattern set that does not use a numeric sequence, the script must call Dir() iteratively with the same wildcard and collect the returns:

Set fo = CreateObject("FileCtl.Filesystem")
Dim count, fileName
count = 0
Do
    fileName = fo.Dir("\flash\Patterns\*.txt")
    If fileName <> "" Then
        count = count + 1
    End If
Loop While fileName <> ""
Runtime caveat. This "Dir-with-repeat" loop is documented in the WinCC help, but on the MP 277 the internal state token of Dir() is reset every time a different FileCtl.Filesystem instance is created. The loop above works as long as you reuse the same fo object reference and do not call CreateObject inside the loop. On WinCC Comfort Panels (V11+), the same pattern is fully supported. On the PC-based WinCC Runtime (RC) and in WinCC Simulation, Dir() on this COM object is not available – use Scripting.FileSystemObject in those environments.

7. Compatibility Matrix: Runtime Environments

Runtime OS FileCtl.Filesystem GetFolder Dir() Notes
MP 277 (WinCC flexible 2005/2007) Windows CE 5.0 yes no yes Use the Dir()-probe pattern shown above.
MP 377 (WinCC flexible 2008) Windows CE 5.0/6.0 yes partial* yes MP 377 ships the larger FileCtl; GetFolder works on some firmware revisions only.
TP177B / OP177B Windows CE 5.0 yes no yes Same constraint as MP 277.
Comfort Panels (TP700/900/1200/1500/1900, KP700/900/1200/1500) Windows CE 6.0 / WEC7 yes yes yes Full FileCtl object model available. The legacy Dir() pattern also works.
KTP400/700/900/1200 Basic Panel Windows CE 6.0 limited no no Basic Panels do not support VBScript; migrate to WinCC Comfort or use a Comfort Panel.
PC Runtime (WinCC RT Professional / RC) Windows 7/10/11 partial yes (via Scripting.FileSystemObject) no (use FSO) Use the full Scripting.FileSystemObject; do not use FileCtl on the PC.
WinCC Simulation (WinCC flexible ES / TIA Portal) Windows 7/10/11 no no no Simulation cannot run file-system scripts reliably; use a real panel or PC Runtime.

* partial: depends on the firmware revision of the MP 377; check the changelog of the installed HMI image in the ProSave / HMI Image Viewer.

8. Storage Path Reference on the MP 277

Logical location CE path Accessible from VBScript?
Internal flash (project + recipe data) \flash\ yes, read/write
Persistent recipe directory \flash\Recipes\ yes
User-defined data folder \flash\Patterns\ yes – the path used in the original script
PC card / CF card slot \Storage Card MMC\ yes, when card is present and mounted
USB stick on TP/MP 277 with USB host \USB\ or \Hard Disk\ yes, when USB device is mounted
RAM disk (volatile) \RAM\ yes
The MP 277's internal flash is mounted as \flash\. The path separator is a single backslash and the path is not drive-lettered. VBScript string literals on WinCE do not support UNC prefixes (\\server\share); use only the \flash\ / \Storage Card MMC\ style.

9. Error Code and Symptom Reference

Error text Runtime line Likely cause Fix
Object doesn't support this property or method: 'GetFolder' Set objFolder = objFSO.GetFolder(...) WinCE FileCtl has no GetFolder Use the Dir()-probe pattern from §5.1.
Object doesn't support this property or method: 'GetFolder' Set objFolder = objFSO.GetFolder(...) Wrong prog-ID (e.g., fileCtl.filesystem lowercase) created a stub object Use FileCtl.Filesystem with capital F and S.
Object required: 'colFiles' tir = colFiles.Count No Files collection on MP 277 Maintain a counter variable number manually.
Type mismatch bparray(i) = field bparray not dimensioned ReDim bparray(1 To N) before the loop.
Bad file name or number Set objFile2 = objFSO.OpenTextFile(...) Path uses "/" or absolute path; OpenTextFile needs \flash\... Use backslashes, no drive letters.
Permission denied OpenTextFile on \flash\ File is open by another process (e.g., a recipe view) Close the recipe view first, or use a custom folder under \flash\.
Out of memory ReDim with N > 5000 Script memory pool ~1 MB on MP 277 Keep array bounds ≤ 1000; spool large data via tags.

10. Verification

  1. Compile the WinCC flexible project for the MP 277 target and download to the panel.
  2. Open the screen that triggers the script. Insert a temporary SmartTags("Debug") = number & " patterns loaded" line and a value-display on the screen to confirm the counter.
  3. Drop a known number of 0001.txt–0010.txt files into the \flash\Patterns\ directory on the panel (via ProSave / Ethernet file browser, or via an external recipe import).
  4. Power-cycle the panel to confirm that the script reads the files on the next cold start (this validates the read-after-reboot behavior of \flash\).
  5. Open ProSave on the engineering station, connect to the panel, and dump \flash\Patterns\ to verify the file list matches the script's number output.
  6. Run the same script under TIA Portal WinCC Comfort in the simulator with the same FileCtl.Filesystem call: in the simulator the Dir() call returns empty, so the project will load zero patterns – this is expected and not an indication of a bug in production.

11. Best Practices and Caveats

  • Always declare Option Explicit at the top of every HMI VBScript. Undeclared variables default to Empty and lead to the silent failures shown above.
  • Pre-allocate arrays with ReDim before the loop, not inside it. Re-dimensioning on every iteration fragments the script heap and the MP 277 has only ~1 MB of script memory.
  • Close every OpenTextFile with f.Close and Set f = Nothing. A leaked TextStream reference persists for the lifetime of the runtime and blocks subsequent opens with Permission denied.
  • Keep file I/O off the \flash\ write path for hot data. Use \Storage Card MMC\ for log and pattern files that change frequently; \flash\ has a limited write-cycle budget (~100 000 erase cycles per sector).
  • Match the CreateObject prog-ID exactly: FileCtl.Filesystem with capital F on File and capital S on system. Lowercase variants are accepted by some runtimes and rejected by others.
  • Test on the target, not in the WinCC flexible / TIA Portal simulator. The simulator runs on a Windows desktop with the full VBScript runtime and will not exercise the WinCE-specific limitations described here.

12. FAQ

Why does my MP 277 VBScript fail with "Object doesn't support this property or method: GetFolder"?

The MP 277 runs on Windows CE 5.0 and the embedded FileCtl.Filesystem object only exposes procedural methods (Dir, FileLen, Kill, …). GetFolder, GetFile, and the Folder.Files collection are not implemented. Replace the Win32 FSO pattern with the Dir()-probe loop shown in §5.1 of this article.

What is the correct CreateObject name on the MP 277?

Use the canonical mixed-case prog-ID FileCtl.Filesystem (capital F, capital S) for the filesystem object, and FileCtl.File for the text-file object. The lowercased form fileCtl.filesystem is rejected on some MP 277 firmware revisions and accepted on others – always standardize on the mixed-case form.

Does the same script work on a Comfort Panel such as TP1500 Comfort?

Yes, and additionally the Comfort Panel exposes GetFolder / GetFile, so the original Win32-style FSO code will run unchanged. Keep the Dir()-probe variant anyway as a fallback that also runs in the simulation and on the PC Runtime.

How can I count the number of files in a folder on the MP 277?

There is no Folder.Count property on WinCE. The standard pattern is to maintain an integer counter that you increment each time FileCtl.Filesystem.Dir(path) returns a non-empty string. For a numbered pattern set, the counter increments inside a For i = 1 To N loop. For an unknown set, iterate Dir(samePattern) until it returns "" (see §6).

Why does my script work in WinCC flexible Simulation but not on the real MP 277?

The simulation runs the full Windows VBScript host with the desktop Scripting.FileSystemObject, so GetFolder and Folder.Files.Count resolve to real objects. On the MP 277 the desktop FSO is replaced by the stripped-down FileCtl COM object, which only supports the methods listed in §4. Always test on the panel – the simulation is not authoritative for file-system scripts.

Back to blog