?
Solved

script to move files

Posted on 2011-04-20
11
Medium Priority
?
411 Views
Last Modified: 2012-05-11
Here's the situation.  On a Win 2K3 server, I have software monitoring a folder.  It checks every two seconds for new subfolders - I cannot change the scan intervals.  When it finds new subfolders, it processes them immediately; however, if the subfolders have an incomplete set of files,they do not process properly.  The data is being transferred using DeltaCopy from a remote site.  During the transfer, DeltaCopy names the files currently being transferred as .filename.ext.abcd  (abcd is a random set of letters). When the file has completed it is renamed with the original filename.ext.  I need to have a recursive scan of each subfolder until all files in the subfolder are completely downloaded and then move that subfolder to the monitored folder.  

Does anyone have a script up there sleeve that will work for this situation?

0
Comment
Question by:wellnecessities
  • 5
  • 3
  • 3
11 Comments
 
LVL 59

Expert Comment

by:Bill Prew
ID: 35437587
Will all the files normally be of the form:

xxxxxxxxxxx.xxxxx

or could they also be things like:

xxxxxxxxxxx.xxxxxxxxx.xxxxx
xxxxxxxxxxxxxxxxx

~bp
0
 

Author Comment

by:wellnecessities
ID: 35437627
The partial files always have the name format of .filename.ext.xxxx so they will have a "." preceding the file name. I figured either that or the 4 letter extension would be the elements to look for.  
0
 
LVL 59

Expert Comment

by:Bill Prew
ID: 35437645
Right, but if a filename could be something like

.filename

then we can't just look for files with an extension that is 4 letters, since that would think

.filename.docx

was a temp file.

~bp
0
Creating Active Directory Users from a Text File

If your organization has a need to mass-create AD user accounts, watch this video to see how its done without the need for scripting or other unnecessary complexities.

 
LVL 12

Expert Comment

by:prashanthd
ID: 35437648
Try the following

regards
Prashanth
Set objFSO = CreateObject("Scripting.FileSystemObject")
objStartFolder = "c:\download\"
objMoveFolder="c:\monitored\"

On Error Resume Next
status=True
Do While status=True
    Set objFolder = objFSO.GetFolder(objStartFolder)
    ctr=0
    For Each Subfolder In objFolder.SubFolders
        WScript.Echo Subfolder.Path
        Set objFolder = objFSO.GetFolder(Subfolder.Path)
        Set colFiles = objFolder.Files
        move_status=True
        For Each objFile In colFiles
            If InStr(LCase(objfile.Name),".ext.")>0  Then
                move_status=False
                Exit For
            End If
        Next
        If move_status=True Then
            objfso.MoveFolder subfolder.Path objmovefolder 
        End If
        ctr=ctr+1
    Next
    If ctr=0 Then
        status=False
   	End If
Loop

Open in new window

0
 

Author Comment

by:wellnecessities
ID: 35440846
Bill: Thanks for that thought and THANK YOU M$ FOR CHANGING THINGS!  I hadn't though about the four letter ext they've added.
Prash: Thanks for the code.  I have a monkey wrench to throw in now.  The file extensions differ within the same folder i.e. they have ".rsl", ".xml", ".NNN" (where N is sequential integers from 001 - 999) .

The code works great when all files have the same extension.  
0
 
LVL 12

Accepted Solution

by:
prashanthd earned 2000 total points
ID: 35441363
Try the following...

regards
Prashanth
Set objFSO = CreateObject("Scripting.FileSystemObject")
objStartFolder = "c:\download\"
objMoveFolder="c:\monitored\"

On Error Resume Next
status=True
Do While status=True
    Set objFolder = objFSO.GetFolder(objStartFolder)
    ctr=0
    For Each Subfolder In objFolder.SubFolders
        WScript.Echo Subfolder.Path
        Set objFolder = objFSO.GetFolder(Subfolder.Path)
        Set colFiles = objFolder.Files
        move_status=True
        For Each objFile In colFiles
            If Left(Right(objFile.Name,5),1)="."  Then
                move_status=False
                Exit For
            End If
        Next
        If move_status=True Then
            objfso.MoveFolder subfolder.Path objmovefolder 
        End If
        ctr=ctr+1
    Next
    If ctr=0 Then
        status=False
   	End If
Loop

Open in new window

0
 

Author Comment

by:wellnecessities
ID: 35441824
I get an error on line 22 char 46 "expected end of statement"

0
 
LVL 59

Expert Comment

by:Bill Prew
ID: 35445408
I can't speak to the rest of the code, but I suspect that error is due to:

objfso.MoveFolder subfolder.Path objmovefolder

needing to be:

objfso.MoveFolder subfolder.Path, objmovefolder

~bp
0
 
LVL 59

Expert Comment

by:Bill Prew
ID: 35445423
@wellnecessities

The latest code offered by prashanthd will not work as desired if there is a file with a legitimate 4 character extension, like ".docx".  I'm not criticising his work, but I wouldn't think that was acceptable.  Before I work an alternate approach, is that acceptable, or no?

==> The partial files always have the name format of .filename.ext.xxxx so they will have a "."
==> preceding the file name. I figured either that or the 4 letter extension would be the elements to look
==> for.  

So would it make sense to check for any files with THREE dots in there name, as an indicator of still being processed?

Also, do all of the files get created in the staging folder first, before they start getting processed and renamed without the temporary 4 character extension?

~bp
0
 
LVL 12

Expert Comment

by:prashanthd
ID: 35445815
@bill..thanks for the correction.

@wellnecessities

My code will work only if the file extension is 3 letter.

regards
Prashanth
0
 
LVL 59

Expert Comment

by:Bill Prew
ID: 35451651
So I get that the main folder being monitored will have subfolders underneath it where the files show up.  Will those also have subfolders, or is there just one level of subfolders to be processed?

Also, let's say we have the following:

c:\monitored-folder
c:\monitored-folder\sub-folder-1
c:\monitored-folder\sub-folder-2

If all the files in sub-folder-1 no longer have the 4 character temporary extension, can that folder be copied, even if there are still files in sub-folder-2 that have the 4 character extension?  Or can there be no files in that state across all subfolders when the copy occurs?

~bp
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

A project that enables an administrator to perform actions within a user session context not just at the time of login but any time later on day(s) or week(s) later.
Measuring Server's processing rate with a simple powershell command. The differences in processing rate also was recorded in different use-cases, when a server in free and busy states.
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an antispam), the adminiā€¦
Loops Section Overview

830 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question