Discussion:
Moving folders and files
(too old to reply)
Keith Tizzard
2023-02-15 16:37:24 UTC
Permalink
In my application I need to access the file system to carry out a number of activities.

There is a folder (orginalQuoteFolder) that contains a number of subfolders, many of which contain files.

I need to move this folder to a new location (newQuoteFolder) using something like:

Dim FSO As Object
Set FSO = CreateObject("Scripting.FileSystemObject")
FSO.movefolder originalQuoteFolder, newQuoteFolder
' move the Quote folder
Set FSO = Nothing

This usually works but the client says that it occasionally fails. They claim, although I have not seen the evidence, that this is because one or more of the contained files is open by another user.

Q1: Is this likely to be true?
i.e is it only possible to move a folder if all its contained files are closed?

Q2: If the move fails for this reason, how can one determine which file is open and which user has opened it?
Ulrich Möller
2023-02-16 09:14:54 UTC
Permalink
Hi,
Post by Keith Tizzard
In my application I need to access the file system to carry out a number of activities.
There is a folder (orginalQuoteFolder) that contains a number of subfolders, many of which contain files.
Dim FSO As Object
Set FSO = CreateObject("Scripting.FileSystemObject")
FSO.movefolder originalQuoteFolder, newQuoteFolder
' move the Quote folder
Set FSO = Nothing
This usually works but the client says that it occasionally fails. They claim, although I have not seen the evidence, that this is because one or more of the contained files is open by another user.
Q1: Is this likely to be true?
i.e is it only possible to move a folder if all its contained files are closed?
That's correct.
Post by Keith Tizzard
Q2: If the move fails for this reason, how can one determine which file is open and which user has opened it?
In case of an error, the error number can be evaluated.
Unfortunately, I don't know of any way to tell who opened the file.

Ulrich
Ron Paii
2023-02-20 22:14:53 UTC
Permalink
Post by Ulrich Möller
Hi,
Post by Keith Tizzard
In my application I need to access the file system to carry out a number of activities.
There is a folder (orginalQuoteFolder) that contains a number of subfolders, many of which contain files.
Dim FSO As Object
Set FSO = CreateObject("Scripting.FileSystemObject")
FSO.movefolder originalQuoteFolder, newQuoteFolder
' move the Quote folder
Set FSO = Nothing
This usually works but the client says that it occasionally fails. They claim, although I have not seen the evidence, that this is because one or more of the contained files is open by another user.
Q1: Is this likely to be true?
i.e is it only possible to move a folder if all its contained files are closed?
That's correct.
Post by Keith Tizzard
Q2: If the move fails for this reason, how can one determine which file is open and which user has opened it?
In case of an error, the error number can be evaluated.
Unfortunately, I don't know of any way to tell who opened the file.
Ulrich
I don't know to tell who has a file open using FSO. Using <Control panel / Administrative Tools / Computer Management / Shared Folders / Open Files> on the computer with the file, will show who has file open.

A quick test on the ability to move a folder is attempting to rename the folder.
Keith Tizzard
2023-02-21 19:26:06 UTC
Permalink
Post by Ulrich Möller
Hi,
Post by Keith Tizzard
In my application I need to access the file system to carry out a number of activities.
There is a folder (orginalQuoteFolder) that contains a number of subfolders, many of which contain files.
Dim FSO As Object
Set FSO = CreateObject("Scripting.FileSystemObject")
FSO.movefolder originalQuoteFolder, newQuoteFolder
' move the Quote folder
Set FSO = Nothing
This usually works but the client says that it occasionally fails. They claim, although I have not seen the evidence, that this is because one or more of the contained files is open by another user.
Q1: Is this likely to be true?
i.e is it only possible to move a folder if all its contained files are closed?
That's correct.
Post by Keith Tizzard
Q2: If the move fails for this reason, how can one determine which file is open and which user has opened it?
In case of an error, the error number can be evaluated.
Unfortunately, I don't know of any way to tell who opened the file.
Ulrich
I don't know to tell who has a file open using FSO. Using <Control panel / Administrative Tools / Computer Management / Shared Folders / Open Files> on the computer with the file, will show who has file open.
A quick test on the ability to move a folder is attempting to rename the folder.
If this were Unix I could most likely find and run the program that produces this. And then pipe its output through a filter to select just those files in the folder of interest.
Loading...