Bulk file move from one folder to another

Say you have a system which is processing some files e.g. Data files and Response files. Response files are given by 3rd party system based on your data submission to that system.

You have the data files and response files in your windows PC in different folder. Now you need to move the response files by year in a new folder based on the data file. You have the relationship in database.

In this scenario, we can move the files easily developing a small tool using C#.

At first we need to extract the data file vs. response file relationship from database and kept in a csv file. Sample file: https://www.screencast.com/t/fjK4nBUR

In this sample file, 1st column contains the name of response file, 2nd one data file name and 3rd claim id (which is not needed now).

Say in you local PC, all files are kept in this location: D:\Files\AllResponseFiles\

And you want to move 2017 response files only in a new folder e.g. D:\Files\AllResponseFiles\2017

So, the C# code would like this:
private static void fileMove()
{
   string path = @"D:\Files\AllResponseFiles\Sample.csv";
   string[] lines = File.ReadAllLines(path);
   foreach (string line in lines)
   {
      if (line.Split(',')[1].Contains("_2017"))
      {
         try
         {
            File.Move(@"D:\Files\AllResponseFiles\" + line.Split(',')[0],             @"D:\Files\AllResponseFiles\2017\" + line.Split(',')[0]);
         }
         catch (IOException e)
         {
            if (e.Source != null)
             Console.WriteLine("IOException source: {0}", e.Source);
         }
      }
   }
}

This may help you.

Batch Rename multiple files using PowerShell command

In this article I’ll describe how easily you can rename files in a folder/directory using Microsoft Windows PowerShell.

You will get lots of article in internet, I’ve consolidated some commands in one article.

1st open the Windows PowerShell and navigate to your desired folder/directory (e.g. > cd “D:\Hello World”) and then run the following Windows PowerShell command:

  1. Appending directory name into file names
    • dir | Rename-Item -NewName {$_.Directory.Name + " - " + $_.Name}
      Output of above example: If your directory name is Hello World then all files of this directory will be Hello World – file1.txt, Hello World – file2.txt and so on.
  2. Find a specific text and replace with new text
    • Get-ChildItem -Filter "*Hello World*" | rename-item -NewName {$_.Name -replace "Hello World", "New World"}
      Output of above example: If a file name is Hello World – file1.txt then it will be New World – file1.txt.
  3. Changing the file extension of all .jpeg files to .jpg
    • dir *.jpeg | rename-item -newname {$_.name  -replace ".jpeg",".jpg"}
      Output of above example: All files of the directory will be .jpg.
  4. Appending a file extension
    • dir | rename-item -newname {$_.Name +".txt"}
      Output of above example: All files of the directory will be now .txt
  5. File rename with customizable increasing number
    • dir *.txt | ForEach-Object -begin { $count=1 }  -process {rename-item $_ -NewName "fileName$count.txt"; $count++}
      Output of above example: All files of the directory will be fileName1.txt, fileName2.txt and so on.

Web Application Testing, Basic

Testing is a vast thing. And you cannot limit your testing boundary. But you have to draw a boundary to checking your web application for potential bugs/issues before you give a release i.e. before you made your application live.

Some of the following basic testing checklist you should perform depending on your requirements:

Functionality testing:

  1. Verify all Links: all internal links, outgoing links, anchor links, mailto links should work properly.
  2. Test Forms: This is the most important part to testing as data are saved (that user input into forms) in database through the forms submission. We should verify following:
    1. Verify Required fields: Based on the requirement, some fields should require in the form.
      • So, validation should be implemented both from client side and server side.
      • And proper validation message should show to user
      • And there should be indication for required fields on form so that user can identify them easily.
    2. Verify Default values of the fields (if any in the form as per requirement) should populate properly.
    3. Verify Exception handling of the form.
    4. Verify Form Submission is working properly i.e.
      • All data should be saved in DB properly.
      • In some cases mail functionality given on form submission if so, need to verify the email functionality and its content as per requirement.
  3. Test HTML and CSS to ensure that search engines can crawl your application easily. This will include:
    1. Checking for Syntax Errors
    2. Readable Color Schemas
    3. Standard Compliance
  4. If your application have Print functionality then make sure fonts, page alignment, page graphics etc., are getting printed properly. Pages should fit to the paper size or as per the size mentioned in the printing option.
  5. If your application have Export functionality then make sure data are exported into chosen file format properly. Say, through your application user can export data in Doc format and/or Excel format then
    1. Make sure fonts, alignment are properly implemented on exported doc as well along with actual data that you are expected.
    2. Make sure column names, data integrity, additional cell/column format if any are properly implemented on exported excel as well.

GUI testing: Graphical User Interface testing also known as UI testing is important as well. At a glance user will use the application though interface so it’s UI should be accurate. We should verify following:

  1. Alignment should be implemented properly
    • for page content;
    • for Form input fields and label;
    • Menu/Sub Menu items etc.
  2. Validation message should prominent so that user can notice the error easily.
  3. Font, Font size, Font family, Color scheme should be readable.
  4. Image aspect ratio should maintain.
  5. If your application is implemented based on liquid design then test following scenarios:
    • Full screen and other view modes.
    • Different application window sizes (document window sizes too, if your app has a multi-document interface); especially: default launch size, minimized, maximized, not-maximized-but-sized-to-fill-the-screen, and sized very small.

Security testing: It is also vital if your application have secure data. Verify following:

  1. Secure pages/forms/files should not accessible without proper authentication like cannot accessible without login.
  2. On use of SSL certificates, application should re-direct to encrypted SSL pages.
  3. Login session should be destroyed after prolonged user inactivity.
  4. Verify Cookie stealing is not possible in your web application.
  5. Some security testing should be verified on form fields as well:
    1. HTML tags for input fields on form should encode/decode on save/retrieval, which will make the form vulnerable to XSS attack. Common try from the attacker as like this: alert(‘XSS’);
    2. Set the max length of a input field (mainly for text box), otherwise that will make the form vulnerable to Buffer overflow and will causes the program termination ( a crash), incorrect results or a breach of system security.
    3. Filtered the input field by the script, otherwise that will make the form vulnerable to SQL injection and will causes the dropping the DB table, edit/delete the records from DB by the attacker. Common try from the attacker as like this: ‘or1=1–
    4. If you have file upload control in your web form then verify following:
      • Check the file type for file upload field; if you not block the dangerous file extensions for the file upload control, which could gain access to the file server system of your web applications by the attacker.
      • Check the zero size file and how application behave.
      • Check with Single character filenames.
      • Check with Short filenames.
      • Check with Extra-long filenames.
      • Check with filenames containing reserved words.
      • Check the complete path to the file (c:\My\Directory\Structure\testfile.txt)
      • Check A relative path into the current folder (.\testfile.txt)
      • Check a deeply nested path (Some\Very\Very\Very\Very\Very\Deeply\Nested\File\That\You\Will\Never\Find\Again\testfile.txt)
    5. For some cases only implement the client-side validation. But server side validation missed for some potential input fields e.g. file upload control.
    6. If your form uses CAPTCHA then ensure following as well:
      • Server side validation must be implemented for CAPTCHA field.
      • CAPTCHA images should not reveal absolute path names.
      • Do not have cyclic fashion CAPTCHA images. Like 1 to 100 and then again 1 to 100. It is Easy to crack.
      • Usage of background noise in the image, different textures, and different angle of displaying the characters might be a good idea to make it difficult for some CAPTCHA cracking programs like http://free-ocr.com/ and few others.
      • If audio CAPTCHA given then use some Audio to text converters software and see whether they are able to crack the audio CAPTCHA or not.
      • CAPTCHA should refresh on every wrong entry. Keeping it static might be vulnerable to brute force attack for CAPTCHA to bypass it.

Usability testing: Usability testing has now become a vital part of any web based application. Verify following:

  1. Test the Navigation: Menus, buttons or Links to different pages on your application should be easily visible and consistent on all pages.
  2. Test the Content:
    • Content should be clear enough to read with no spelling or grammatical errors.
    • Images if present should contain an “alt” text.

Compatibility testing: Compatibility tests ensures that your web application displays correctly across different browsers/devices. Verify following:

  1. Browser compatibility, also known as cross browser testing:
    • Your web application need to ensure that works fine on different browsers. Different browsers have different configurations and settings so that your web application should be compatible with.
    • Verify JS or Ajax calls, UI on different browser.
    • Test your application at least on Chrome, Firefox, Internet Explorer, Safari etc. If possible with different versions.
    • If your application mobile browser compatible then test the application mobile browser as well.
  2. OS compatibility: Some functionality in your web application may not be compatible with all operating systems. So, you need to ensure your application is running properly on renowned OS platform like Windows, Mac, Linux etc.

Performance testing: You application should work smoothly under heavy loads. Testing activities will include:

  1. Web application response times at different connection speeds.
  2. Load test your web application to determine its behavior under normal and peak loads.
  3. Stress test your web site to determine its break point when pushed to beyond normal loads at peak time.
  4. Test if a crash occurs due to peak load , how does the site recover from such an event
  5. Make sure optimization techniques like gzip compression, browser and server side cache enabled to reduce load times.

Database testing: Database is one critical component of your web application and stress must be laid to test it thoroughly. Testing activities will include:

  1. Test if any errors are shown while executing queries
  2. Data Integrity is maintained while creating, updating or deleting data in database.
  3. Check response time of queries and fine tune them if necessary.
  4. Test data retrieved from your database is shown accurately in your web application.

Network Connectivity testing: You should verify how your application handles various network configurations and events. You should have various permission level on server and how those behave on different network configurations. Like:

  1. Connecting over a network which supports only IPv4.
  2. Connecting over a network which supports only IPv6.
  3. Connecting over a wireless network.
  4. Accessing documents from a network location which requires user authentication.
  5. Performing a Print Preview to a network printer which is disconnected or otherwise unavailable.

Create large data file using SQL easily from your small data file

Say, you have a small set of data file like 1K and now you need a large data set say 1M records in the file. You will get some tools in online to do that. But this may not fulfill your needs.

For my case not helped. Because my data set require some additional requirement like, some ID must be unique; some fields data should not overlapped with another field data etc.

In the SQL Management Studio we have a nice feature i.e. Import Data/Export Data. Using this feature you can easily and efficiently prepare your test data.

So, at 1st you need to import you small file in your database using ‘Import Data…’. You can import CSV, Excel, Text type file. My sample file.

I’ve seen SQL Import wizard can import the Text (tab delimited) file more accurately than other file type. So I have tried with Tab delimited file.

See the attached file to Import your file in database for details, Import Data.

After successful import, you will see a table (table will same as file name) in your database with your file data into it. FYI, table column and it’s data type will automatically set based on your data of your file.

Now, you have to create another table if you need to change the column data type. You can do that using this script.

After creating the 2nd table you need to move the data from 1st table to 2nd table. You can do that using this script.

Now, you can looping the 2nd table data and increase the data volume as you want. You can do that using this script.

All are set, now you need to export your data into a file. You can set your data volume for your file based on your table records. You can do that using ‘Export Data…’ feature of the SQL management studio.

See the attached file for export for details, Export Data. FYI, you can export the file in Excel/Plain text format.

Hope this article may help you a bit. Feel free to comment here if you have any query.

CountIt! a simple Chrome extension that may help you.

This is a simple chrome extension which may help you to quickly determine the number of words and characters contained in any phrase along with the string match.

You can download it from the chrome web store.

You are most welcome to give your review and comments.

Thanks.