How to automatically create batch copies of test data files on Windows for testers

Tram Ho

In the fast-paced world of software testing, efficiency is key. As a tester, sometimes I have to create 2000 duplicated records from 1 record with 1GB capacity and have to do repetitive tasks like generating test data or generating sample files. Sometimes it takes hours to run rice just to copy files and wait. These manual processes are not only time consuming but also increase the risk of errors.

Therefore, today I will share with you a solution: a tool to automatically create files with Windows PowerShell itself on a windows computer – the purpose of managing automation and configuring tasks based on . NET frameworks. *On Macbook you can also customize it yourself.* 🙂

The problem I have is that there is a file named 500 in drive E, I want to make n copies of 500 with automatic ascending number: 501, 502, 503…, without a editor. edit code.

 

Step 1: You go to Windows PowerShell on the Start Menu and open

Uploading image.png…

Step 2: Point the path to the destination location of the files that will be copied from the original file, here I will point to drive E

From the Powershell interface, enter Set-Location -Path “E:”
Make sure that the parent folder “TargetFile_E” and the subfolder “500” already exist on drive E of the computer.

Step 3: Paste the entire command below into Powershell and Enter

$startingIndex = 500
$parentFolder = "TargetFile_E"
$sourceFolder = ""
for ($i=$startingIndex; $i -lt ($startingIndex + 100); $i++) {
$newFolderName = "$i"
$destinationPath = Join-Path -Path $parentFolder -ChildPath $newFolderName
Copy-Item -Path $sourceFolder -Destination $destinationPath -Recurse
}

Explain

Line 1: Define the variable “$startingIndex” with a value of 500.
Line 2: Define the variable “$parentFolder” with the value “TargetFile_E”, this is the name of the folder that will contain the copied files.
Line 3: Define the variable “$sourceFolder” with the value “OriginalFile”, this is the source folder containing the content that will be copied to the new folders.
Lines 4-9: Use a “for” loop to create 100 new directories. For each “$i” value from “$startingIndex” to “$startingIndex + 100”, the following steps will be performed:
Line 5: Define the variable “$newFolderName” with the value “$i”, this is the new folder name.
Line 6: Define the variable “$destinationPath” by combining the path “$parentFolder” and the new folder name “$newFolderName”.
Line 7: Use the “Copy-Item” command to copy the contents from the source folder “$sourceFolder” to the destination folder path “$destinationPath”.
The “-Recurse” option is used to copy all files and subdirectories.

Note

The “TargetFile_E” and “500” paths may vary depending on the actual path of the parent and subdirectories.
If the parent directory “TargetFile_E” is in another subdirectory, provide the full path of the parent directory in the $parentFolder variable.

After running this PowerShell script, you’ll have 100 new folders created, each with an ascending number from 510, and containing content copied from the “500” subdirectory.

Good luck with your test!

Share the news now

Source : Viblo