package com.mindprod.example;
import com.mindprod.commandline.CommandLine;
import com.mindprod.filter.AllButSVNDirectoriesFilter;
import com.mindprod.filter.OnlyFilesFilter;
import java.io.File;
import static java.lang.System.*;
/**
* Converts spaces in filenames to underscores.
*
* @author Roedy Green, Canadian Mind Products
* @version 1.0 2016-10-09 initial version
* @since 2016-10-09
*/
public class NoSpace
{
/**
* List directories and files on command line to correct. -s mean recure dirs to right.
*
* @param args list of dirs and files
*/
public static void main( String[] args )
{
final CommandLine commandLine = new CommandLine( args,
new AllButSVNDirectoriesFilter(),
new OnlyFilesFilter() );
for ( File f : commandLine )
{
final String oldName = f.getName();
final String newName = oldName.replace( ' ', '_' );
if ( !newName.equals( oldName ) )
{
out.println( "renaming " + oldName + " to " + newName );
if ( !f.renameTo( new File( newName ) ) )
{
out.println( "rename failed\n" );
}
}
}
}
}