I have around 200 folders which I have to rename. Each folder contain multiple children but I just want to rename the parent. I know it should not have been required in the first place but not I am already in this situation. Renaming them one by one is going to take a long time and I wanted to automate this somehow. Is it possible to do so ?
Just use command line tf.exe. For just 200 renames, you can just call tf.exe 200 times "tf rename foo bar" and then check all changes in.
You can also explore powershell option (there are tfs cmdlets).
Last but not least you can write tfs script - each line is new tf.exe command, but they all share server connection so it's speedier:
script1.tfs
"
rename foo1 bar1
rename foo2 bar2
" and you call tf #script1.tfs (the # is crucial)
Please remember to create workspace that covers all your folders first and easiest is to call tf.exe from folder that is mapped in it.
Good luck!
As suggested by MicahalMa, I used a similar approach and called rename in a loop using c#. Here is my not so elegant code.
private static void RenameDirectories()
{
string path = #"E:\Local\Development\"; //Path for parent directory
List<string> directoriesToRename = new List<string>();
string[] directories = Directory.GetDirectories(path, "*", SearchOption.TopDirectoryOnly);
string tfsTool = #"C:\Program Files (x86)\Microsoft Visual Studio 11.0\Common7\IDE\TF.exe";
string command = "rename";
var p = new Process();
int i = 0;
foreach (string s in directories)
{
i++;
string param = command + " " + path + "\\" + s + " " + path + "\\" + s.Remove(s.Length - 1);
Console.WriteLine("Running " + i + " of" + directoriesToRename.Count());
Console.WriteLine("Renaming started for " + s);
p.StartInfo = new ProcessStartInfo(tfsTool, param)
{
UseShellExecute = false
};
p.Start();
p.WaitForExit();
Console.WriteLine("Renaming Complete for " + s);
Console.WriteLine("-----------------------------------------------------------");
File.AppendAllText(#"c:\log.txt", s + Environment.NewLine);
}
}
Related
I'm new to Java. Working on QuikcFixJ.
I'm trying to load custom.xml file using datadictionary and later parsing msg string from this datadictionary. Not sure what is wrong with datadictionary , its not throwing any error whether I pass correct fix.xml file path or incorrect one.
Later when I pass msg string to Message object it just parse initial 3 tags irrespective of whatever xml file I mention in datadictionary.
Please give me some pointers to resolve it.
Adding code snippet:
public Message createMsg(String type, String message)
{
message = "35=" + type + "\001" + message;
message = "8=FIX4.2\0019=" + message.length() + "\001"+message ;
String msgCharStr = message.replaceAll("\\|", "\001");
int checksum = MessageUtils.checksum(msgCharStr);
msgCharStr = msgCharStr +"\00110=" + (1 +
MessageUtils.checksum(msgCharStr)) + "\001" ;
quickfix.Message msg = new Message();
msg.fromString(msgCharStr, null,true);
}
This code works fine for regular neworder or quoterequest msgs.
But, when I pass quoterequest msg with custom repeating group which I loaded via UseDictionary config settings, it gives undesired output msg.
e.g: Lets say if I pass input, "35=R|146=1|...|453=2|448=XX|447=G|452=1|448=YY|447=D|452=2|......"
parser gives output as :
"35=R|146=1|...|448=XX|447=G|452=1|453=2|448=YY|447=D|452=2|......"
----Code re-build steps for new custom FIX42.xml ---
Copied quickfixj2.3.1.zip (url: https://github.com/quickfix-j/quickfixj/releases )
Updated xml at path quickfixj-messages/quickfixj-messages-fix42/src/main/resources/FIX42.xml
run mvn build command.
Maven re-build jar for below:
quickfixj-all
quickfixj-core/
quickfixj-messages/
quickfixj-codegenerator/
quickfixj-dictgenerator/
Tried using all above jar files in my RobotFramework with an assumption that it will now refer the modified QuoteRequest msg which has repeating group support.
To my surprise, its output was exactly same. No changes.
After quickfixj rebuild for customised xml file.
Final version of code snippet:
public Message createMsg(String type, String message)
{
message = "35=" + type + "\001" + message;
message = "8=FIX4.2\0019=" + message.length() + "\001"+message ;
String msgCharStr = message.replaceAll("\\|", "\001");
int checksum = MessageUtils.checksum(msgCharStr);
msgCharStr = msgCharStr +"\00110=" + (1 +
MessageUtils.checksum(msgCharStr)) + "\001" ;
DataDictioanry dd = DataDictionary("FIX42.xml");
quickfix.Message msg = new Message();
msg.fromString(msgCharStr, dd ,true);
}
I have a Shared Library containing a declarative pipeline which numerous jobs are using to build with.
However I want to be able to pass the trigger block in from the Jenkinsfile to the Shared Library as some jobs I want to trigger via Cron, others I want to trigger via SNS and others with an upstream job trigger.
Is there a way I can do this? Everything I have tried so fails
I have tried
#Jenkinsfile
#Library('build') _
buildAmi{
OS = "amazonlinux"
owners = "amazon"
filters = "\"Name=name,Values=amzn-ami-hvm-*-x86_64-gp2\""
template = "linux_build_template.json"
trigger = triggers {
cron('0 H(06-07) * * *')
}
#Shared Lib
pipeline {
$buildArgs.trigger
which fails with
Not a valid section definition
Have also tried passing just the cron schedule into the Shared lib e.g.
triggers {
cron("${buildArgs.cron}")
}
but that gives the error
Method calls on objects not allowed outside "script" blocks
Have tried various other thing but it seems the declarative style requires a trigger block with just triggers inside.
Does anyone know of a way to achieve what I am trying to do?
Too much code for a comment:
We wanted to merge some preset properties with jenkinsfile properties.
This is the way to get this to work since the properties method can only be called once.
We used an additional pipeline parameter with the trigger info:
Jenkinsfile:
mypipeline (
pipelineTriggers: [pollSCM(scmpoll_spec: '0 5,11,15,22 * * 1-5')],
)
then in the shared library
#Field def pipelineProperties = [
disableConcurrentBuilds(abortPrevious: true),
buildDiscarder(logRotator(numToKeepStr: '10', artifactNumToKeepStr: '0'))
]
def pipelineTriggersArgs = args.pipelineTriggers
def setJobProperties() {
def props = pipelineProperties
def str = ""
pipelineProperties.each { str += (blue + it.getClass().toString() + it.toString() + "\n") }
if (pipelineTriggersArgs) {
if (debugLevel > 29) {
def plTrig = pipelineTriggers(pipelineTriggersArgs)
str += (mag + "args: " + pipelineTriggersArgs.getClass().toString() + "\t\t" + pipelineTriggersArgs.toString() + "\n" + off)
str += (red + "expr: " + plTrig.getClass().toString() + "\t\t" + plTrig.toString() + "\n" + off)
echo str
}
props?.add(pipelineTriggers(pipelineTriggersArgs)) // pass param with list as the arg
}
properties(props)
}
That was the only way to merge preset and parameters since the properties cannot be overwritten. not exactly the answer but an approach to solve it I think.
I'm working on a DXL program in Doors which supposed to output to a csv file all of source module, target, linkset and version of each (source/target) modules. I've succeed to output "source module, target, linkset but I couldn't extract the version of modules. Does anyone know how to do it ?
Here is my code bellow:
The following uses an output file which is in C:\Temp, but you can easily change that.
it works by matching modules using a grep string, again which you can change to suit.
I have different module types, and therefore I can just get the results on the prefix 'STR' in this case. I decided to have multiple scripts for different prefix modules, rather than dynamically pass the STR keyword.
You need to enter your folder and subfolders for the "modPathname"
then adjust the Regexp "GrepString" to suit your naming convention
alternatively you can bypass all this by hardcoding the values.
string filename = "C:\\TEMP\\STR_Baseline_Info.txt"
Stream outFile = write filename
string Modtype = "STR"
void PrintAndOutput ( string s)
{
// print (s) // Enable if you want output
outFile << s
}
void DisplayResults( string Modtype )
{
Item modItem
Module mName
Regexp GrepString = regexp2 "^" Modtype "-[0-8][0-9][0-9]"
Folder modPathname = folder "/EnterYourFolderHere/AnySubFolders/" Modtype ""
string fullModuleName , CommentStr , moduleName
Baseline b
PrintAndOutput "------------------------------------------------------------------------------\n"
CommentStr = "This File is automatically produced via the " Modtype " Baseline Info.dxl script. \n" Modtype " Versions as of : " dateAndTime(today) "\n"
PrintAndOutput CommentStr
PrintAndOutput "-------------------------------------------------------------------------------\n\n"
for modItem in modPathname do
{
if (type (modItem ) == "Formal")
{
moduleName = (name modItem)
if (GrepString moduleName)
{
fullModuleName = (fullName(modItem))
mName = read(fullName modItem , false)
b= getMostRecentBaseline (mName)
if (b != null )
{
PrintAndOutput moduleName " -\tBaseline : "(major b)"."(minor b)(suffix b) " \t " (dateOf b) "\n"
}
else
{
PrintAndOutput moduleName " \t### No Baseline Information ### \t" " \n"
}
}
}
}
}
DisplayResults ( Modtype)
I browsed around for a solution and I am sure it's a simple question but still not sure how to do that. So, I have a string that contains many words and some times it has links in it. For example:
I like the website http://somesitehere.com/somepage.html and I suggest you try it too.
I want to display the string in my view and have all links automatically converted to URLs.
#Model.MyText
Even StackOverflow gets it.
#Hunter is right.
In addition i found complete implementation in C#: http://weblogs.asp.net/farazshahkhan/archive/2008/08/09/regex-to-find-url-within-text-and-make-them-as-link.aspx.
In case original link goes down
VB.Net implementation
Protected Function MakeLink(ByVal txt As String) As String
Dim regx As New Regex("http://([\w+?\.\w+])+([a-zA-Z0-9\~\!\#\#\$\%\^\&\*\(\)_\-\=\+\\\/\?\.\:\;\'\,]*)?", RegexOptions.IgnoreCase)
Dim mactches As MatchCollection = regx.Matches(txt)
For Each match As Match In mactches
txt = txt.Replace(match.Value, "<a href='" & match.Value & "'>" & match.Value & "</a>")
Next
Return txt
End Function
C#.Net implementation
protected string MakeLink(string txt)
{
Regex regx = new Regex("http://([\\w+?\\.\\w+])+([a-zA-Z0-9\\~\\!\\#\\#\\$\\%\\^\\&\\*\\(\\)_\\-\\=\\+\\\\\\/\\?\\.\\:\\;\\'\\,]*)?", RegexOptions.IgnoreCase);
MatchCollection mactches = regx.Matches(txt);
foreach (Match match in mactches) {
txt = txt.Replace(match.Value, "<a href='" + match.Value + "'>" + match.Value + "</a>");
}
return txt;
}
One way to do that would be to do a Regular Expression match on a chunk of text and replace that url string with an anchor tag.
Another regex that can be used with KvanTTT answer, and has the added benefit of accepting https urls
https?://([\w+?.\w+])+([a-zA-Z0-9\~!\##\$\%\^\&*()_-\=+\/\?.:\;\'\,]*)?
.net string representation:
"https?://([\\w+?\\.\\w+])+([a-zA-Z0-9\\~\\!\\#\\#\\$\\%\\^\\&\\*\\(\\)_\\-\\=\\+\\\\\\/\\?\\.\\:\\;\\'\\,]*)?"
I need to get all the files in a folder that match a certain wildcard pattern, using JScript. For example:
var fso = new ActiveXObject("Scripting.FileSystemObject");
var folderName = "C:\\TRScanFolder\\";
var folder = fso.GetFolder(folderName);
var searchPattern = "1001-*POD*.*"
// Now I need a list of all files matching the search pattern
I know I could iterate through the folder.Files collection and test the names against a regex, but I would prefer to just get Windows to do a search and get only the ones matching. This is mostly for performance, since there could be several hundred files in the folder, but only a few will be the ones I want.
Is there a function or something that I can use to do a search? Or should I stick with a loop and regex?
Edit: Here I what I got to work with a regex. Is there a way to do it without?
var regex = /^1001-.*POD.*\..*$/i;
var files = new Enumerator(folder.Files);
for (files.moveFirst(); !files.atEnd(); files.moveNext())
{
var fileAttachment = files.item();
if (regex.test(fileAttachment.Name))
{
// Do stuff
}
}
One alternative is to shell out to the command line and use the dir command.
var wsh = new ActiveXObject("WScript.Shell");
var fso = new ActiveXObject("Scripting.FileSystemObject");
var dirName = "C:\\someFolder";
var pattern = "s*";
var fileName;
var oExec = wsh.Exec('%comspec% /c dir /on /b "' + dirName + '\\' + pattern + '"');
// wait for dir command to finish
while (oExec.Status === 0) {
WScript.Sleep(100);
}
// process output
while (!oExec.StdOut.AtEndOfStream) {
fileName = oExec.StdOut.ReadLine();
if ( fso.FileExists(fso.BuildPath(dirName, fileName)) ) {
//do stuff
WScript.Echo(fileName);
}
}