cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
Try the Materials Informatics Toolkit, which is designed to easily handle SMILES data. This and other helpful add-ins are available in the JMP® Marketplace
Choose Language Hide Translation Bar
dadawasozo
Level IV

go through each zip folder to get list of files name from it and save in a single table

Hi,

I need some help here. I tried to write the jsl but I got stuck and hope someone can guide me here.

I have a directory that contain 10000+ zipped folders. Each zipped folder has 100+ files.

I want to do task below without unzip WITHOUT UNZIP the zipped folders.
1) get the name of each zipped folder.

2) get into individual zipped folder.

3) get the files in the zipped folder.

4) in a table, add the zipped folder name in column 1 and its files name in column 2.

5) repeat step 1)-4) for the next zipped folder until all done.

 

Thanks in advance

 

 

4 REPLIES 4
jthi
Super User

Re: go through each zip folder to get list of files name from it and save in a single table

Check out fairly new Uncharted blog post MFI from Selected CSVs in a ZIP . It might give some quite good ideas how to approach this.

Scripting Index seems to have also documentation on ZipArchive:

jthi_1-1638289510815.png

 

 

-Jarmo
txnelson
Super User

Re: go through each zip folder to get list of files name from it and save in a single table

Here is a simple script that I threw together, using previous Community entries that dealt with zip files.  See if it works for you.

Names Default To Here( 1 );
directory = Pick Directory( "Select Directory that contains the Zip files" );
folders = Files In Directory( directory );

dt = New Table( "Zip Files",
	New Column( "Folder Name", character ),
	New Column( "File Name", character )
);


For( i = 1, i <= N Items( folders ), i++,
	If( Word( -1, folders[i], "." ) == "zip",
		theFolder = Open( directory || folders[i], zip );
		dirList = theFolder << dir;
		For( k = 1, k <= N Items( dirList ), k++,
			dt << add rows( 1 );
			numRows = N Rows( dt );
			dt:Folder Name[numRows] = folders[i];
			dt:File Name[numRows] = dirList[k];
		);
	)
);
Jim
dadawasozo
Level IV

Re: go through each zip folder to get list of files name from it and save in a single table

 Hi, I able to get the list of filenames. I want to add the step open file that contains specific string from each zipped folder and later concate all into one table. I modified the script as below, but it dont seems opening those files (there are totally 6000+ of it). the 6000+ files that the filename contain "rag" are ".log" type file.
is there a way I can keep append the file into the same table without having open all 6000+ files then only concate?

 

path ="C:\Users\Desktop\test\";

folders = Files In Directory( path );

 

tables={};

For( i = 1, i <= N Items( folders ), i++,
      If( Word( -1, folders[i], "." ) == "zip",
      theFolder = Open( path || folders[i], zip );
      dirList = theFolder << dir;
           For( k = 1, k <= N Items( dirList ), k++,
                If (contains(dirlist[i], "rag"),
                rag_file = theFolder << read(dirList[i], format(blob));
                Open(path || folders[i] ||"\" || rag_file);

                Insert Into(tables, data table(path || folders[i]));
                  );
            );

       );
);

 

dt = New Table ("all_rag_files");

dt << concatenate(tables, append to first table( 1 ), create source column);

ian_jmp
Level X

Re: go through each zip folder to get list of files name from it and save in a single table

This code might get you started:

NamesDefaultToHere(1);

myFolder = PickDirectory("Pick Folder", "$DESKTOP");
zipList = FilesInDirectory(myFolder);

col1Vals = {};
col2Vals = {};
for(z=1, z<=NItems(zipList), z++,
	filePath = myFolder||"/"||zipList[z];
	thisZIP = Open(filePath, zip);
	filesInThisZIP = thisZIP << dir;
	for(f=2, f<=NItems(filesInThisZIP), f++,
		if(NItems(Words(filesInThisZIP[f], "/")) == 2,
			InsertInto(col1Vals, zipList[z]);
			InsertInto(col2vals, filesInThisZIP[f]);
			);
		);
	Close(thisZIP, noSave);
	);

NewTable("Folder of ZIP Files",
	NewColumn("Folder Name", Character, Values(col1Vals)),
	NewColumn("File Name", Character, Values(col2Vals))
	);