Copy specific folders to new location - c#

Firs of, i am new here and hope you can help.
I am a systen engeneer and have to move (copy) 400 out of 500 folder's in a directory.
The folder names are uniek GUID {f199a57f-fbee-411b-a70e-32619f87e6aa} naming
Is there a VB or C# way to have the user input the 400 names of the folders that need to be copyd and let the scrip search them and copy the folders too a new location?
Thank you for your help...
Regards,
Wim
Wat i tried:
I tried this, but noting hapens :-(
Sub CopySomeFolder()
Dim FSO, sourceFolder, currentFile, filesInSourceFolder
Dim strSourceFolderPath
Dim strDestinationFolderPath
Dim strUserInput
Set FSO = CreateObject("Scripting.FileSystemObject")
' Figure out which folder to copy from where to where
strUserInput = InputBox("Please enter name of file to copy.")
strSourceFolderPath = "M:\"
strDestinationFolderPath = "M:\"
Set sourceFolder = FSO.GetFolder(strSourceFolderPath)
Set filesInSourceFolder = sourceFolder.Files
' Look at all folders in source folder. If name matches,
' copy to destination folder.
For Each currentFile In filesInSourceFolder
If currentFile.Name = strUserInput Then
currentFile.Copy (FSO.BuildPath(strDestinationFolderPath, _
currentFile.Name))
End If
Next
End Sub

Decide whether you need to copy folders or files
Don't be a sadist - asking a user to type 400 GUIDs into an InputBox!
Use dir to create the list of all 500 folder in a text file
Ask your asistent to delete the 100 not to be copied
Use a .bat or .vbs to copy the 400 remaining folders

This is simple to do. Example script that will read a text file and move them is as fallows;
Const ForReading = 1
Const list = "c:\list_of_folders.txt"
Const destination = "c:\temp\"
Dim fso : Set fso = CreateObject("Scripting.FileSystemObject")
Dim folders : Set folders = fso.OpenTextFile(list, ForReading)
Dim folder
Do Until folders.AtEndOfStream
folder_loc = folders.ReadLine
If fso.FolderExists(folder_loc) Then
Set folder = fso.GetFolder(folder_loc)
folder.move(destination)
End If
Loop
Wscript.echo "Operation completed."
The list_of_folders.txt needs to have full paths.

First of, thank's for all your help...
We ended up using both answers. We got the DB admins to give us the GUIS's that have to be moved, slapt that in too 4 txt doc's, 1 for everyday of the migration. We used copy, not move for if something goes wrong.... here is the script i made...
Dim arrFileLines()
i = 0
set filesys = CreateObject("Scripting.FileSystemObject")
Set objFSO = CreateObject("Scripting.FileSystemObject")
strUserInput = InputBox ("Pathe to TXT file containing the folder names: " & _
chr(10) & chr(10) & "(i.e. C:\Program Files or " & _
"\\Servername\C$\Program Files)")
strUserInputFrom = InputBox("Enter the directory path to the folders u want to copy: " & _
chr(10) & chr(10) & "(i.e. C:\Program Files or " & _
"\\Servername\C$\Program Files)")
strUserInputTo = InputBox("Enter the destination folder: " & _
chr(10) & chr(10) & "(i.e. C:\Program Files or " & _
"\\Servername\C$\Program Files)")
Set objFile = objFSO.OpenTextFile(strUserInput, 1)
Do Until objFile.AtEndOfStream
Redim Preserve arrFileLines(i)
arrFileLines(i) = objFile.ReadLine
i = i + 1
Loop
objFile.Close
For l = Ubound(arrFileLines) to LBound(arrFileLines) Step -1
Wscript.echo strUserInputFrom&"\"&arrFileLines(l) &" copy to " & strUserInputTo&"\"
filesys.CopyFolder strUserInputFrom&"\"&arrFileLines(l), strUserInputTo&"\"
Next
Please let me know if there is a better way, i like to learn :-)
Thanks

Related

Translating "Bodies to Parts" Macro in CATIA V5 from VBA to C#

