IMDTouchKnowledge BaseShop main store

Explainer

Why fso.CopyFolder does not exist on an MP 377 panel

HMI and touchscreens Published 8 min read

Short answer

The MP 377 runs Windows CE, which never provides the desktop Scripting.FileSystemObject behind fso.CopyFolder and fso.MoveFolder; those calls belong to PC runtime only. On the panel you create the documented FileCtl.FileSystem object, move files one at a time with Movefile inside a loop you write, and verify the destination count. Fix the loop's own defects first: the reused object variable, the unassigned target variable and untested object creation.

On this page
  1. Why does fso.CopyFolder work in PC runtime but not on the panel?
  2. Which file object does Windows CE provide instead?
  3. Why does my For Each file loop fail on the MP 377?
  4. How do I move a whole folder on an MP 377 in a script?
  5. How do I test which objects the panel actually provides?
  6. What should the bench verification show before I ship the script?
  7. What breaks these scripts in the field?
  8. Questions asked

MoveFolder and CopyFolder have no equivalent on an MP 377, and the reason is the operating system, not your script: the panel runs Windows CE, and its runtime image installs only the automation objects the HMI runtime ships with it. Scripting.FileSystemObject, the desktop component behind fso.CopyFolder, fso.MoveFolder and GetFolder, never exists there, so the line that fails on the panel is the object creation itself. The documented route on the panel is the FileCtl.FileSystem object and its file-level Movefile call, driven by a loop you write: create the destination folder, move each file, then verify the count. Before blaming the panel, fix the three defects in the loop that was tried — an object variable reused as the loop variable, a call on a never-assigned variable, and an untested CreateObject. This article gives the mechanism, the corrected pattern with a worked example, and the bench checks that prove it.

Why does fso.CopyFolder work in PC runtime but not on the panel? #

Scripting.FileSystemObject is a desktop Windows component, and the MP 377 runs Windows CE, whose runtime image installs only the automation objects the HMI runtime ships, so the folder calls never exist on the panel — the CreateObject call that fetches them is what fails.

WinCC flexible VBScript is the same language on both targets; the object layer behind it is not. In PC runtime, lines in the form fso.MoveFolder Sourcefolder, "\Storage Card USB\Destinationfolder\" and fso.CopyFolder Sourcefolder, "\Storage Card USB\Destination\Destinationfolder" execute because the PC supplies Scripting.FileSystemObject, which carries CopyFolder, MoveFolder and GetFolder together with the folder semantics those names imply: recursion into subfolders, implicit creation of the destination, and removal of the source folder after a move.

A Windows CE image carries only the objects its HMI runtime installs, so a script that passes on a PC is evidence about the PC, not about the panel. The language ports; the objects do not.

Which file object does Windows CE provide instead? #

Windows CE panels get the documented FileCtl.FileSystem object, obtained with CreateObject, and its calls operate on one file at a time — Movefile source, destination — so any folder-level CopyFolder or MoveFolder behavior has to be built from a loop over individual files.

The documented CE example moves or copies a single file into a folder, which matches the object's scope: file-level in, file-level out. CreateObject is documented for WinCC VBScript on Windows CE panels precisely for this job — generating a reference to an automation object the runtime provides. What the file-level call does not carry: recursion, implicit destination creation, or removal of the source folder. Your loop supplies what the job needs, or the job is shaped to need less.

Decide the folder handling from the tree you actually have:

  • Flat folder, known file names: one Movefile call per name.
  • Flat folder, variable names: enumerate with the listing method this object documents in the WinCC flexible information system for your runtime version; GetFolder is desktop-only.
  • Nested subfolders: flatten the layout at the source — one archive folder per logging task — so a single loop covers the job.

Why does my For Each file loop fail on the MP 377? #

The tried loop script carries three defects of its own — an object variable reused as the loop variable, a call on a never-assigned variable, and a CreateObject for the desktop object the panel lacks — and any one of them stops the script before the folder question is reached.

The reported pattern:

Folder = "\Storage Card USB\ArchiveVariables\"
Set System = CreateObject("Scripting.FileSystemObject")
Set File = CreateObject("FileCtl.FileSystem")
For Each File In System.GetFolder(Folder).Files
FichierVB2.Movefile File,"\flash\"
Next

Three things break here, each on its own enough to fail the script:

  1. File receives the FileCtl.FileSystem reference, and the very next line reuses File as the For Each element variable, which overwrites the object with the first file item — the reference is gone before any move runs. An element variable must be unique to its loop and never shared with an object you still need.
  2. FichierVB2 is never assigned anywhere in the script, so Movefile is called on an empty variable — an object-required error in any VBScript engine, PC or panel alike.
  3. System depends on Scripting.FileSystemObject, the desktop object the panel does not have; if that CreateObject fails, the script stops on that line and never reaches the loop at all.

That is why the failed loop says nothing about the panel yet: fix the three defects first, then test the panel's objects on purpose.

How do I move a whole folder on an MP 377 in a script? #

Replace the single folder call with three steps — create or confirm the destination folder, move each source file with Movefile, then verify that the destination holds the same file count the source held — keeping one variable for the object and a different one for the loop.

Worked example, one logging archive: the source folder \Storage Card USB\ArchiveVariables\ holds 12 files from one logging task and the destination \flash\ArchiveVariables\ starts empty. The loop performs one Movefile call per name — 12 calls in total — and the acceptance check is arithmetic: 12 calls with 0 failures leave 12 files at the destination and 12 - 12 = 0 files at the source. If the destination reads 11 after the run, exactly one call failed, and the alarm on that call names the file.

The call pattern, with illustrative variable names declared and initialized:

Dim fc, srcDir, dstDir, fileName
Set fc = CreateObject("FileCtl.FileSystem")
srcDir = "\Storage Card USB\ArchiveVariables\"
dstDir = "\flash\ArchiveVariables\"
fileName = "ArchiveTag_2024-05-12.csv"  ' example name; repeat the call per file
fc.Movefile srcDir & fileName, dstDir & fileName

fc, srcDir, dstDir and fileName are illustrative names; CreateObject, FileCtl.FileSystem and Movefile are the documented ones. The paths reuse the card names the working scripts show. Create the destination folder before the first call — PC CopyFolder builds it for you, the file-level call does not — using the folder-create method this object documents for your runtime version, or create it once on the bench and let the logging task reuse it. The reported script passes a file object as the first argument and this example passes two path strings, so confirm the argument forms your runtime version accepts before relying on the string form.

How do I test which objects the panel actually provides? #

Bind a test script with nothing else in it to a bench button, call CreateObject for each object name, and report each result with ShowSystemAlarm: on a healthy MP 377 image expect no error for FileCtl.FileSystem and a failure on the Scripting.FileSystemObject line.

Run one object per test pass so a failure on the first call cannot hide the second. The failure on the desktop-object line is the correct reading, not a fault: that object is simply not in the panel image. If FileCtl.FileSystem itself fails to create, the problem is the project or the panel image, not your loop logic, and no amount of loop rewriting will help. One bench pass settles which objects exist, so every later decision rests on a measured answer instead of an assumption carried over from the PC.

What should the bench verification show before I ship the script? #

Six checks decide it: object creation succeeds for FileCtl.FileSystem, a named file arrives at the destination and leaves the source, a missing name traps to an alarm, a 12-file loop ends with equal counts, an existing destination name behaves as coded, and a pulled card stops the script.

  1. Object creation: FileCtl.FileSystem creates without error. A failure here means the runtime lacks the object — a project or image fault, not loop logic.
  2. Single fixed-name transfer: the file is at the destination and, for a move, gone from the source. Confirm with the panel's file browser or by reading the card on a PC.
  3. Missing-name run: a defined failure, trapped and reported through ShowSystemAlarm or a status tag — never a frozen script.
  4. Loop over the worked-example folder: the destination count equals the source count before and after the run.
  5. Same-name file already at the destination: the outcome matches what your code expects, because the script checks for the existing name before the call instead of trusting a default.
  6. Card removed mid-test on a bench panel: a trapped error and a clean stop, with no write to a path that no longer exists.

