SSIS variable lookup of existing subfolders by name - variables

I have added a File System Task to an SSIS package for the purpose of creating 7 new subfolders in 24 existing directory subfolders based on a purchase order number.
The first var titled MainFolderPath is to the main system where the existing and new subfolders reside. Additionally I have created a var called FolderName that creates a subfolder with the PO #, and then creates 7 new subfolders in the PO # subfolder.
The part I am struggling with is creating a var that will create the PO and 7 new subfolders in each of the 24 existing subfolders at the same time.
Below is my example:
Var 1: var.MainFolderPath Type – String
\\10.xxx.xx.xxx\sales\subsystem
Var 3: var.FolderName Type – String
+ [#User::var_PurchaseOrder] + "1. Estimates" + "2. Approval" + "3. Legal" + "Processing" + "5. Fulfilment" + "6. Shipping" + "7. Billing"
In the subsystem are 24 existing subfolders, e.g. engines, tires, electrical, etc. The missing var finds those existing subfolders by name for the var.PurchaseOrder to create the new PO # folder and 7 new subfolders.
I hope this structure makes sense, and would appreciate any assistance on how I can make this work.

I would store the names of the folders in a SQL Server table and then use an Execute SQL Task to select these into an object variable (set ResultSet to 'Full result set' and then map the result set to the object variable [set the Result Name to "0"]). (You're essentially putting a single-column result set into an object variable.)
You can then use a Foreach Loop to iterate over this collection using a Foreach ADO Enumerator, mapping each result to a string variable, which can then be included as part of your Create Directory path.
Then simply add the File System Task for Create Directory into the Loop.
I'm not sure this is what you need in its entirety, as you also mentioned 24 sub-directories, but this design pattern will be able to handle any level of complexity in that regard, e.g., you may end up with a Loop (for the 7 folders) within another Loop (for the 24 sub-directories).

Related

Microsoft Project pool resources - count problem

code from learn.microsoft:
Dim R As Long, Names As String
For R = 1 To ActiveProject.Resources.Count
Names = ActiveProject.Resources(R).Name & ", " & Names
Next R
MsgBox Names
Works great when resources are defined in project file.
But when you use resources only in subprojects Resources collection is empty.
Adding new resource manually does not any changes - still count 0.
Using ribbon and Add Resources - counts this resource but other not.
How can I count resources from subprojects in main project?
When I terminate link to subprojects Resources collection count correctly.
Any ideas?
Sebastian, There is no error. I assume the "main project" you reference is a dynamic master. In a master project, subprojects are not part of the master, rather, the master contains pointers to each subproject. So when you run code in a master that loops through the Active.Project, the loop is looking for objects in the master and the master has no resource objects. Here is a modified version of your macro that will show the names of all resources in the resource pool, assuming all subprojects are using the pool. If there is a mixture of subprojects sharing and/or using their own resources the code will need to be modified.
Names As String
Dim Res As Resource
For Each Res In ActiveProject.Subprojects(1).SourceProject.Resources
Names = Res.Name & ", " & Names
Next Res
MsgBox Names
End Sub
The solution given by john-project solves the problem.
Browsing a resource collection with Resources collection remains problematic in one more situation: the project file contains its own resources separated by a blank line inserted with the insert key.
Such a line has an identifier but all fields are empty. Browsing resources using a collection generates an error (e.g. when reading the resource name).

VBA - Finding folder inside a directory and returning the path of that folder

I am using excel vba to make an application that acts as a job card. User will fill in relevant fields, press a button to update a running summary of costs, as well as generate a printable pdf of the job card. I have very limited experience in coding (a semester of java 4 years ago) so i am relatively new to this.
Currently, the application automatically updates the summary file and can open a word template file and fill it in with information from the input fields, so it mostly works. I have realised an issue in the way it is finding the summary files, in that as soon as a folder name does not align with the way i am constructing the folder paths in the app, it will return errors.
At the moment I am going into folders like this:
templatePath = "C:\SERVICE\Card Template.doc"
If cbxType.Text = "Plant" Then
savePath = "C:\SERVICE\0.1 PLANT\" & cbxNo.Text & " - " & txtMakeModel.Text & " " & txtRego.Text & "\0.2 SERVICE SHEETS\"
ElseIf cbxType.Text = "Vehicle" Then
savePath = "C:\SERVICE\0.2 VEHICLES\"
End If
The directory is constructed from text and combo boxes which are populated once the user chooses a type (plant, vehicle, etc.) and then ID, which fills in boxes for model name, registration number, hours etc.
I am after a piece of code that can iterate through a given directory, searching the folder names for a string and returning the path of that folder. Each folder begins with the ID number, so I figure I can search folder names for that but I am not sure how to construct the loop. Any help with this, or alternative ideas would be appreciated. If it isn't too much to ask I'd also like a little bit of an explanation on how it works.

applescript to move files in numeric order

i started a project for a friend, that involved moving large quantities of files into specific folders. i was using automator as I'm handling the project on my mac, however automator does not have a feature to move section of files that are numbered numerically. for instance i will have files that are say "this file 100" and ill have 100 files like that. and then files that say "That file 50" and ill have 200 files like that. the project is splitting these files into there own folder but in section. so ill need "This file" 1-25 in one folder 26-80 in anther and so on. same is true for the "THAT FILES" but there isn't a pattern just the requirement my friend has asked for.
is there a easy way to write a script that could grab 1-25 or any sequel ordering with the same file name? because moving each file one at a time with automator has been taking to long.
thank you so much in advanced
I am not sure tu fully understand your naming convention, but overall , yes, with Applescript, you can move files into folders based on names, eventually adding sequence numbers.
Because I am not sure about your requirements, at least, here are some sample of syntax for main operations :
Get list of files with names containing xxx in folder myFolder :
Tell Application "Finder" to set myList to every file of myFolder whose name contains "xxx"
Then you have to do a repeat / end repeat loop :
Repeat with aFile in myList
-- do something here with aFile : example with name of aFile
end repeat
In that loop you can extract name, parse it, add a counter,...
To move file to new folder, you must use "move" instruction in a tell "Finder" bloc. Instruction "make" can also be used to create new destination folder based on name or root names of files. You must remember that Applescript commands will give error if same file name already exists in destination folder : Finder is able to add "copy" in the name, but you must do it yourself in Applescript.
Last advice if about the number of files to handle. If that number is not so high (less than few hundreds) Applescript is still OK for speed. If your number of files is much higher, then you must use either shell command or, better, a mix of AS and shell commands. The shell commands can be called from AS with a "do shell script". For instance, getting the list of 1000 files from a folder is time consuming with AS, but much quicker with 'ls' command ! Same for a copy. here is an example of copy using shell 'cp' :
do shell script "cp " & quoted form of (POSIX path of (aFile as string)) & " " & quoted form of (POSIX path of DestFolder) & (quoted form of newFileName)
Note : "Posix path" converts the AS file path (Users:myName:Documents:File.txt) into shell path (Users/myName/Documents/File.txt)
I hope it helps.

Retrieve the name of the most recent file in a directory using VB.Net

Let's say I am looking for a file that has a name that starts with GLNO1_
I can have hundreds of files that start with those characters, but I want to retrieve the name of the file that starts with those characters that is the most recently modified.
For example, Lets say I have files GLNo1_1, GLNo1_2, GLNo1_3 etc. up to _1000
and number 556 is the file that was modified the most recent.
In VB.Net, how do I retrieve that file name.
The file extensions are of .csv
You'll have to enumerate the files and pick the last one. That's a job for Linq:
Dim dir = New System.IO.DirectoryInfo("c:\foo\bar")
Dim file = dir.EnumerateFiles("GLNo1_*.csv").
OrderByDescending(Function(f) f.LastWriteTime).
FirstOrDefault()
If file IsNot Nothing Then
Dim path = file.FullName
'' etc..
End If
Never overlook the odds that there will be more than one "last one". If your program hasn't run for a while then more than one file could easily have been added by whatever software generates the *.csv files. You generally need to keep track of the files you've already seen before.

Find a Directory somewhere in Subdirectories

I want to find a directory somewhere among a lot of subdirectories using VB.NET. I have the path of the parent directory (D:\) and I have the name of the subdirectory (X) and I want to find this directory in any of the subdirectories of D:\. In D:\ I have 3 subdirectories (A, B, and C) and I want to find X (the name of the directory) inside A,BorC`. Is it possible to do that with VB.NET?
You can do so using the Directory.EnumerateDirectories method, like this:
For Each i As String In Directory.EnumerateDirectories("D:\", "X", SearchOption.AllDirectories)
Console.WriteLine("Matching Directory: " & i)
Next
Please note that there may be multiple matches. Also, be aware that if the directory tree is very large, it may take a long time for the method to find all of the matches. The key to that working for you is the SearchOption.AllDirectories option. By passing AllDirectories, that causes the method to search the entire directory tree below "D:\". If you omitted that parameter, or passed TopDirectoryOnly, it would only look at the directories that are directly children of "D:\". It would not search through all of the descendants.
If you just want to get an array of all the matching directories, you can alternatively use the Directory.GetDirectories method:
Dim matches() As String = Directory.GetDirectories("D:\", "X", SearchOption.AllDirectories)
If matches.Length > 0 Then
Console.WriteLine("First match: " & matches(0))
End If
The advantage of the EnumerateDirectories method, though, is that, if you only care about the first match, you can exit the loop after processing the first match and skip searching the rest of the directory tree. From the MSDN article:
The EnumerateDirectories and GetDirectories methods differ as follows: When you use EnumerateDirectories, you can start enumerating the collection of names before the whole collection is returned; when you use GetDirectories, you must wait for the whole array of names to be returned before you can access the array. Therefore, when you are working with many files and directories, EnumerateDirectories can be more efficient.
For instance, if you really only cared about the first match, it would be more efficient to do this:
For Each i As String In Directory.EnumerateDirectories("D:\", "X", SearchOption.AllDirectories)
Console.WriteLine("First match: " & i)
Exit For
Next
Or with LINQ:
Dim firstMatch As String = Directory.EnumerateDirectories("D:\", "X", SearchOption.AllDirectories).FirstOrDefault()
If firstMatch IsNot Nothing Then
Console.WriteLine(firstMatch)
End If
Please check the below link
http://msdn.microsoft.com/en-us/library/6ff71z1w%28v=vs.110%29.aspx?cs-save-lang=1&cs-lang=vb#code-snippet-1
it will help you in getting all the directories in the specified path. Regarding the second argument that is the "pattern" try and check pattern as "" and hopefully should return and array of all directories and subdirectories
Then you can just compare/search for the file name in the returned array list using simple for loop and display the result which will show where the file is located