# Archive Folder In Use

**URL:** <https://resource.dopus.com/t/archive-folder-in-use/51652>\
**Category:** Help & Support\
**Created:** [July 4, 2024, 11:52am UTC](https://resource.dopus.com/t/archive-folder-in-use/51652 "2024-07-04T11:52:06Z")\
**Posts on this page:** 13\
**Page:** 1

<div class="post-metadata">

**Author:** ![pro](https://resource.dopus.com/user_avatar/resource.dopus.com/pro/32/46008_2.png) [@pro](https://resource.dopus.com/u/pro)\
**Post date:** [July 4, 2024, 11:52am UTC](https://resource.dopus.com/t/archive-folder-in-use/51652/1 "2024-07-04T11:52:06Z")

</div>

I love Opus' Archive integration, but for some reason it automatically opens newly created or moved archives in the background (so not visibly) all by itself, making those impossible to move or delete for a few seconds.

![image](https://resource.dopus.com/uploads/default/original/3X/3/6/36e6d4da5d839b275d6051cf9768c20de615ea90.png)

Upon pressing 'Try Again', it works properly. Also when disabling the internal Opus Zip support, it's no issue at all, but that defeats the purpose.

The file has not been opened manually and there is no other process for it still ongoing, with it fully finished being created or moved prior. Also disabled any virus scanner and firewall to ensure it wasn't those checking it out and locking it up.

---

<div class="post-metadata">

**Author:** ![Leo](https://resource.dopus.com/user_avatar/resource.dopus.com/leo/32/69732_2.png) [@Leo](https://resource.dopus.com/u/Leo)\
**Post date:** [July 4, 2024, 8:16pm UTC](https://resource.dopus.com/t/archive-folder-in-use/51652/2 "2024-07-04T20:16:33Z")

</div>

Strange for such a small archive to be held open for that amount of time, if it isn't a virus scanner doing it.

Maybe a Process Monitor log of what happens will reveal the cause:

- [Process Monitor instructions](https://resource.dopus.com/t/process-monitor-instructions/27806)

---

<div class="post-metadata">

**Author:** ![pro](https://resource.dopus.com/user_avatar/resource.dopus.com/pro/32/46008_2.png) [@pro](https://resource.dopus.com/u/pro)\
**Post date:** [July 5, 2024, 4:06am UTC](https://resource.dopus.com/t/archive-folder-in-use/51652/3 "2024-07-05T04:06:03Z")

</div>

I think I found the culprit, the being kept open by a column/label script (disabling the internal Opus Zip support for no apparent reason making a difference).

It seems that `File.Close` doesn't do anything in JScript (whereas something like `var obj = new ActiveXObject('Scripting.FileSystemObject'); obj.Close()` does work and releases the file right away, but it would be nice to be able to rely on internal functions.

The [documentation](https://docs.dopus.com/doku.php?id=reference:scripting_reference:scripting_objects:file) is unclear on this. It can be interpreted as that `File.Close` can be used to manually close the file, or that the file needs to be closed manually separate from `.Close` (in which case that's not possible, because the file isn't visibly opened).

---

<div class="post-metadata">

**Author:** ![Leo](https://resource.dopus.com/user_avatar/resource.dopus.com/leo/32/69732_2.png) [@Leo](https://resource.dopus.com/u/Leo)\
**Post date:** [July 5, 2024, 5:46am UTC](https://resource.dopus.com/t/archive-folder-in-use/51652/4 "2024-07-05T05:46:15Z")

</div>

Can you provide a minimal example script that demonstrates the problem?

---

<div class="post-metadata">

**Author:** ![pro](https://resource.dopus.com/user_avatar/resource.dopus.com/pro/32/46008_2.png) [@pro](https://resource.dopus.com/u/pro)\
**Post date:** [July 6, 2024, 12:17pm UTC](https://resource.dopus.com/t/archive-folder-in-use/51652/5 "2024-07-06T12:17:42Z")

</div>

```auto
function OnInit(initData) {
 initData.default_enable = true;
 var col = initData.AddColumn();
 col.autogroup = false;
 col.autorefresh = true;
 col.label = col.name = 'English';
 col.method = 'OnEnglish';
}

function OnEnglish(data) {
 if (!data.item.is_dir) {
  var file = data.item,
      res = 0;
  if (file.size == 0) {
   res = -1;
  } else if (!file.Open.error) {
   var txt = file.Open.Read(2);
   file.Close; // also tried txt.Close; just in case
   res = (DOpus.Create.StringTools.Decode(txt,'utf-8') == 'en') ? 1 : -1;
  }
  data.value = res;
 }
}
```

---

<div class="post-metadata">

**Author:** ![aIex](https://resource.dopus.com/letter_avatar_proxy/v4/letter/a/c67d28/32.png) [@aIex](https://resource.dopus.com/u/aIex)\
**Post date:** [July 6, 2024, 12:23pm UTC](https://resource.dopus.com/t/archive-folder-in-use/51652/6 "2024-07-06T12:23:58Z")

</div>

Shouldn’t you call it `file.Close();` ?

---

<div class="post-metadata">

**Author:** ![pro](https://resource.dopus.com/user_avatar/resource.dopus.com/pro/32/46008_2.png) [@pro](https://resource.dopus.com/u/pro)\
**Post date:** [July 6, 2024, 12:25pm UTC](https://resource.dopus.com/t/archive-folder-in-use/51652/7 "2024-07-06T12:25:21Z")

</div>

I'm used to that in JavaScript too, but in Opus that throws errors, whereas `.Close` without parenthesis doesn't.

`Object doesn't support this property or method (0x800a01b6)`

---

<div class="post-metadata">

**Author:** ![aIex](https://resource.dopus.com/letter_avatar_proxy/v4/letter/a/c67d28/32.png) [@aIex](https://resource.dopus.com/u/aIex)\
**Post date:** [July 6, 2024, 12:30pm UTC](https://resource.dopus.com/t/archive-folder-in-use/51652/8 "2024-07-06T12:30:30Z")

</div>

I believe you define your `file` var wrong. It’s not `data.item`, it should be `data.item.Open()` per docs.

Then you could read the content via `file.Read()` and close the file correctly via `file.Close();`

---

<div class="post-metadata">

**Author:** ![pro](https://resource.dopus.com/user_avatar/resource.dopus.com/pro/32/46008_2.png) [@pro](https://resource.dopus.com/u/pro)\
**Post date:** [July 6, 2024, 12:35pm UTC](https://resource.dopus.com/t/archive-folder-in-use/51652/9 "2024-07-06T12:35:41Z")

</div>

I don't think so, else `.size` doesn't exist or work.

Replacing every single `file` with `data.item` will yield the same result:

```auto
function OnInit(initData) {
 initData.default_enable = true;
 var col = initData.AddColumn();
 col.autogroup = false;
 col.autorefresh = true;
 col.label = col.name = 'English';
 col.method = 'OnEnglish';
}

function OnEnglish(data) {
 if (!data.item.is_dir) {
  var res = 0;
  if (data.item.size == 0) {
   res = -1;
  } else if (!data.item.Open.error) {
   var txt = data.item.Open.Read(2);
   data.item.Close;
   res = (DOpus.Create.StringTools.Decode(txt,'utf-8') == 'en') ? 1 : -1;
  }
  data.value = res;
 }
}
```

Everything works, except for `.Close`.

---

<div class="post-metadata">

**Author:** ![aIex](https://resource.dopus.com/letter_avatar_proxy/v4/letter/a/c67d28/32.png) [@aIex](https://resource.dopus.com/u/aIex)\
**Post date:** [July 6, 2024, 12:40pm UTC](https://resource.dopus.com/t/archive-folder-in-use/51652/10 "2024-07-06T12:40:25Z")

</div>

You misunderstood me. `var file` should point to the file opened via `data.item.Open();`. it has `File` type. but `size` in your script is a property of the `Item` type itself, so you should get it from `data.item`, like `data.item.size`.

I’m not sure how that should work:  
`data.item.Open.error`  
`data.item.Open.Read(2);`  
since you don’t even call Open() here properly (or does JScript allow calls without parenthesis?). anyways, even if it does work, you open a new file each time, instead of saving the result `File` object once and operating on it, like I said.

---

<div class="post-metadata">

**Author:** ![pro](https://resource.dopus.com/user_avatar/resource.dopus.com/pro/32/46008_2.png) [@pro](https://resource.dopus.com/u/pro)\
**Post date:** [July 6, 2024, 12:42pm UTC](https://resource.dopus.com/t/archive-folder-in-use/51652/11 "2024-07-06T12:42:12Z")

</div>

I'm afraid I'm still misunderstanding it then. 😞 Can you please post the fixed code snippet?

---

<div class="post-metadata">

**Author:** ![aIex](https://resource.dopus.com/letter_avatar_proxy/v4/letter/a/c67d28/32.png) [@aIex](https://resource.dopus.com/u/aIex)\
**Post date:** [July 6, 2024, 12:47pm UTC](https://resource.dopus.com/t/archive-folder-in-use/51652/12 "2024-07-06T12:47:20Z")

</div>

Try this, but I couldn’t check it out right now:

```auto
function OnInit(initData) {
 initData.default_enable = true;
 var col = initData.AddColumn();
 col.autogroup = false;
 col.autorefresh = true;
 col.label = col.name = 'English';
 col.method = 'OnEnglish';
}

function OnEnglish(data) {
 if (!data.item.is_dir) {
  var res = 0;
  if (data.item.size == 0) {
   res = -1;
  } else { var openedFile = data.item.Open(); if (!openedFile.error) {
   var txt = openedFile.Read(2);
   res = (DOpus.Create.StringTools.Decode(txt,'utf-8') == 'en') ? 1 : -1;
  } openedFile.Close(); }
  data.value = res;
 }
}

```

---

<div class="post-metadata">

**Author:** ![pro](https://resource.dopus.com/user_avatar/resource.dopus.com/pro/32/46008_2.png) [@pro](https://resource.dopus.com/u/pro)\
**Post date:** [July 6, 2024, 12:52pm UTC](https://resource.dopus.com/t/archive-folder-in-use/51652/13 "2024-07-06T12:52:27Z")

</div>

For goodness sake, so it's really just like normal JavaScript. I thought I was following the docs to a tee with vanilla throwing all kinds of errors, making me think `.Open` was just using `data.item` itself and could be stored. 😫

Thank you so much! 🥳
