Here is a simple recursive function to display all file-names with full path in folders and sub-folders. You can only run this command in Windows PowerShell available since the release of Windows 7.
Wednesday 30 December 2015
Batch Rename All Files in a Folder to Lowercase in MS Windows
If you are not interested in external programs to renames all files in a folder to lowercase, there is a simple command for you.
- Open Command Prompt (cmd.exe) in Windows
- Go to the directory and run the following command
Note: This is not a recursive function, it will rename files to lowercase only on the directory where you will run the command.
- Open Command Prompt (cmd.exe) in Windows
- Go to the directory and run the following command
for /f "Tokens=*" %f in ('dir /l/b/a-d') do (rename "%f" "%f")
Note: This is not a recursive function, it will rename files to lowercase only on the directory where you will run the command.
Sunday 8 November 2015
Create Yozio SubLink using C#
If you need to read more about Yozio Sublink API, here is the documentation http://docs.yozio.com/articles/sublink-apis
Wednesday 7 October 2015
Batch Convert PSD files to PNG Using Photoshop
Follow the steps to batch convert Photoshop Files (PSD) into PNG files.
Wednesday 9 September 2015
Visual Studio 2015 - Open Old/Migrated Solution Creates Backup Folder Continuously
I was in the process of migrating over to Visual Studio 2015 from Visual Studio 2013. When I executed a local command line build, I received the following error.
Saturday 16 May 2015
How to Get Random Items from Array or List in C#
The simple way to get random item from an Array is to use the return value from random.next(0, array.length) as index to get value from the array.
The easy approach is to consider Array as a deck of cards. We want the items to be 'shuffled' similar to a deck of cards, meaning avoiding any repetition. So we will use a List<> for the source items, grab them at random and push them to a Stack<> to create the deck of items.
You can create a Stack from anything that is IEnumerable
However, the stack constructor will be using a loop internally, you just don't see it. So for understanding the purpose I will use an example to create Stack with loop.
/Adnan
var randomIndex = random.Next(0, Array.Length); Console.Write(Array[randomIndex]);The downside of the above code is it might return you item multiple times (repetition) as we don't keep track of items that we are getting from the source Array.
The easy approach is to consider Array as a deck of cards. We want the items to be 'shuffled' similar to a deck of cards, meaning avoiding any repetition. So we will use a List<> for the source items, grab them at random and push them to a Stack<> to create the deck of items.
You can create a Stack from anything that is IEnumerable
var stack = new StackSee MSDN: http://msdn.microsoft.com/en-us/library/76atxd68.aspx(myList);
However, the stack constructor will be using a loop internally, you just don't see it. So for understanding the purpose I will use an example to create Stack with loop.
public static Stack CreateShuffledDeck(IEnumerable values) { var random = new Random(); var list = new List(values); var stack = new Stack(); while (list.Count > 0) { // Get the next item at random. var randomIndex = random .Next(0, list.Count); var randomItem = list[randomIndex]; // Remove the item from the list and push it to the top of the deck. list.RemoveAt(randomIndex); stack.Push(randomItem ); } return stack; }Now we have a solution to create a Shuffled Deck. We can now get random items out using Stack.Pop method . Popping something from the stack means "taking the top 'thing'" off the stack.
public static string[] RandomArrayEntries(string[] arrayItems, int count) { var listToReturn = new List(); if (arrayItems.Length != count) { var deck = CreateShuffledDeck(arrayItems); for (var i = 0; i < count; i++) { var arrayItems= deck.Pop(); listToReturn .Add(item); } return listToReturn .ToArray(); } return arrayItems; }We can execute the above code as following:
var countriesArray = new string[] { "Sweden", "Pakistan", "United Kingdom", "Denmark", "Norway", "Finland" }; var newRandomAraay = RandomArrayEntries(countriesArray, 3);
/Adnan