@Helal asked in Import Multiple CSV Files from different folder, Update Value, and save CSV with different names how to do several things: gather a bunch of CSV files from a directory tree, make edits, and save the files back to their original directory, as CSV, renamed slightly. This JSL will get you started.
Do be careful with the Delete Directory! Don't use it in your code!
dir = Convert File Path( "$temp/deletemeCSV/" );
Create Directory( dir );
subdira = Convert File Path( dir || "argyle/" );
subdirb = Convert File Path( dir || "plaid/" );
Create Directory( subdira );
Create Directory( subdirb );
dt = Open( "$sample_data/big class.jmp" );
dt:name[1] = "katieA";
dt << save( subdira || "a.csv" );
dt:name[1] = "katieB";
dt << save( subdirb || "b.csv" );
Close( dt, nosave );
dtlist =
Multiple File Import(
<<Set Folder( dir ),
<<Set Subfolders( 1 ),
<<Set Stack Mode( "Table Per File" )
) << Import Data;
For( i = 1, i <= N Items( dtlist ), i += 1,
dt = dtlist[i];
For Each Row(
dt,
If( dt:name == "katieA",
dt:age = 98
);
If( dt:name == "katieB",
dt:age = 99
);
);
sourceFile = (dt << getproperty( "Files" ))[1][1];
destfile = Substr( sourcefile, 1, Length( sourcefile ) - 4 ) || "_new.csv";
dt << save( dir || destfile );
Close( dt, nosave );
);
Show( Files In Directory( dir, recursive( 1 ) ) );
Open( subdira || "a_new.csv" );
Open( subdirb || "b_new.csv" );
Write( "\!n\!n", Left( Load Text File( subdira || "a_new.csv" ), 47 ) );
Write( "\!n\!n", Left( Load Text File( subdirb || "b_new.csv" ), 47 ) );
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.