Message Boards Message Boards

0
|
3713 Views
|
1 Reply
|
0 Total Likes
View groups...
Share
Share this post:

Is it possible to Export to subfolders?

Posted 10 years ago
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

Import:
SetDirectory[NotebookDirectory[]];
hefiles = FileNames["*Data*.txt"];

Export:
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,
Martin
POSTED BY: ma bu
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
"Teilchendichte_test\\someData123.txt.dat"
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"
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard

Group Abstract Group Abstract