PAIP batch renaming JS implementation
Author Attilax, EMAIL: 1466519819@qq.com; 112237553@qq.com
Why JS? Because the script language is more convenient, it is more powerful than dos cmd .. PHP is also acceptable. The environment is too large. In JS, each machine has its running environment, which can be directly written by the master for convenience .. JS is more commonly used than VBS ..
The main process is as follows: Use FSO to perform directory loop, list the file list, and COPY to the specified location .. The file name rule is to add a number to the front, starting from 100. To facilitate sorting ..
Find the renamed software online, or change the main file name. Or add a suffix .. What I need is a prefix number + the original file name ..
-------------R.htm ----------------------
<Meta http-equiv = "content-type" content = "text/html; charset = UTF-8"/>
<Script src = "renamecw.js"> </script>
<Script>
Var dir = "C: \ Users \ attilax \ Desktop \ new folder (2 )";
Dir = "C :\\ korea font ";
Var dircopy2 = "c: \ korea2 ";
RenameC426 (dir );
Document. write ("OK ");
</Script>
-------------- Renamecw..js ----------------
Function renameC426 (dir)
{
Var fso, f1, ts, s;
Var ForReading = 1;
Fso = new ActiveXObject ("Scripting. FileSystemObject ");
Var f = fso. GetFolder (dir );
Var fc = new Enumerator (f. files );
Var n = parseInt (100 );
For (;! Fc. atEnd (); fc. moveNext ())
{
N ++;
Var file = fc. item ();
Var extname = getExtname (file );
Var mainname = getMainname (file );
Var newfilename = dircopy2 + "\" + n + mainname + "." + extname;
// Document. write (newfilename + "<p> ");
File. copy (newfilename );
}
}
Function getExtname (file)
{
Var arr = file. name. split (".");
Return arr [1];
}
Function getMainname (file)
{
Var arr = file. name. split (".");
Return arr [0];
}