Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

permission denied when moving folder

970 views
Skip to first unread message

Lee Kok Onn

unread,
Jan 30, 2008, 4:15:07 AM1/30/08
to
I use the following script to move folder from my server1 to another server2
share folder.

Set objFSO = CreateObject("Scripting.FileSystemObject")
objFSO.MoveFolder "C:\data" , "\\server2\backup"

It will end with "permission denied" error. So how can I resolve this, pls
help.

Thanks

Pegasus (MVP)

unread,
Jan 30, 2008, 4:46:24 AM1/30/08
to

"Lee Kok Onn" <ko...@viperlink.com.sg> wrote in message
news:eKJo2ByY...@TK2MSFTNGP06.phx.gbl...

The MoveFolder method is basically a "rename" method,
hence it only works if the source and destination reside on
the same volume (same as move.exe under WinXP).


Tom Lavedas

unread,
Jan 30, 2008, 8:29:57 AM1/30/08
to
On Jan 30, 4:46 am, "Pegasus \(MVP\)" <I....@fly.com.oz> wrote:
> "Lee Kok Onn" <ko...@viperlink.com.sg> wrote in messagenews:eKJo2ByY...@TK2MSFTNGP06.phx.gbl...

While the WSH 5.6 documentation does state a caveat:

"<b>Important</b> This method allows moving folders between volumes
only if supported by the operating system. "

This Technet Script Center example and associated documentation
suggests that this may not be the problem.

<Quote>
Description
Demonstration script that uses the FileSystemObject to move a folder
from one location to another. Script must be run on the local
computer.
Supported Platforms

Windows Server 2003 Yes
Windows XP Yes
Windows 2000 Yes
Windows NT 4.0 Yes
Windows 98 Yes

Set objFSO = CreateObject("Scripting.FileSystemObject")

objFSO.MoveFolder "C:\Scripts" , "M:\helpdesk\management"
</Quote>

It is more likely to be related to a file or subfolder being in use at
the time of the attempted more - or related to the UNC addressed
target permissions.

Tom Lavedas
===========
http://members.cox.net/tglbatch/wsh/

Pegasus (MVP)

unread,
Jan 30, 2008, 8:40:35 AM1/30/08
to

"Tom Lavedas" <tglb...@cox.net> wrote in message
news:aee22b1a-eb43-41d0...@i3g2000hsf.googlegroups.com...

I read what you wrote but my tests tell me something else.
Both of the following scripts fail:


Set objFSO = CreateObject("Scripting.FileSystemObject")

objFSO.MoveFolder "C:\Thu" , "D:\Thu"

Set objFSO = CreateObject("Scripting.FileSystemObject")

objFSO.MoveFolder "C:\Thu" , "D:\"

whereas this one works:


Set objFSO = CreateObject("Scripting.FileSystemObject")

objFSO.MoveFolder "C:\Thu" , "C:\Wed"

Since drive D: is a FAT32 volume, there are no permission
issues. What do you get when you try this script?


Tom Lavedas

unread,
Jan 30, 2008, 9:30:43 AM1/30/08
to
On Jan 30, 8:40 am, "Pegasus \(MVP\)" <I....@fly.com.oz> wrote:
> "Tom Lavedas" <tglba...@cox.net> wrote in message

I had to use different source and destination locations, but as you
assert, the documentation seems to be in error. The move attempt to a
network drive addressed as H:\ failed (with a permission denied, even
though I have appropriate permissions there), while a move to the same
NTFS local drive worked.

Lee Kok Onn

unread,
Feb 4, 2008, 4:55:33 AM2/4/08
to
Thanks for the info.

I try to use movefile in the script and I need to overwrite the same file
everyday. But it prompt an error "file already exist". So its there anyway
that I can overwrite the file using movefile.

Thanks.


"Tom Lavedas" <tglb...@cox.net> wrote in message

news:681c1307-46e9-48a4...@e4g2000hsg.googlegroups.com...

Paul Randall

unread,
Feb 4, 2008, 9:23:26 AM2/4/08
to

"Lee Kok Onn" <ko...@viperlink.com.sg> wrote in message
news:O1UEvPxZ...@TK2MSFTNGP06.phx.gbl...

> Thanks for the info.
>
> I try to use movefile in the script and I need to overwrite the same
> file everyday. But it prompt an error "file already exist". So its
> there anyway that I can overwrite the file using movefile.

Why not, just before the move, check for the existence of the file at
the destination, and deleting it if necessary?

Something like:
If objFSO.FileExists(sDestinationPath) Then
objFSO.DeleteFile ( sDestinationPath[, force] )
End If

-Paul Randall


Lee Kok Onn

unread,
Feb 5, 2008, 4:46:20 AM2/5/08
to
i am using the following to delete file,

Set objFSO = CreateObject("Scripting.FileSystemObject")

objFSO.MoveFile "C:\data\*.*" , "\\server2\backup"

so how can I check for file existence with the line recommend by you.


"Paul Randall" <paul...@cableone.net> wrote in message
news:%23JLazlz...@TK2MSFTNGP06.phx.gbl...

Pegasus (MVP)

unread,
Feb 5, 2008, 5:38:49 AM2/5/08
to

"Lee Kok Onn" <ko...@viperlink.com.sg> wrote in message
news:uydLPv9Z...@TK2MSFTNGP02.phx.gbl...

>i am using the following to delete file,
>
> Set objFSO = CreateObject("Scripting.FileSystemObject")
> objFSO.MoveFile "C:\data\*.*" , "\\server2\backup"
>
> so how can I check for file existence with the line recommend by you.
>

The code you used won't "delete" files - it will move them.

To avoid an error condition you would have to thest the
target folder to see if any of the files already exist. This is
tedious. A much easier method goes like this:

Set objFSO = CreateObject("Scripting.FileSystemObject")

objFSO.CopyFile "C:\data\*.*" , "\\server2\backup" , true
objFSO.DeleteFile "C:\data\*.*", true


Paul Randall

unread,
Feb 5, 2008, 10:24:12 AM2/5/08
to
For my method, you would have to move them one at a time, using the
full name of each (no wild cards). This does have the advantage of
allowing a rename if you don't want to overwrite a previously backed
up file. If you want to always overwrite, then use Pegasus' method.

-Paul Randall

"Lee Kok Onn" <ko...@viperlink.com.sg> wrote in message

news:uydLPv9Z...@TK2MSFTNGP02.phx.gbl...

0 new messages