Run the card-pull test on a bench panel, never on the machine's operating terminal: mid-write card removal is the fault you are deliberately provoking.

What breaks these scripts in the field? #

Four field failures account for most of it: a card name that does not match what the panel reports, a script proven only in PC runtime, a loop long enough to freeze the screen until it finishes, and silent failures with no alarm path.

Path syntax first: a leading backslash, the card name exactly as the panel's file browser reports it, and a trailing backslash on destination folders. \Storage Card USB\ and \flash\ are the names the working scripts use; a renamed card or a dropped trailing backslash produces failures that read like script bugs.

A pass in PC runtime proves the language, not the panel. The object test runs on the target hardware before any deployment, every time.

Loop length matters because the script task runs to completion before the screen updates again — the same mechanism behind why an HMI screen freezes until its script finishes. Keep archive folders small, split the work across triggers, and never put an unbounded loop on a button an operator can hit mid-shift.

Without a reported result on every call, an absent card or a missing name looks like success. Surface each failure so the alarm list tells you what moved and what did not.

The decision, by target: in WinCC flexible PC runtime, keep the fso.CopyFolder and fso.MoveFolder calls — the desktop object provides them. On an MP 377, do not call them at all: test object creation on the panel, build the operation from FileCtl.FileSystem and per-file Movefile calls, keep the object and loop variables separate, assign every variable you call, and ship only after the six bench checks read as expected.

Questions asked

Does Movefile overwrite a file that is already at the destination?

The documented material for this object does not state the overwrite behavior, so treat it as unknown until your bench test answers it: place a file with the same name at the destination, run one move, and record whether it is overwritten or rejected. Then add your own name check before the call so the panel's default behavior never decides the outcome for you.

How large can a folder be before the loop freezes the panel?

No documented per-file transfer time exists for this object, so the limit is measured on your own hardware, not published. Time a bench run over a real archive folder, then keep each button-triggered batch under the longest pause your operators accept and move the remainder on further triggers. An archive built in thousands of files belongs in a batch design outside a button event.

Can one script serve both PC runtime and the panel?

Yes, if every file call is guarded. Create each object with CreateObject, test the reference before use, and branch on which creation succeeded: the desktop-object branch keeps the folder calls, the FileCtl.FileSystem branch runs the per-file loop. The VBScript language is identical on both targets; only the object behind the calls differs, so the object reference itself is the version check.

What does a file-level move leave behind at the source?

The source folder itself: a file-level move takes files, not folders, so after the last file moves the folder stays on the card, empty. That is harmless when the logging task keeps writing into the same folder, and cleanup is only worth it if a documented folder-delete call exists in this object's method list for your runtime version.

Keep reading

  • Troubleshooting

    Why WinCC Flexible Edits Do Not Show in Runtime

    Saved WinCC flexible edits stay invisible in Runtime until the runtime output is regenerated with Rebuild all and transferred to the target; the panel runs a build, not your project file. After redeploying, confirm the edit on the panel itself, and test every VBScript command on that target class because Windows CE panels support fewer commands than PC Runtime.

    HMI and touchscreens

  • Troubleshooting

    WinCC flexible IO field not editable on the panel

    An IO field that displays its tag but ignores touches is disabled, not over-protected: the enabled checkbox for operator interaction is cleared even though the secured box is unchecked. Tick enabled on the object first, then clear or set the secured box to match your access policy, compile and download. Clearing security alone never makes the field interactive.

    HMI and touchscreens

  • Explainer

    Can You Migrate a WinCC 7.2 Project to WinCC Flexible

    No migration path converts a WinCC 7.2 project into WinCC flexible 2008; Siemens documents the two as architecturally incompatible, and the documented directions run the other way - WinCC flexible into TIA Portal, and WinCC 7.2 up to WinCC V7.5. Treat the MP 377 12-inch Touch application as a new WinCC flexible project: inventory every function, rebuild it item by item, and verify each one on the bench.

    HMI and touchscreens