script to move files

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?

wellnecessitiesAsked:
Who is Participating?
 
prashanthdConnect With a Mentor Commented:
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
 
Bill PrewCommented:
Will all the files normally be of the form:

xxxxxxxxxxx.xxxxx

or could they also be things like:

xxxxxxxxxxx.xxxxxxxxx.xxxxx
xxxxxxxxxxxxxxxxx

~bp
0
 
wellnecessitiesAuthor Commented:
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
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.

 
Bill PrewCommented:
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
 
prashanthdCommented:
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
 
wellnecessitiesAuthor Commented:
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
 
wellnecessitiesAuthor Commented:
I get an error on line 22 char 46 "expected end of statement"

0
 
Bill PrewCommented:
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
 
Bill PrewCommented:
@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
 
prashanthdCommented:
@bill..thanks for the correction.

@wellnecessities

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

regards
Prashanth
0
 
Bill PrewCommented:
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
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.