# EmEditor 的 JS 脚本能读写文件吗？

**URL:** <https://forum.freemdict.com/t/topic/15851>\
**Category:** 软件经验交流展望\
**Tags:** emeditor\
**Created:** [2022 年9 月 30 日 05:47 UTC](https://forum.freemdict.com/t/topic/15851 "2022-09-30T05:47:51Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

作者： ![surfactant](https://forumcdn.freemdict.com/letter_avatar_proxy/v4/letter/s/dbc845/32.png) [@surfactant](https://forum.freemdict.com/u/surfactant)\
发布日期： [2022 年9 月 30 日 05:47 UTC](https://forum.freemdict.com/t/topic/15851/1 "2022-09-30T05:47:51Z")

</div>

EmEditor 自带的几个宏脚本用一个奇怪的 ActiveXObject 对象操作文件，查MDN没找到，一搜居然是[JScript 里面的](https://learn.microsoft.com/en-us/previous-versions/windows/internet-explorer/ie-developer/scripting-articles/7sw4ddf8%28v=vs.84%29)，可文档里也没查到怎么读写文件。我印象里 JS 是不能对文件读写的，有熟悉的朋友知道 EmEditor 的 JS 脚本能否读写文件吗？谢谢！

---

<div class="post-metadata">

作者： ![wa0dhnejws](https://forumcdn.freemdict.com/letter_avatar_proxy/v4/letter/w/ecc23a/32.png) [@wa0dhnejws](https://forum.freemdict.com/u/wa0dhnejws)\
发布日期： [2022 年9 月 30 日 13:35 UTC](https://forum.freemdict.com/t/topic/15851/2 "2022-09-30T13:35:21Z")

</div>

> **[FileSystemObject object](https://learn.microsoft.com/en-us/office/vba/language/reference/user-interface-help/filesystemobject-object)**
>
> Office VBA reference topic

you may also search “FileSystemObject” for more references

---

<div class="post-metadata">

作者： ![wa0dhnejws](https://forumcdn.freemdict.com/letter_avatar_proxy/v4/letter/w/ecc23a/32.png) [@wa0dhnejws](https://forum.freemdict.com/u/wa0dhnejws)\
发布日期： [2022 年9 月 30 日 13:44 UTC](https://forum.freemdict.com/t/topic/15851/3 "2022-09-30T13:44:11Z")

</div>

For more information, below is part of EmEditor’s online help document:

## Windows Scripting Host

EmEditor macros are based on the Windows Scripting Host (WSH) engine, so you can use various Windows Component Object Model (COM) objects. For example, you can perform regular expression searches using the RegExp object, manipulate files using the FileSystemObject object, create a short-cut, manipulate the Windows Registry using the WshShell object, or work with networking functions using the WshNetwork object.

---

<div class="post-metadata">

作者： ![surfactant](https://forumcdn.freemdict.com/letter_avatar_proxy/v4/letter/s/dbc845/32.png) [@surfactant](https://forum.freemdict.com/u/surfactant)\
发布日期： [2022 年9 月 30 日 14:00 UTC](https://forum.freemdict.com/t/topic/15851/4 "2022-09-30T14:00:07Z")

</div>

It’s difficult to imagine it’s based on such a system. Thank you for sharing!

---

<div class="post-metadata">

作者： ![surfactant](https://forumcdn.freemdict.com/letter_avatar_proxy/v4/letter/s/dbc845/32.png) [@surfactant](https://forum.freemdict.com/u/surfactant)\
发布日期： [2022 年9 月 30 日 14:13 UTC](https://forum.freemdict.com/t/topic/15851/5 "2022-09-30T14:13:20Z")

</div>

Clearly you are an expert on this topic. Another question: if Python is used as the scripting language as suggested in the [doc](https://www.emeditor.com/text-editor-features/history/new-in-version-6/#activescript), is it possble to simply use Python api for manipulating files? Thanks!

---

<div class="post-metadata">

作者： ![wa0dhnejws](https://forumcdn.freemdict.com/letter_avatar_proxy/v4/letter/w/ecc23a/32.png) [@wa0dhnejws](https://forum.freemdict.com/u/wa0dhnejws)\
发布日期： [2022 年9 月 30 日 15:01 UTC](https://forum.freemdict.com/t/topic/15851/6 "2022-09-30T15:01:00Z")

</div>

> **[Python Programming on Win32: Chapter 21 - Active Scripting](http://www.icodeguru.com/WebServer/Python-Programming-on-Win32/ch21.htm)**
>
> codeguru,ºõıà³ÌѧϰÍøվ,Sample,¾µä±à³̳̽Ì,±à³̻ù´,±à³̰®ÃÕßÍøվ

Not familiar with Python, but WSH would accept any language once the corresponding engine is installed, and according to the above link, pywin32 is what you need:

> **[pywin32](https://pypi.org/project/pywin32/)**
>
> Python for Window Extensions

You may give it a try.  
BTW, I’m not an expert at all.

---

<div class="post-metadata">

作者： ![surfactant](https://forumcdn.freemdict.com/letter_avatar_proxy/v4/letter/s/dbc845/32.png) [@surfactant](https://forum.freemdict.com/u/surfactant)\
发布日期： [2022 年9 月 30 日 15:03 UTC](https://forum.freemdict.com/t/topic/15851/7 "2022-09-30T15:03:47Z")

</div>

Thank you for your reply! WSH seems to be a system with long history. Is it still actively used and worthwhile to spend some time to be acquainted with?

---

<div class="post-metadata">

作者： ![wa0dhnejws](https://forumcdn.freemdict.com/letter_avatar_proxy/v4/letter/w/ecc23a/32.png) [@wa0dhnejws](https://forum.freemdict.com/u/wa0dhnejws)\
发布日期： [2022 年9 月 30 日 15:17 UTC](https://forum.freemdict.com/t/topic/15851/8 "2022-09-30T15:17:01Z")

</div>

My pleasure. Although it’s not widely used, Windows and Office use certain WSH script files (slmgr.vbs and ospp.vbs) to manipulate their activation systems, so you can find WSH really useful once you want to use COM in your scripts.

---

<div class="post-metadata">

作者： ![surfactant](https://forumcdn.freemdict.com/letter_avatar_proxy/v4/letter/s/dbc845/32.png) [@surfactant](https://forum.freemdict.com/u/surfactant)\
发布日期： [2022 年9 月 30 日 15:19 UTC](https://forum.freemdict.com/t/topic/15851/9 "2022-09-30T15:19:46Z")

</div>

OK. Great thanks for your patient explanation!

---

<div class="post-metadata">

作者： ![wa0dhnejws](https://forumcdn.freemdict.com/letter_avatar_proxy/v4/letter/w/ecc23a/32.png) [@wa0dhnejws](https://forum.freemdict.com/u/wa0dhnejws)\
发布日期： [2022 年9 月 30 日 15:23 UTC](https://forum.freemdict.com/t/topic/15851/10 "2022-09-30T15:23:59Z")

</div>

You’re welcome
