Skip to main content
Announcements
Qlik Connect 2024! Seize endless possibilities! LEARN MORE
cancel
Showing results for 
Search instead for 
Did you mean: 
Not applicable

Change filename when copy & paste

Hi all,

I'm trying copy & paste the images from location to another location. While pasting image, the image name should change in suffix should have with another field name.

i.e; LotNo-ImageName

Below is the my macro code, how can i add suffixname when pasting image to destination folder

Here

vImagesLocation = C:\ImageSource\

vImagesDestination = D:\ImageDestination\

vLensInspectionImageNames = GetFieldSelections(ImageName,',','*') Ex : 2012_1030_153442_664.bmp (In vImageLocation images having this kind of names)

Now when saving in vImagesDestination it should save as 100123-2012_1030_153442_664.bmp (Consider here the LotNo for this file is 100123).

Please let me know what i needs to add in code to get exact output what i expected.

Sub CopyPasteImages

          Dim sOriginFolder, sDestinationFolder, sFile, oFSO,

          Dim iCount

          Set oFSO = CreateObject("Scripting.FileSystemObject")

          Set vLensInspectionImageNames=ActiveDocument.Variables("vLensInspectionImageNames")

          Set vImageSourcePath=ActiveDocument.Variables("vImagesLocation")

          Set vImageDestinationPath=ActiveDocument.Variables("vImagesDestination")

          ArrFields = split(vLensInspectionImageNames.GetContent.String, ",")

 

          iCount = 0

          For Each fIndex in ArrFields

                    sOriginFolder = vImageSourcePath.GetContent.string&fIndex

                    sDestinationFolder = vImageDestinationPath.GetContent.string&fIndex

                    sFileNameExtension = vImageNameExtension.GetContent.string

                    if oFSO.fileExists(sOriginFolder) then

                              iCount = iCount + 1

                              oFSO.CopyFile sOriginFolder, sDestinationFolder

                    end if 

                    If iCount >=1000 then Exit Sub

          Next

End Sub

Thanks in advance

3 Replies
Gysbert_Wassenaar

Maybe like this (untested):

          For Each fIndex in ArrFields

                    sOriginFolder = vImageSourcePath.GetContent.string&fIndex

                    ActiveDocument.Fields("ImageName").Select fIndex

                    vPV = ActiveDocument.Fields("LotNo").GetPossibleValues

                    LotNo = vPV.Item(0).Text

                    sDestinationFolder = vImageDestinationPath.GetContent.string&LotNo&'-'&fIndex

                    sFileNameExtension = vImageNameExtension.GetContent.string

                    if oFSO.fileExists(sOriginFolder) then

                              iCount = iCount + 1

                              oFSO.CopyFile sOriginFolder, sDestinationFolder

                    end if 

                    If iCount >=1000 then Exit Sub

          Next


talk is cheap, supply exceeds demand
Not applicable
Author

Hi Gysbert,

Yes it is getting LotNo name suffix to imagename, but currently for every image the lotno is getting same

Actually imagenames having different lotno's.

What i needs to change in your code to get the same LotNo for that particular ImageName ?

Thanks in advance.

Not applicable
Author

Hi can anyone help on this. It is urgent !!!

Thanks in advance