Message Boards Message Boards

Is it possible to Export to subfolders?

Hey folks,

wrote a notebook to read in all files of a specific type in all the subfolders, process then i want to export the processed data as graphic into the folder, where the original file is located.
So here is my problem: If i just use the files in the notebook directory, it works just fine

hefiles = FileNames["*Data*.txt"];

For[i = 1, i <= Length, i++,
makeDensity[i, hefiles[]] Export[
   StringJoin["Teilchendichte_", ToString[hefiles[]], ".dat"],
   makeDensity[i, hefiles[]]]]

If i try to also import the files from the subfolder using:
hefiles = FileNames["*Data*.txt", {"*"}, Infinity];

The export yieds in an error saying:
Export::nodir: Directory H:\Martin\05_Messreihen\Neue Düse\Wellenfronten\GD23\3DPlot_ 150\sSignal\ does not exist

But the folder DOES exist.

Any suggestions what i might change to process all the files i got at once (it is about 420 in like 50 folders)

Thanks in advanced,
POSTED BY: ma bu
3 years ago
Try a file name builder that injects the desired prefix into the file name part, instead of prepending it to the relative file path with StringJoin, like this
In[ ]:= datPrefix[prefix_String, fn_String] := StringReplace[fn,
  FileNameTake[fn] :> StringJoin[prefix, FileNameTake[fn], ".dat"]]

In[ ]:= datPrefix["Teilchendichte_", hefiles[[1]]]
Out[ ]= "test\\Teilchendichte_someData123.txt.dat"
POSTED BY: Christopher French
3 years ago

Group Abstract Group Abstract