ByteScout Barcode Reader SDK - VBScript - Rename Files To Barcode Values - ByteScout

ByteScout Barcode Reader SDK – VBScript – Rename Files To Barcode Values

  • Home
  • /
  • Articles
  • /
  • ByteScout Barcode Reader SDK – VBScript – Rename Files To Barcode Values

How to rename files to barcode values in VBScript using ByteScout BarCode Reader SDK

The tutorial below will demonstrate how to rename files to barcode values in VBScript

The sample source code below will teach you how to rename files to barcode values in VBScript. ByteScout BarCode Reader SDK can rename files to barcode values. It can be used from VBScript. ByteScout BarCode Reader SDK is the barcode decoder with support for code 39, code 128, QR Code, Datamatrix, GS1, PDF417 and all other popular barcodes. Can read barcodes from images, pdf, tiff documents and live web camera. Supports noisy and damaged documents, can split and merge pdf and tiff documents based on barcodes. Can export barcode decoder results to XML, JSON, CSV and into custom data structures.

Fast application programming interfaces of ByteScout BarCode Reader SDK for VBScript plus the instruction and the code below will help you quickly learn how to rename files to barcode values. In your VBScript project or application you may simply copy & paste the code and then run your app! Detailed tutorials and documentation are available along with installed ByteScout BarCode Reader SDK if you’d like to dive deeper into the topic and the details of the API.

Trial version of ByteScout BarCode Reader SDK can be downloaded for free from our website. It also includes source code samples for VBScript and other programming languages.

Try ByteScout BarCode Reader SDK today: Get 60 Day Free Trial or sign up for Web API

RenameFilesToBarcodeValues.vbs
      
if WScript.Arguments.Count < 2 Then MsgBox "Run with the folder path as the argument" & vbCRLF & vbCRLF & "RenameFiles.vbs InputFolder\ OutputFolder\" WScript.Quit 0 End If Set objFSO = CreateObject("Scripting.FileSystemObject") ' define allowed input images extensions inputImagesExtensions = "JPG,JPEG,PNG,BMP,PDF,TIF" ' make sure they all are upper cases inputImagesExtensions = UCASE(inputImagesExtensions) Set bc = CreateObject("Bytescout.BarCodeReader.Reader") ' Set barcode types to find: bc.BarcodeTypesToFind.Code39 = True bc.BarcodeTypesToFind.QRCode = True bc.BarcodeTypesToFind.PDF417 = True Set objinputFolder = objFSO.GetFolder(WScript.Arguments(0)) ' output folder set objOutputFolder = objFSO.GetFolder(WScript.Arguments(1)) Call ShowSubfolders (objinputFolder) WScript.Quit 0 Sub ShowSubFolders(fFolder) Set objFolder = objFSO.GetFolder(fFolder.Path) Set colFiles = objFolder.Files For Each objFile in colFiles ' check if allowed extension If inStr(inputImagesExtensions, UCase(objFSO.GetExtensionName(objFile.name)))>0 Then ' read barcode from filename WScript.Echo "Reading from: " & objFile.Path bc.ReadFromFile objFile.Path ' getting the sub folder path outputSubFolder = Replace(objFile.Path, objinputFolder.Path, "") outputSubFolder = Replace(outputSubFolder, objFile.Name, "") ' rename the file to the value of the very first barcode found on this image or pdf newFileName = bc.GetFoundBarcodeValue(0) & "." & objFSO.GetExtensionName(objFile.name) ' replace some special characters as they may not be allowed for use in filename newFileName = Replace(newFileName, "<", "_") newFileName = Replace(newFileName, ">", "_") ' first check if output subfolder exists if Not objFSO.FolderExists (objOutputFolder.Path & outputSubFolder) Then objFSO.CreateFolder objOutputFolder.Path & outputSubFolder End If WScript.Echo "Copying and renaming " & objFile.path & " into " & objOutputFolder.Path & outputSubFolder & newFileName ' copying the source file into output folder with new filename based on the barcode value objFSO.CopyFile objFile.path, objOutputFolder.Path & outputSubFolder & newFileName End If Next For Each Subfolder in fFolder.SubFolders ShowSubFolders(Subfolder) Next End Sub

Try ByteScout BarCode Reader SDK today: 60 Day Free Trial (on-premise version) or sign up for Web API (on demand version)

RunRenaming.bat
      
REM running from the command line cscript.exe RenameFilesToBarcodeValues.vbs "input" "output" pause

Try ByteScout BarCode Reader SDK today: 60 Day Free Trial (on-premise version) or sign up for Web API (on demand version)

VIDEO

ON-PREMISE VERSION

Get 60 Day Free Trial or Visit ByteScout BarCode Reader SDK page

Explore ByteScout BarCode Reader SDK documentation

WEB API

Sign Up for free Web API key

Explore Web API Documentation

Tutorials:

prev
next