We help IT Professionals succeed at work.

script to move files

Medium Priority
430 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?

Comment
Watch Question

Bill PrewTest your restores, not your backups...
CERTIFIED EXPERT
Expert of the Year 2019
Top Expert 2016

Commented:
Will all the files normally be of the form:

xxxxxxxxxxx.xxxxx

or could they also be things like:

xxxxxxxxxxx.xxxxxxxxx.xxxxx
xxxxxxxxxxxxxxxxx

~bp

Author

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.  
Bill PrewTest your restores, not your backups...
CERTIFIED EXPERT
Expert of the Year 2019
Top Expert 2016

Commented:
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
Top Expert 2011

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 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

Author

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.  
Top Expert 2011
Commented:
Unlock this solution and get a sample of our free trial.
(No credit card required)
UNLOCK SOLUTION

Author

Commented:
I get an error on line 22 char 46 "expected end of statement"

Bill PrewTest your restores, not your backups...
CERTIFIED EXPERT
Expert of the Year 2019
Top Expert 2016

Commented:
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
Bill PrewTest your restores, not your backups...
CERTIFIED EXPERT
Expert of the Year 2019
Top Expert 2016

Commented:
@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
Top Expert 2011

Commented:
@bill..thanks for the correction.

@wellnecessities

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

regards
Prashanth
Bill PrewTest your restores, not your backups...
CERTIFIED EXPERT
Expert of the Year 2019
Top Expert 2016

Commented:
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
Unlock the solution to this question.
Thanks for using Experts Exchange.

Please provide your email to receive a sample view!

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.