|
|
|||||||||
|
|||||||||
|
|||||||||
| |
||
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
#1
|
|||
|
|||
|
VBScript - Need to distribute files evenly to other folders
I need to distribute files evenly to other folders, from a single directory. Would a VBscript work? If so, can you help me with that?
Thanks. |
|
#2
|
||||
|
||||
|
Sure. But can you be more specific when you say you need to distribute files evenly?
__________________
Click the image if at any point you don't like my decision.Scripting problems? Windows questions? Ask the Windows Guru! |
|
#3
|
|||
|
|||
|
Thanks
Thanks for your reply.
To be more specific, when files are uploaded into the Upload Directory, I'd like the VBscript to evenly distribute the files that it finds in the Upload Directory to the four destination folders, wait X seconds, then repeat the process again. So, if 20 files arrive into the Upload Directory while the script is "sleeping", I will end up with 5 files in each destination folder. Also, we will need to add one more measure, that is a file should not be moved while in the middle of being uploaded. Thanks> i look forward to your reply. |
|
#4
|
|||
|
|||
|
Quote:
Are these specific files with specific names which need to be distributed to one of the four specific folders, or can you just pick any file and send it to any of the four folders ?? |
|
#5
|
|||
|
|||
|
Thanks
Thanks for your reply. Great question.
These are not specific files needing to go to specific folders. I just want the script to distribute the files evenly. So that each of the four destination folders keeps getting files one after another, rather than having one destinaton folder having way more files than the other three destination folders. Someone suggested: "You can use the FileSystemObject to get a list of all the files in folder A.Then use a for loop to iterate through the list. Then use do: <your for loop variable> mod 4 to determine which folder to place it in and move the file. That should evenly distribute the files." But I don't know enough about code to know if this is a viable solution. Any suggestions will be welcomed. Thanks Last edited by chrisj : August 7th, 2008 at 03:03 PM. Reason: more info |
|
#6
|
|||||
|
|||||
|
There are several different solutions to his problem. I might suggest using WMI Events. You can monitor a folder for file creations (i.e. a file upload) then simply move it as soon as it appears. You could simply rotate through each of your folders as a destination.
vb Code:
|
|
#7
|
||||
|
||||
|
On a side note, this script runs indefinitely. You'll have to manually stop it in Task Manager.
|
|
#8
|
|||
|
|||
|
Quote:
Wahooo !! (Sorry, I'm thrilled.) I am thinking along the same lines as the pro !! Nilpo the pro I was wondering how one would monitor the folder, but I was trying to write some code that would rotate through the destination folders as you suggested. I'm not nearly as fast though as I had to go look some things up and do a little trouble shooting. But that's what I was think'n. ![]() |
|
#9
|
|||
|
|||
|
Thank you
Thank you Nilpo for this solution. As I'm not highly skilled in Vbs, I have a few questions, please.
1. Would I save this code as a .vbs file? 2. How do I execute this code on a windows server? 3. How often does it scan the "C:\myfolder" for new files? 4. Is there anything in this code to make sure it doesn't move a file while the file is still in the middle of uploading to "C:\myfolder"? Thank you again. I look forward to your reply. Last edited by chrisj : August 7th, 2008 at 06:09 PM. |
|
#10
|
||||
|
||||
|
Quote:
1. Yes, this should be saved with a .vbs extension. 2. In most cases, this can be executed by simply double-clicking the file. Since it doesn't require user input and doesn't output anything it does not matter which engine (wscript.exe or cscript.exe) it runs in. 3. Technically, it isn't scanning the folder. It monitors the system for new file creations. I'm just limiting the results to those files in a specific folder. Each time a file is created, WMI issues an event. We are monitoring and reacting to those events. The "WITHIN 1" part of the query indicates how often to check for new events. In this case, every 1 second. 4. Since the __InstanceCreationEvent is not fired until a file is completely written, the script should never try to move a file before the upload completes. |
|
#11
|