I have two questions. I am trying to export results from my calculation when I iterate. I am processing multiple files using code below:
processFile[fileName_] :=
Module[{data},
data = Import[fileName, "Data"];
(*Here I have all my function and processing that I don't want to include here*)
Results1 = Table[{(ii 5) - 2.5, Abs[Mean[bin[5, ii]]]}, {ii, 1, 200}];
(*then here I want to export the resulting table*)
Export["Results_" <> fileName <> ".csv" , Results1]
When I want to loop with multiple files I use this command :
files = FileNames[NotebookDirectory[] <> "*.txt"];
Do[Print["Processing file ", files[[n]]];
processFile[files[[n]]], {n, 1, 2}]
I got an error, because in Export
command fileName
should come before "Results_",
so I changed it to
Export[fileName <> "Results_" <> ".csv" , Results1]
It gives no error, but I wonder if there is a way to fix this issue without moving fileName
?
Also As you see the files that I import are .txt, but I want to export in .csv,
When I export, the exported files contain .txt attached, for example ("file1.txtResults.csv") How to get rid of .txt in the name?
Thank you,
Export["Results_" <> FileBaseName@fileName <> ".csv" , Results1]
$\endgroup$