Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Problem with fso.move

Status
Not open for further replies.

xim

MIS
Sep 2, 2003
8
AU
I'm having a small problem setting up a folder move from one w2k server to another, yet when I do a copy, it works fine. The error I get is a permissions thing, and funnily enough, the directories both have full permissions for everyone. My code looks as follows:

Call objFolder.Move(BGOArchiveDir & strServerName & "\")

Any help on this matter would be highly appreciated...

xim_
 
If you have a file open when doing a move, you will get a
Permission Denied message (or something similar). Since you can cope but not move, my guess is that you, or someone else, has one of the files in that folder open.
 
I don't believe this is the issue, as the files have no need to be in use at the time the script is run (ie. they are log files). A double check of the current Open Files, as shown in the MMC | Shared Folders | Open Files shows no files currently open/locked
 
I can't really tell what you're doing with your example. What happens if you try code like this:

dim sourceFolder
dim destFolder

sourceFolder = "c:\MySourceFolder"
destFolder = "c:\MyDestFolder" 'If destination folder already exists then append with "\"

Call MoveThisFolder(sourceFolder, destFolder)

Sub MoveThisFolder(SourceFolder, DestFolder)
Dim fso
Set fso = CreateObject("Scripting.FileSystemObject")
fso.MoveFolder SourceFolder, DestFolder
msgbox "Move complete"
End Sub

 
VBScript,

I dunno, I'm a newb when it comes to this stuff. My boss likes to throw me into the deep end with no training. :)

I can't use the MoveFolder command, no idea why, but it doesn't work.
 
Here is enough of the script for you to get an understanding of what it does/doesn't do, if you need any more, just ask.



dim WshNetwork
dim strServerName
dim strDay, strMonth
dim intSlash1, intSlash2, strNow
Dim objFSO, objMainFolder, objFolders, objFolder, strCurrentDate, objFiles, objFile, strNewFileName, strFolderName, intPos, strCopiedFolder, tmpFolder

Set objFSO = CreateObject("Scripting.FileSystemOBJECT")

If not objFSO.FolderExists(BGOArchiveDir & strServerName) Then
set tmpFolder = objfso.CreateFolder(BGOArchiveDir & strServerName)
End If

Set objMainFolder = objFSO.GetFolder("D:\logmovetest")
Set objFolders = objMainFolder.SubFolders

For Each objFolder In objFolders

If Left(objFolder.Name, Len(BGOFolderPrefix)) = BGOFolderPrefix Then

strFolderName = BGOArchiveDir & strServerName

If Mid(objFolder.Name, Len(BGOFolderPrefix)+1, Len(strCurrentDate)) < strCurrentDate Then
wscript.echo BGOArchiveDir & strServerName & &quot;\&quot;
Call objFolder.Move(BGOArchiveDir & strServerName & &quot;\&quot;)

Cheers,


xim_
 
Can you post the whole thing? There's code in here that makes comparisons before the variable is set. There's a reference a variable that looks like it is going to be used with WindowsScriptHost, but I don't see it referenced or initialized.

From what I can tsee, it looks like someone is trying to move subfolders within a folder, based on whether the folder name starts the same as something and the next X characters are less the the Current Date.

Unless the code you posted is bits and pieces of the whole code, it's not coded right.

I don't know why the MoveFolder method won't work for you. Does the MoveFile method work?
 
Unfortunately the whole piece of code is at work, which I am no longer at, and won't be for another two days. Bear with me, and I will post it for you then.

As for the gist of what you've put, you're pretty much right.

I have no idea why MoveFolder won't work, but I doubt MoveFile will work either. I can't remember the error I get when I try to do the MoveFolder, but I will also get you that error at the same time.

Cheers,


xim_
 
Here is the complete code:

Option Explicit

dim WshNetwork
dim strServerName
dim strDay, strMonth
dim intSlash1, intSlash2, strNow
Dim objFSO, objMainFolder, objFolders, objFolder, strCurrentDate, objFiles, objFile, strNewFileName, strFolderName, intPos, strCopiedFolder, tmpFolder

Const BGOFolderPrefix = &quot;Optimization&quot;
Const BGOArchiveDir = &quot;\\wsapp0202\d$\xim\&quot;

Set WshNetwork = WScript.CreateObject(&quot;WScript.Network&quot;)

strServerName = WshNetwork.ComputerName
strNow = now()

intSlash1 = instr(strNow,&quot;/&quot;)
intSlash2 = instr(intSlash1 + 1,strNow,&quot;/&quot;)
strday = mid(strNow,1,intSlash1 - 1)

If len(strDay) = 1 Then
strDay = &quot;0&quot; & strDay
End If

strmonth = mid(strNow,intSlash1 + 1 ,intSlash2 - intSlash1 - 1)

If len(strMonth) = 1 Then
strMonth = &quot;0&quot; & strMonth
End If

strCurrentDate = Mid(strNow, intSlash2 +1 , 4) & &quot;_&quot; & strMonth & &quot;_&quot; & strDay
strCopiedFolder = &quot;&quot;

Set objFSO = CreateObject(&quot;Scripting.FileSystemOBJECT&quot;)

If not objFSO.FolderExists(BGOArchiveDir & strServerName) Then
set tmpFolder = objfso.CreateFolder(BGOArchiveDir & strServerName)
End If

Set objMainFolder = objFSO.GetFolder(&quot;D:\logmovetest&quot;)
Set objFolders = objMainFolder.SubFolders

For Each objFolder In objFolders

If Left(objFolder.Name, Len(BGOFolderPrefix)) = BGOFolderPrefix Then

strFolderName = BGOArchiveDir & strServerName

If Mid(objFolder.Name, Len(BGOFolderPrefix)+1, Len(strCurrentDate)) < strCurrentDate Then
wscript.echo BGOArchiveDir & strServerName & &quot;\&quot;
Call objFolder.Move(BGOArchiveDir & strServerName & &quot;\&quot;)
'Call objFolder.Delete
End If
End If
Next




Let me know if you can do anything with it...

Cheers,


Danny
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top