How to make an empty copy of a folder structure in Windows

I found myself needing to copy a folder structure in Windows, but I didn’t need any of the files contained within.

One way of doing this would be copying and pasting it to where I wanted, then navigating the folders and manually deleting all of the files, but the copy operation would be longer than necessary, due to it copying the contents of all of the folders & the deletion of the files after the copy would take even more time.

So, I recommend using a command line utility called xcopy.

Xcopy has been around for a very long time & is an extended version of the copy command.

So, back to it. Let’s say we want to copy the structure of FolderA including all it’s sub-folders recursively and call the copy FolderB. To do that we can fire up the command prompt or powershell and run the following command

xcopy /t /e FolderA FolderB

It will then ask if the target is a file or directory, we want to press D for our scenario.

And that’s it. We are done.

In the above command the /t means copy the directory structure without files and the /e means we want it to copy empty folders too.

If you want a complete list of switches, then you can run:

xcopy /?

Hope this helps someone. Please like & share & I look forward to reading any comments.

Product review: Merrell All Out Blaze 2 GTX low rise hiking shoes

In these strange times, when we can’t venture more than a few miles from our homes, or meet up with friends and family, we all need to take advantage of our daily exercise allowance in order to relieve the tedium of our confinement.

Merrell All Out Blaze 2 GTX
Just unboxed and laces reconfigured
Continue reading

A simple C# JsonConverter example – bool to bit

Newtonsoft Json.NET is a great framework for serialising/de-serialising your Json with .Net, it has a good collection of default handlers for transforming data-types, but what if you would like to override the way in which a property is written/read.
In this example we will change the way that boolean properties are handled, so that they are read and written as 1 or 0 as opposed to the default “True” or “False”.

Continue reading

Splitting strings in MS Excel without regular expressions

Consider a field in Excel that contains a number followed by a ‘\’ character, followed by 3 letters.

For example: 123456789\ABC

No let us say that you would like to get the part of the string that exists before or after the ‘\’ character into another field.

You could write a VBA script that uses regular expressions, but this can more easily be achieved using a combination of the RIGHT, LEFT, LEN and FIND methods. Continue reading

T-SQL: The STUFF method, inserting characters to a varchar

There are many scenarios in which you might want to add characters to the middle of a string, for example formatting a date string from ddMMyyyy to dd/MM/yyyy (standard format in the UK).

There are also quite a few ways to do this, you can use substring and concatenation methods, or in JavaScript you could use a split, splice & join.

In SQL there is a method to do this, you might think that it would be called something nice, like splice, but no! It’s called STUFF! Granted, it does sound worse when you place an exclamation mark after it.

Anyway, this is how you would use the STUFF method using our example above.

DECLARE @strDate VARCHAR(8) = '16041980'

SELECT STUFF(STUFF(@strDate, 5, 0, '/'), 3, 0, '/') as [formattedDateString]

As you can see, we have used the STUFF method twice here, starting with the inner call, we add the ‘/’ character that is nearest the end of our string, then with the outer call, we add the second from last ‘/’ character.

It is important that we do it in this order, as we are modifying the length of the string with each call, & therefore the position of the characters after the one that we are adding.

The 5 and the 3 in the above snippet indicate the positions to insert the character, the 0’s indicate how many characters at those positions we would like to overwrite, the others are self explanatory, however if you would like it, further reference can be found here on MSDN.

T-SQL: Casting Varchar to XML removing illegal characters

As I mentioned in an earlier post, we deal a lot with XML messages on ActiveMQ JMS queues going through our ESB.  For audit purposes most data that goes through the ESB is logged at some point, including these XML messages.

These XML messages have been stored, historically, in fields of type varchar, so if we want to use XPath to query the XML, we need to cast the varchar values to XML first.

Unfortunately, there are illegal characters in our XML, so we can’t just CAST(… AS XML), we have to replace those characters first.

As I am a sharing kind of guy, here’s a snippet to help others…


Declare @cr Char(1) = char(13)
Declare @lf Char(1) = char(10)
Declare @tab Char(1) = char(9)
Declare @pound Char(1) = char(163)
Declare @uScore Char(1) = char(150)
Declare @regSymbol Char(1) = char(174)
Declare @tmSymbol Char(1) = char(153)
Declare @f1Quote Char(1) = char(146)
Declare @b1Quote Char(1) = char(145)

SELECT
CAST(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE([MyXMLField], @cr, ''), @lf, ''), @tab, ''), @pound, ''), @uScore, ''),@regSymbol,''),@tmSymbol,''),@f1Quote,''),@b1Quote,'') AS XML)
FROM ...

Please let me know in the comments if you have come across a cleaner solution to this problem, or if it needs updating with extra characters.

Configuring a proxy in Visual Studio 2015

Every now & then, I would get a little message pop-up in Visual Studio telling me that I needed to re-authenticate with the proxy, or proxy authentication required.

This isn’t a massive problem, but it is a minor irritation, so to stop this happening, I found the devenv.exe.config file in C:\Program Files (x86)\Microsoft Visual Studio 14.0\Common7\IDE and updated the <system.net> with default proxy settings, as below:

<system.net>
   <defaultProxy enabled="true" useDefaultCredentials="true">
      <proxy bypassonlocal="True" proxyaddress="http://webproxy.someDomain.com:8080"/>
   </defaultProxy>
   <settings>
      <ipv6 enabled="true"/>
   </settings>
</system.net>

Obviously, the proxyaddress has been modified above to something generic, so you will need to change that to whatever your proxy address is & specify the correct port number.

First foray into the lair of the Mule…

Around a year ago I started a new job in the motor insurance industry, with a company that is part of the Lloyds Insurance syndicate who only do business through insurance brokers. These brokers send in details of new business, mid-term adjustmment, renewals & cancellations, claims.  Then this is complicated further by us providing breakdown cover too.

Now, you might think that this doesn’t sound too complicated, give them a schema and ask them to send files to match that schema, or provide them with an API that they can hook into… nope! Continue reading