I'm trying to convert the Bodies from Parts to Parts in a Product in CATIA. I found a VBA script that works fine, but I have to translate it to C#.
The VBA script is the following:
Sub GreateProductsFromBodies_SelectAllBodies()
On Error Resume Next
Set CATIA = GetObject(, "CATIA.Application")
'Declare variables
Dim oPartDoc As PartDocument
Dim oPart As Part
Dim oProductDoc As ProductDocument
Dim oProduct As Product
'Create a new ProductDoc and rename it's PartNumber equals to Partdoc's PartNumber
Set oPartDoc = CATIA.ActiveDocument
Set oProductDoc = CATIA.Documents.Add("Product")
oProductDoc.Product.PartNumber = oPartDoc.Product.PartNumber
'Arrange windows use "Title Vertically" ,then active window contain Partdoc
CATIA.Windows.Arrange catArrangeTiledVertical
CATIA.Windows.Item(1).Activate
'Check the Body's name use "For ... Next"loop . If Body's name duplicate,then rename.
Dim j As Integer, k As Integer
For j = 1 To oPartDoc.Part.Bodies.Count
For k = 1 To oPartDoc.Part.Bodies.Count
If oPartDoc.Part.Bodies.Item(j).name = oPartDoc.Part.Bodies.Item(k).name And j <> k Then
oPartDoc.Part.Bodies.Item(j).name = oPartDoc.Part.Bodies.Item(k).name & "_Rename_" & j
End If
Next
Next
'Copy Bodies from PartDocument
Dim i As Integer, ProductPN As String, FinalProductPN As String
For i = 1 To oPartDoc.Part.Bodies.Count
With oPartDoc.Selection
.Clear
.Add oPartDoc.Part.Bodies.Item(i)
.Copy
.Clear
End With
'Modify the Product's PartNumber,replace "\" and "."to "_" ,then delete Space
ProductPN = oPartDoc.Part.Bodies.Item(i).name
If Right(ProductPN, 1) = "\" Then
ProductPN = Left(ProductPN, Len(ProductPN) - 1)
End If
FinalProductPN = Replace(Replace(Replace(ProductPN, "\", "_"), ".", "_"), " ", "") 'Replace "\" and "."to "_",Delete Space
'Paste Body in Product's Part as Result
Set oProduct = oProductDoc.Product.Products.AddNewComponent("Part", FinalProductPN) 'Add Part
With oProductDoc.Selection
.Clear
.Add oProductDoc.Product.Products.Item(i).ReferenceProduct.Parent.Part
.PasteSpecial "CATPrtResultWithOutLink"
.Clear
End With
oProductDoc.Product.Products.Item(i).ReferenceProduct.Parent.Part.Update
Next
'Use Msgbox to echo the complete flag
MsgBox "All the select Bodies had been created as a PartDocument successfully !" & Chr(13) & _
">>> The Partdocument's Bodies's count : " & oPartDoc.Part.Bodies.Count & Chr(13) & _
">>> The ProductDocument's PartDocument's count : " & oProductDoc.Product.Products.Count, _
vbOKOnly + vbInformation, "#LSY >>> CATIAVBAMacro of Part to Product >>> Run Result"
End Sub
I translated every line, except the line:
oProductDoc.Selection.Add oProductDoc.Product.Products.Item(i).ReferenceProduct.Parent.Part
I found no corresponding property in C#, cause the last property Part is missing in C#.
I wrote:
oProductDoc.Selection.Add(oProductDoc.Product.Products.Item(i).ReferenceProduct.Parent.??????);
I'm very thankfull for every help!
I solved it, if someone else is in this situation:
I had to cast the line as PartDocument, whish gives me the needed .Part Property!
Before the selection:
PartDocument partDoc = oProductDoc.Product.Products.Item(i).ReferenceProduct.Parent as PartDocument;
And in the required line:
oProductDoc.Selection.Add(partDoc.Part);

Copy document content (including formatting and page format) to another using Word Interop in c# with 100% fidelity

I want to copy the content of a document created by the user to an existing document. The existing document content must be an exact mirror to the document created by the user.
I cannot simply copy the file using System.IO or saving a copy of the document created by the user using SaveAs methods in Word Interop. This is because the existing document is a document that is generated from a webserver and has VBA modules for uploading it back to the server.
The document generated by the webserver (existing document) is a Word 2003 document, but the document created by the user is either a Word 2003 document or Word 2007+.
Having these limitations in mind, I first created the following method:
string tempsave = //location of user created document;
string savelocation = //location of existing document;
Word.Application objWordOpen = new Word.Application();
Document doclocal = objWordOpen.Documents.Open(tempsave);
Document d1 = objWordOpen.Documents.Open(savelocation);
Word.Range oRange = doclocal.Content;
oRange.Copy();
d1.Activate();
d1.UpdateStyles();
d1.ActiveWindow.Selection.WholeStory();
d1.ActiveWindow.Selection.PasteAndFormat(Word.WdRecoveryType.wdFormatOriginalFormatting);
This is generally working. However, the tables are messed up.
Also, if there is a Page Break, the output is different.
The user created document:
The output - existing document:
Also, at the end of the document a paragraph mark is added, as follows:
The user created document:
The output - existing document:
The page format is also messed up, the output having mirror margins set up.
The user created document:
The output - existing document:
I have also tried using Range.Insert() method and setting the range without copying as described here https://stackoverflow.com/a/54500605/10468231, but I am still having these issues.
I have also tried adding the VBA modules to the document, but there are also Document Variables and other custom properties and I don't want to mess with the file being uploaded to the server.
How do I handle these issues? Both the documents are based on Normal template.
I am open to another suggestion regarding this topic, but I know that .doc files are not handled as easily as .docx format, this is why I think I am stuck with COM Interop.
Thank you.
UPDATE
Based on Macropod code posted by Charles Kenyon, I have managed to copy more of the formatting from the source to target. Still, there is the difference at the page break - the paragraph mark is places on the new page, instead on the same page.
Also, the text is slightly larger, even though the Font Size is the same.
Word.Range oRange;
oRange = Source.Content;
Target.Content.FormattedText = oRange.FormattedText;
LayoutTransfer(Source, Target);
LayoutTransfer method:
private void LayoutTransfer(Document source, Document target)
{
float sPageHght;
float sPageWdth;
float sHeaderDist;
float sFooterDist;
float sTMargin;
float sBMargin;
float sLMargin;
float sRMargin;
float sGutter;
WdGutterStyle sGutterPos;
WdPaperSize lPaperSize;
WdGutterStyleOld lGutterStyle;
int lMirrorMargins;
WdVerticalAlignment lVerticalAlignment;
WdSectionStart lScnStart;
WdSectionDirection lScnDir;
int lOddEvenHdFt;
int lDiffFirstHdFt;
bool bTwoPagesOnOne;
bool bBkFldPrnt;
int bBkFldPrnShts;
bool bBkFldRevPrnt;
WdOrientation lOrientation;
foreach (Word.Section section in source.Sections)
{
lPaperSize = section.PageSetup.PaperSize;
lGutterStyle = section.PageSetup.GutterStyle;
lOrientation = section.PageSetup.Orientation;
lMirrorMargins = section.PageSetup.MirrorMargins;
lScnStart = section.PageSetup.SectionStart;
lScnDir = section.PageSetup.SectionDirection;
lOddEvenHdFt = section.PageSetup.OddAndEvenPagesHeaderFooter;
lDiffFirstHdFt = section.PageSetup.DifferentFirstPageHeaderFooter;
lVerticalAlignment = section.PageSetup.VerticalAlignment;
sPageHght = section.PageSetup.PageHeight;
sPageWdth = section.PageSetup.PageWidth;
sTMargin = section.PageSetup.TopMargin;
sBMargin = section.PageSetup.BottomMargin;
sLMargin = section.PageSetup.LeftMargin;
sRMargin = section.PageSetup.RightMargin;
sGutter = section.PageSetup.Gutter;
sGutterPos = section.PageSetup.GutterPos;
sHeaderDist = section.PageSetup.HeaderDistance;
sFooterDist = section.PageSetup.FooterDistance;
bTwoPagesOnOne = section.PageSetup.TwoPagesOnOne;
bBkFldPrnt = section.PageSetup.BookFoldPrinting;
bBkFldPrnShts = section.PageSetup.BookFoldPrintingSheets;
bBkFldRevPrnt = section.PageSetup.BookFoldRevPrinting;
var index = section.Index;
target.Sections[index].PageSetup.PaperSize = lPaperSize;
target.Sections[index].PageSetup.GutterStyle = lGutterStyle;
target.Sections[index].PageSetup.Orientation = lOrientation;
target.Sections[index].PageSetup.MirrorMargins = lMirrorMargins;
target.Sections[index].PageSetup.SectionStart = lScnStart;
target.Sections[index].PageSetup.SectionDirection = lScnDir;
target.Sections[index].PageSetup.OddAndEvenPagesHeaderFooter = lOddEvenHdFt;
target.Sections[index].PageSetup.DifferentFirstPageHeaderFooter = lDiffFirstHdFt;
target.Sections[index].PageSetup.VerticalAlignment = lVerticalAlignment;
target.Sections[index].PageSetup.PageHeight = sPageHght;
target.Sections[index].PageSetup.PageWidth = sPageWdth;
target.Sections[index].PageSetup.TopMargin = sTMargin;
target.Sections[index].PageSetup.BottomMargin = sBMargin;
target.Sections[index].PageSetup.LeftMargin = sLMargin;
target.Sections[index].PageSetup.RightMargin = sRMargin;
target.Sections[index].PageSetup.Gutter = sGutter;
target.Sections[index].PageSetup.GutterPos = sGutterPos;
target.Sections[index].PageSetup.HeaderDistance = sHeaderDist;
target.Sections[index].PageSetup.FooterDistance = sFooterDist;
target.Sections[index].PageSetup.TwoPagesOnOne = bTwoPagesOnOne;
target.Sections[index].PageSetup.BookFoldPrinting = bBkFldPrnt;
target.Sections[index].PageSetup.BookFoldPrintingSheets = bBkFldPrnShts;
target.Sections[index].PageSetup.BookFoldRevPrinting = bBkFldRevPrnt;
}
}
UPDATE 2
Actually, the page break not remaining in line with paragraph format is not an issue of copying fidelity, but rather an issue of conversion from .doc to .docx. (https://support.microsoft.com/en-us/help/923183/the-layout-of-a-document-that-contains-a-page-break-may-be-different-i)
Maybe someone thought of a method to overcome this.
The following code by Paul Edstein (macropod) may assist you. It will at least give you an idea of the complexities you are facing.
' ============================================================================================================
' KEEP NEXT THREE TOGETHER
' ============================================================================================================
'
Sub CombineDocuments()
' Paul Edstein
' https://www.msofficeforums.com/word-vba/43339-combine-multiple-word-documents.html
'
' Users occasionally need to combine multiple documents that may of may not have the same page layouts,
' Style definitions, and so on. Consequently, combining multiple documents is often rather more complex than
' simply copying & pasting content from one document to another. Problems arise when the documents have
' different page layouts, headers, footers, page numbering, bookmarks & cross-references,
' Tables of Contents, Indexes, etc., etc., and especially when those documents have used the same Style
' names with different definitions.
'
' The following Word macro (for Windows PCs only) handles the more common issues that arise when combining
' documents; it does not attempt to resolve conflicts with paragraph auto-numbering,
' document -vs- section page numbering in 'page x of y' numbering schemes, Tables of Contents or Indexing issues.
' Neither does it attempt to deal with the effects on footnote or endnote numbering & positioning or with the
' consequences of duplicated bookmarks (only one of which can exist in the merged document) and any corresponding
' cross-references.
'
' The macro includes a folder browser. Simply select the folder to process and all documents in that folder
' will be combined into the currently-active document. Word's .doc, .docx, and .docm formats will all be processed,
' even if different formats exist in the selected folder.
'
Application.ScreenUpdating = False
Dim strFolder As String, strFile As String, strTgt As String
Dim wdDocTgt As Document, wdDocSrc As Document, HdFt As HeaderFooter
strFolder = GetFolder: If strFolder = "" Then Exit Sub
Set wdDocTgt = ActiveDocument: strTgt = ActiveDocument.fullname
strFile = Dir(strFolder & "\*.doc", vbNormal)
While strFile <> ""
If strFolder & strFile <> strTgt Then
Set wdDocSrc = Documents.Open(FileName:=strFolder & "\" & strFile, AddToRecentFiles:=False, Visible:=False)
With wdDocTgt
.Characters.Last.InsertBefore vbCr
.Characters.Last.InsertBreak (wdSectionBreakNextPage)
With .Sections.Last
For Each HdFt In .Headers
With HdFt
.LinkToPrevious = False
.range.Text = vbNullString
.PageNumbers.RestartNumberingAtSection = True
.PageNumbers.StartingNumber = wdDocSrc.Sections.First.Headers(HdFt.Index).PageNumbers.StartingNumber
End With
Next
For Each HdFt In .Footers
With HdFt
.LinkToPrevious = False
.range.Text = vbNullString
.PageNumbers.RestartNumberingAtSection = True
.PageNumbers.StartingNumber = wdDocSrc.Sections.First.Headers(HdFt.Index).PageNumbers.StartingNumber
End With
Next
End With
Call LayoutTransfer(wdDocTgt, wdDocSrc)
.range.Characters.Last.FormattedText = wdDocSrc.range.FormattedText
With .Sections.Last
For Each HdFt In .Headers
With HdFt
.range.FormattedText = wdDocSrc.Sections.Last.Headers(.Index).range.FormattedText
.range.Characters.Last.Delete
End With
Next
For Each HdFt In .Footers
With HdFt
.range.FormattedText = wdDocSrc.Sections.Last.Footers(.Index).range.FormattedText
.range.Characters.Last.Delete
End With
Next
End With
End With
wdDocSrc.Close SaveChanges:=False
End If
strFile = Dir()
Wend
With wdDocTgt
' Save & close the combined document
.SaveAs FileName:=strFolder & "Forms.docx", FileFormat:=wdFormatXMLDocument, AddToRecentFiles:=False
' and/or:
.SaveAs FileName:=strFolder & "Forms.pdf", FileFormat:=wdFormatPDF, AddToRecentFiles:=False
.Close SaveChanges:=False
End With
Set wdDocSrc = Nothing: Set wdDocTgt = Nothing
Application.ScreenUpdating = True
End Sub
' ============================================================================================================
Private Function GetFolder() As String
' used by CombineDocument macro by Paul Edstein, keep together in same module
' https://www.msofficeforums.com/word-vba/43339-combine-multiple-word-documents.html
Dim oFolder As Object
GetFolder = ""
Set oFolder = CreateObject("Shell.Application").BrowseForFolder(0, "Choose a folder", 0)
If (Not oFolder Is Nothing) Then GetFolder = oFolder.Items.Item.Path
Set oFolder = Nothing
End Function
Sub LayoutTransfer(wdDocTgt As Document, wdDocSrc As Document)
' works with previous Combine Documents macro from Paul Edstein, keep together
' https://www.msofficeforums.com/word-vba/43339-combine-multiple-word-documents.html
'
Dim sPageHght As Single, sPageWdth As Single
Dim sHeaderDist As Single, sFooterDist As Single
Dim sTMargin As Single, sBMargin As Single
Dim sLMargin As Single, sRMargin As Single
Dim sGutter As Single, sGutterPos As Single
Dim lPaperSize As Long, lGutterStyle As Long
Dim lMirrorMargins As Long, lVerticalAlignment As Long
Dim lScnStart As Long, lScnDir As Long
Dim lOddEvenHdFt As Long, lDiffFirstHdFt As Long
Dim bTwoPagesOnOne As Boolean, bBkFldPrnt As Boolean
Dim bBkFldPrnShts As Boolean, bBkFldRevPrnt As Boolean
Dim lOrientation As Long
With wdDocSrc.Sections.Last.PageSetup
lPaperSize = .PaperSize
lGutterStyle = .GutterStyle
lOrientation = .Orientation
lMirrorMargins = .MirrorMargins
lScnStart = .SectionStart
lScnDir = .SectionDirection
lOddEvenHdFt = .OddAndEvenPagesHeaderFooter
lDiffFirstHdFt = .DifferentFirstPageHeaderFooter
lVerticalAlignment = .VerticalAlignment
sPageHght = .PageHeight
sPageWdth = .PageWidth
sTMargin = .TopMargin
sBMargin = .BottomMargin
sLMargin = .LeftMargin
sRMargin = .RightMargin
sGutter = .Gutter
sGutterPos = .GutterPos
sHeaderDist = .HeaderDistance
sFooterDist = .FooterDistance
bTwoPagesOnOne = .TwoPagesOnOne
bBkFldPrnt = .BookFoldPrinting
bBkFldPrnShts = .BookFoldPrintingSheets
bBkFldRevPrnt = .BookFoldRevPrinting
End With
With wdDocTgt.Sections.Last.PageSetup
.GutterStyle = lGutterStyle
.MirrorMargins = lMirrorMargins
.SectionStart = lScnStart
.SectionDirection = lScnDir
.OddAndEvenPagesHeaderFooter = lOddEvenHdFt
.DifferentFirstPageHeaderFooter = lDiffFirstHdFt
.VerticalAlignment = lVerticalAlignment
.PageHeight = sPageHght
.PageWidth = sPageWdth
.TopMargin = sTMargin
.BottomMargin = sBMargin
.LeftMargin = sLMargin
.RightMargin = sRMargin
.Gutter = sGutter
.GutterPos = sGutterPos
.HeaderDistance = sHeaderDist
.FooterDistance = sFooterDist
.TwoPagesOnOne = bTwoPagesOnOne
.BookFoldPrinting = bBkFldPrnt
.BookFoldPrintingSheets = bBkFldPrnShts
.BookFoldRevPrinting = bBkFldRevPrnt
.PaperSize = lPaperSize
.Orientation = lOrientation
End With
End Sub
' ============================================================================================================
I used a Template and copied it several times into a new Word Document after editing it.
It worked like this
Word.Range rng = wordDocTarget.Content;
rng.Collapse(Word.WdCollapseDirection.wdCollapseEnd)
rng.FormattedText = wordDocSource.Content.FormattedText
An alternative could also be to insert a whole file to a range / document
rng = wordDoc.Range
rng.Collapse(Word.WdCollapseDirection.wdCollapseEnd)
rng.InsertFile(filepath)

Batch takes a part from the file name and create a folders with this part

I have files with names like this:
414_gtmlk_videos_Mas_147852_hty1147.xls
414_gtmlk_videos_Mas_P147852_hty1147.txt
I want to creat a job to check the filenames and take the part after Mas in the file name (147852-P147852)
and create a folders with this part name (the folder name should be: 147852-P147852).
And finally move each file to his folder.
Batch takes a part from the file name and create a folders with this part i have files with names like this:
414_gtmlk_videos_Mas_147852_hty1147.xls
414_gtmlk_videos_Mas_P147852_hty1147.txt (the folder name will be
here:147852-P147852)
Here's a way to do this with a Batch Script since you have this tagged as a batch-file in your question. Just set your source directory accordingly and the rest should just work based on the detail you provided and my understanding.
I used a simple batch FOR /F loop incorporating MD with IF conditions. I used the underbar characters as the delimiter and set the token to 5 to make this work.
#ECHO ON
SET Src=C:\Folder\Path
FOR /F "TOKENS=5 DELIMS=_" %%F IN ('DIR /B /A-D "%Src%\*.txt"') DO (
IF NOT EXIST "%Src%\%%~F-P%%~F" MD "%Src%\%%~F-P%%~F"
IF EXIST "%Src%\*%%~F*P%%~F*.txt" MOVE /Y "%Src%\*%%~F*P%%~F*.txt" "%Src%\%%~F-P%%~F"
)
GOTO EOF
Further Resources
FOR /F
IF
MD
FOR /?
delims=xxx - specifies a delimiter set. This replaces the
default delimiter set of space and tab.
tokens=x,y,m-n - specifies which tokens from each line are to
be passed to the for body for each iteration.
This will cause additional variable names to
be allocated. The m-n form is a range,
specifying the mth through the nth tokens. If
the last character in the tokens= string is an
asterisk, then an additional variable is
allocated and receives the remaining text on
the line after the last token parsed.
I have some C# code below. The first part does the following:
Gets paths
Get names of file
Modify full paths to get "147852" part, between __Mas_ and last _
string pathToGetFile = #"C:\\";
string[] filePaths = System.IO.Directory.GetFiles(pathToGetFile +#"\\", "*_Mas_*");
string[] fullName = new string[filePaths.Length];
for (int i = 0; i < filePaths.Length; i++)
{
fullName[i] = filePaths[i].Substring(filePaths[i].LastIndexOf("\\") + 1);
filePaths[i] = filePaths[i].Substring(filePaths[i].LastIndexOf("_Mas_") + 5);
int l = filePaths[i].IndexOf("_");
filePaths[i] = filePaths[i].Substring(0, l);
Now you can create folders with yours names
filePaths is now like that: 147852, P147852
if (!Directory.Exists(#"C:\" + filePaths[i]))
System.IO.Directory.CreateDirectory(#"C:\" + filePaths[i]);
}
Now just move files to new directories
for (int i = 0; i < filePaths.Length; i++)
{
string sourceFile = System.IO.Path.Combine(pathToGetFile, fullName[i]);
string destFile = System.IO.Path.Combine(#"C:\" + filePaths[i], #"C:\" + filePaths[i] + "\\" + fullName[i]);
File.Copy(sourceFile,destFile,true);
}
Now, what happens
Files:
C:\414_gtmlk_videos_Mas_147852_hty1147.xls
C:\414_gtmlk_videos_Mas_P147852_hty1147.txt
They will be copied according to the:
C:\147852\
C:\P147852\

Auto Increment version of setup project

I need to increment version of an installer on every successful build. I have added a VBscript file and called it from a pre-build event. But am not able to get the actual result. my script is as under:
set a = wscript.arguments
if a.count = 0 then wscript.quit 1
'read and backup project file
Set fso = CreateObject("Scripting.FileSystemObject")
Set f = fso.OpenTextFile(a(0))
s = f.ReadAll
f.Close
fbak = a(0) & ".bak"
if fso.fileexists(fbak) then fso.deletefile fbak
fso.movefile a(0), fbak
'find, increment and replace version number
set re = new regexp
re.global = true
re.pattern = "(""ProductVersion"" = ""8:)(\d+(\.\d+)+)"""
set m = re.execute(s)
v = m(0).submatches(1)
v1 = split(v, ".")
v1(ubound(v1)) = v1(ubound(v1)) + 1
vnew = join(v1, ".")
'msgbox v & " --> " & vnew
s = re.replace(s, "$1" & vnew & """")
'replace ProductCode
re.pattern = "(""ProductCode"" = ""8:)(\{.+\})"""
guid = CreateObject("Scriptlet.TypeLib").Guid
guid = left(guid, len(guid) - 2)
s = re.replace(s, "$1" & guid & """")
'replace PackageCode
re.pattern = "(""PackageCode"" = ""8:)(\{.+\})"""
guid = CreateObject("Scriptlet.TypeLib").Guid
guid = left(guid, len(guid) - 2)
s = re.replace(s, "$1" & guid & """")
'write project file
fnew = a(0)
set f = fso.CreateTextfile(fnew, true)
f.write(s)
f.close
and my Pre-build Event is as C:\Projects\VersionProject\myscript.vbs "$(ProjectDir)VersionProject.Installer.vdproj" .Any help appreciated.
You'd need to go into the vdproj file and find the string of the form "ProductVersion" = "8:1.0.0"
and change the string from (say) 1.0.0 to 1.0.1.
However you're likely to get into trouble with updates if that's all you change. Note that when you increment the ProductVersion in the setup project it prompts to change ProductCode, and it will also change the PackageCode of the MSI file. So a safe change of the version involves all those things. For example, if you change only the version and attempt to reinstall the MSI it will fail with "Another version of this product is already installed". If you're unaware of these things, I suggest you familiarise yourself with how ProductCode, UpgradeCode, ProductVersion all interact, together with RemovePreviousVersions, and be aware that every new MSI created needs a new PackageCode.
Take a look at this. This Plugin allows you to set various options for the version number in your project.
And it does exactly what you need, auto increment the version number on each build . I've been using this for years and never had problems with it.
Update:
This Plugin only works if your project has an AssemblyInfo.cs

Outlook/Exchange - how to programmatically export users in distribution list?

How do I export all of the names and email addresses from a distribution list in Outlook using code? I have access to an Outlook 2000 or Outlook 2007 client. Ideally I would like the code to be in C#.
I realize you asked about c#, but the following script from http://www.microsoft.com/technet/scriptcenter/resources/officetips/may05/tips0524.mspx may be of some use.
Const olFolderContacts = 10
Set objOutlook = CreateObject("Outlook.Application")
Set objNamespace = objOutlook.GetNamespace("MAPI")
Set colContacts = objNamespace.GetDefaultFolder(olFolderContacts).Items
intCount = colContacts.Count
For i = 1 To intCount
If TypeName(colContacts.Item(i)) = "DistListItem" Then
Set objDistList = colContacts.Item(i)
Wscript.Echo objDistList.DLName
For j = 1 To objDistList.MemberCount
Wscript.Echo objDistList.GetMember(j).Name & " -- " & _
objDistList.GetMember(j).Address
Next
Wscript.Echo
End If
Next
use outlook component model
http://www.dotnetjunkies.ddj.com/Tutorial/2E1EEEAF-C78A-4A38-A830-AC204B12DF83.dcik

Categories