Message Boards Message Boards

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

Working in multiple directories (Figured it out.)

Hello world!

Here is the gist:

I have spectra that has 3 different variations. I have 64 scans (individual files) per variation. I have neatly organized them into their respective folders. My goal is to export a .csv for each variation. So far I have written the script up to add up all 64 scans and make it a nice 2-d array of data then export to a .csv. However, I want to write a For-Loop that does it for the 3 variations as well. So it goes into one directory, adds, comes back to the parent, and goes to the next directory, adds again and etc.

Problem is, I attempt to use SetDirectory and it rejects the Loop because it is not a String-value. I used the ToString command and it rejects that as well.

The actual error is SetDirectory::fstr: File specification {BG ,data.csv,Sigma Minus ,Sigma Plus} is not a string of one or more characters

Here is the relevant code:

b = FileNames[];

For[i = 1, i <= Length[b], i++, InputForm[StringDrop[StringDrop[ToString[Take[b, i]], -1], 1]] SetDirectory[%]

Any and all help is greatly appreciated.

POSTED BY: John Tokarski

Figured it out. Must be a syntax issue. But you can avoid the situation. In my above example, I have a list of the folders denoted as 'b'.

You can much easier type this as the code

For[i = 1, i <= Length[b], i++, SetDirectory[b[[i]]];

it works much easier.

POSTED BY: John Tokarski

Group Abstract Group Abstract