# How to display new windows for each graphic from several file?

I use the following link in the forum to plot a graphic in a new windows. However when I use the code to create a new windows using the function described below in question, yes it works but in the new window I see only the results for the last file and not for each files I have (i.e. if I have 3 files, I have three new windows but with the result of the last file in my folder and not with the results of each file...). I would like to create a new windows graphic for each file I have...How to do that in my function ?

CreateDocument[Dynamic[secondDisplay]];
showOnSecond[expr_] := (secondDisplay = expr;);

showOnSecond@ListDensityPlot[...]


Here the function I use :

file = FileNames["*.dat", NotebookDirectory[]];

func[file_String /; FileExistsQ[file]] :=
Module[{data, dataT}, data = Import[file, "Table", HeaderLines -> 2];
dataT = Transpose[data];
dataT = {dataT[[1]]*10, dataT[[2]]*10, dataT[[3]]};
dataT[[3]] =
Rescale[dataT[[3]],
MinMax[dataT[[3]]], {0, 1.}]; (*Rescale z between 0 to 1*)
data = Transpose[dataT];

CreateDocument[Dynamic[secondDisplay]];
showOnSecond[expr_] := (secondDisplay = expr;);

showOnSecond@ListDensityPlot[data,
ScalingFunctions -> {"Linear", "Linear", "Log10"},
ImageSize -> UpTo[850],
AspectRatio -> 1];

;
;
]

func /@ file

• Why not ... data = Transpose[dataT]; CreateDocument @ ListDensityPlot[..? It does not work because secondDisplay is a global variable that you use in every plot. – Kuba Dec 5 '18 at 14:12
• Yes it works, thanks a lot – Bigprophete Dec 5 '18 at 14:27

CreateDocument@ListDensityPlot[data,