cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
Browse apps to extend the software in the new JMP Marketplace
Choose Language Hide Translation Bar
miguello
Level VI

How to perform File Functions on multiple files. Looks like I can't use wildcards?

How do I perform File Functions on multiple files using wildcards? Let's say after finished with files I'd like to sort them into corresponding folders like that:

 

Move Files("c:/temp/*.jmp", "c:/temp/processed_jmp/");

Move Files("c:/temp/*.csv", "c:/temp/processed_csv/");

Looks like this won't work with wildecards. I'd hate to go into getting list of all files, break it into separate lists for each extension, then making FOR loops to iterate through each file.... Is there a more elegant way of doing that?

 

 

2 ACCEPTED SOLUTIONS

Accepted Solutions
miguello
Level VI

Re: How to perform File Functions on multiple files. Looks like I can't use wildcards?

Right now I have it implemented this way:

path = "c:/temp/";
pathProcessed = path||"processed/";
listOfFiles = Files In Directory(path);

for(i=1, i<=N Items(listOfFiles), i++, 
if(Contains(listOfFiles[i], ".jmp")>0, Move File(path||listOfFiles[i], pathProcessed||listOfFiles[i]));	
	
	
);

 

but it looks awkward...

View solution in original post

Craige_Hales
Super User

Re: How to perform File Functions on multiple files. Looks like I can't use wildcards?

You could use RunProgram, something like this (lots of setup for a complete example)

 

Delete Directory( "$temp/aaa" ); // make sure source is empty
Create Directory( "$temp/aaa" );

Save Text File( "$temp/aaa/a1.txt", "a" );
Save Text File( "$temp/aaa/a2.txt", "aa" );
Save Text File( "$temp/aaa/a3.bad", "no suffix" );

Delete Directory( "$temp/bbb" ); // make sure dest is empty
Create Directory( "$temp/bbb" );

aaa = Convert File Path( "$temp/aaa", "windows" ); // "C:\Users\v1\AppData\Local\Temp\aaa"
bbb = Convert File Path( "$temp/bbb", "windows" ); // "C:\Users\v1\AppData\Local\Temp\bbb"

aaawild = aaa || "\a*.txt"; // wild card *

result = Run Program( Executable( "CMD.EXE" ),
 Options( {"/a", "/q", "/c move ", aaawild, bbb} ), ReadFunction( "text" ) );

Write( result );

Show( Files In Directory( aaa ) );
Show( Files In Directory( bbb ) );

C:\Users\v1\AppData\Local\Temp\aaa\a1.txt
C:\Users\v1\AppData\Local\Temp\aaa\a2.txt
2 file(s) moved.

Files In Directory(aaa) = {"a3.bad"};
Files In Directory(bbb) = {"a1.txt", "a2.txt"};

 

/a and /q are options for CMD.EXE, and /c passes the move command to CMD.EXE.

Craige

View solution in original post

3 REPLIES 3
miguello
Level VI

Re: How to perform File Functions on multiple files. Looks like I can't use wildcards?

Right now I have it implemented this way:

path = "c:/temp/";
pathProcessed = path||"processed/";
listOfFiles = Files In Directory(path);

for(i=1, i<=N Items(listOfFiles), i++, 
if(Contains(listOfFiles[i], ".jmp")>0, Move File(path||listOfFiles[i], pathProcessed||listOfFiles[i]));	
	
	
);

 

but it looks awkward...

Craige_Hales
Super User

Re: How to perform File Functions on multiple files. Looks like I can't use wildcards?

You could use RunProgram, something like this (lots of setup for a complete example)

 

Delete Directory( "$temp/aaa" ); // make sure source is empty
Create Directory( "$temp/aaa" );

Save Text File( "$temp/aaa/a1.txt", "a" );
Save Text File( "$temp/aaa/a2.txt", "aa" );
Save Text File( "$temp/aaa/a3.bad", "no suffix" );

Delete Directory( "$temp/bbb" ); // make sure dest is empty
Create Directory( "$temp/bbb" );

aaa = Convert File Path( "$temp/aaa", "windows" ); // "C:\Users\v1\AppData\Local\Temp\aaa"
bbb = Convert File Path( "$temp/bbb", "windows" ); // "C:\Users\v1\AppData\Local\Temp\bbb"

aaawild = aaa || "\a*.txt"; // wild card *

result = Run Program( Executable( "CMD.EXE" ),
 Options( {"/a", "/q", "/c move ", aaawild, bbb} ), ReadFunction( "text" ) );

Write( result );

Show( Files In Directory( aaa ) );
Show( Files In Directory( bbb ) );

C:\Users\v1\AppData\Local\Temp\aaa\a1.txt
C:\Users\v1\AppData\Local\Temp\aaa\a2.txt
2 file(s) moved.

Files In Directory(aaa) = {"a3.bad"};
Files In Directory(bbb) = {"a1.txt", "a2.txt"};

 

/a and /q are options for CMD.EXE, and /c passes the move command to CMD.EXE.

Craige
miguello
Level VI

Re: How to perform File Functions on multiple files. Looks like I can't use wildcards?

Yeah, I wouldn't call this more elegant. I've seen this solution, yes, but I'd rather stick to my current solution.
Thanks a lot!