将指定文件夹下的psd文件放到指定目录--内含文件批处理类
2006-04-10 13:25
465 查看
acdsee8,打开psd文件所在文件夹,全选所有psd文件,右健-〉工具-〉文件格式转换
fireworks8文件-〉批处理
fireworks的批处理在处理psd文件导出为jpg的时候,总是弹出字体不存在要你确认的对话框
acdsee则不会。
<?php
return; //2006-04-10
/*
批量处理,将psd文件都放到指定目录
*/
class batchFile{
var $version='0.2' // 此版本修改了算法,使dir列表和file列表均为相对于path /fd/fdsf/fds.txt.....
var $path=null;
var $deepLimit = 0;//目录深度,为1,表示第一层。
var $filterPath=''; //过滤的目录
var $ignoreFile = ''; //过滤的文件
var $extname=null; //有效文本文件的扩展名。
var $dir=array();
var $file=array();
function start(){
$current = $this->path;
//\0、\a、\b、\f、\n、\r、\t 和 \v
$current = str_replace("\\", "/", $current);
$current = preg_replace("/\/+/", "/", $current);
$current = preg_replace("/\/$/", "", $current);
$this->path = $current;
if(!is_dir($current)){
echo "<h1><font color=red>you must set the right dir</font></h1>\n";
return;
}
$this->execute();
}
/** 函数 execute( $dirName = null )
* 功能 对目录下所有文件及子目录下所有文件进行操作
* 参数 $dirName 目录名称
*/
function execute( $dir ='', $dirdeep = 1)
{
$dirName = $this->path.$dir;
if( empty( $dirName ) )
exit( "IBFileSystem: directory is empty." );
if( is_dir( $dirName ) )
{
if( $dh = opendir( $dirName ) )
{
while( ( $file = readdir( $dh ) ) !== false )
{
if( $file != "." && $file != ".." )
{
$filePath = $dir . "/" . $file;
$fileAbsPath = $this->path . $filePath;
//echo $dir."<br>";
if( is_dir( $fileAbsPath ) )//为目录,递归
{
$this->dir[]=$filePath;
$nextDeep = $dirdeep+1;
if ( $this->deepLimit ==0 || $nextDeep<=$this->deepLimit)
{
$pos = strpos($this->filterPath,$file);
//echo $filePath."<br>";
if ($pos===false) {
$this->execute( $filePath , $nextDeep);
}
}
}
else//为文件,进行处理
{
//如果包括全部文件
if ($this->extname=="*") {
$this->file[]=$filePath;
}
else {
$dotpos = strrpos($file,".");
if ($dotpos!==false) {
$extname = substr( $file,$dotpos+1);
$pos = strpos( $this->extname , ";".$extname.";" );
if ($pos!==false) {
$this->file[]=$filePath;
}
}
}
} //文件处理结束
}
}
closedir( $dh );
}
else
{
exit( "IBFileSystem: can not open directory $dirName.");
}
//返回当前的$tree
//return $tree;
}
else
{
exit( "IBFileSystem: $dirName is not a directory.");
}
}//</listDirTree>
/**
* mkdirp is used to instead of mkdir ,mkdirp can create deep multiple directory.
*/
function mkdirp($target) {
// If the path already exists && is a directory, all is well.
// If the path is not a directory, we've a problem.
if (file_exists($target)) {
if (!is_dir($target)) return false;
else return true;
}
// Attempting to create the directory may clutter up our display.
if ( @mkdir($target) ) return true;
// If the above failed, attempt to create the parent node, then try again.
if ( $this->mkdirp(dirname($target)) ) return $this->mkdirp($target);
return false;
}//</function mkdirp>
}// end class
require_once("echo.php");
$fl = new batchFile();
$fl->extname ="*"; //the file type need to be operated
$fl->deepLimit = 0;
$fl->path='D:\web\mambog_corp\模版-html\psd'; //operate dir
$fl->filterPath='_vti_cnf'; //ignored dir
$fl->start();
$outpath = 'D:/web/mambog_corp/模版-html/psdout/';
foreach ($fl->file as $file) {
$path_parts = pathinfo($file);
if( $path_parts["extension"] =='url' || $path_parts["extension"] =='txt'){
unlink($fl->path.$file);
}else {
$nfile = str_replace("/","_",$file);
$nfile = $outpath.$nfile;
//echo $nfile."<br>\n";
rename( $fl->path.$file, $nfile);
}
}
//prt($fl);
?>
fireworks8文件-〉批处理
fireworks的批处理在处理psd文件导出为jpg的时候,总是弹出字体不存在要你确认的对话框
acdsee则不会。
<?php
return; //2006-04-10
/*
批量处理,将psd文件都放到指定目录
*/
class batchFile{
var $version='0.2' // 此版本修改了算法,使dir列表和file列表均为相对于path /fd/fdsf/fds.txt.....
var $path=null;
var $deepLimit = 0;//目录深度,为1,表示第一层。
var $filterPath=''; //过滤的目录
var $ignoreFile = ''; //过滤的文件
var $extname=null; //有效文本文件的扩展名。
var $dir=array();
var $file=array();
function start(){
$current = $this->path;
//\0、\a、\b、\f、\n、\r、\t 和 \v
$current = str_replace("\\", "/", $current);
$current = preg_replace("/\/+/", "/", $current);
$current = preg_replace("/\/$/", "", $current);
$this->path = $current;
if(!is_dir($current)){
echo "<h1><font color=red>you must set the right dir</font></h1>\n";
return;
}
$this->execute();
}
/** 函数 execute( $dirName = null )
* 功能 对目录下所有文件及子目录下所有文件进行操作
* 参数 $dirName 目录名称
*/
function execute( $dir ='', $dirdeep = 1)
{
$dirName = $this->path.$dir;
if( empty( $dirName ) )
exit( "IBFileSystem: directory is empty." );
if( is_dir( $dirName ) )
{
if( $dh = opendir( $dirName ) )
{
while( ( $file = readdir( $dh ) ) !== false )
{
if( $file != "." && $file != ".." )
{
$filePath = $dir . "/" . $file;
$fileAbsPath = $this->path . $filePath;
//echo $dir."<br>";
if( is_dir( $fileAbsPath ) )//为目录,递归
{
$this->dir[]=$filePath;
$nextDeep = $dirdeep+1;
if ( $this->deepLimit ==0 || $nextDeep<=$this->deepLimit)
{
$pos = strpos($this->filterPath,$file);
//echo $filePath."<br>";
if ($pos===false) {
$this->execute( $filePath , $nextDeep);
}
}
}
else//为文件,进行处理
{
//如果包括全部文件
if ($this->extname=="*") {
$this->file[]=$filePath;
}
else {
$dotpos = strrpos($file,".");
if ($dotpos!==false) {
$extname = substr( $file,$dotpos+1);
$pos = strpos( $this->extname , ";".$extname.";" );
if ($pos!==false) {
$this->file[]=$filePath;
}
}
}
} //文件处理结束
}
}
closedir( $dh );
}
else
{
exit( "IBFileSystem: can not open directory $dirName.");
}
//返回当前的$tree
//return $tree;
}
else
{
exit( "IBFileSystem: $dirName is not a directory.");
}
}//</listDirTree>
/**
* mkdirp is used to instead of mkdir ,mkdirp can create deep multiple directory.
*/
function mkdirp($target) {
// If the path already exists && is a directory, all is well.
// If the path is not a directory, we've a problem.
if (file_exists($target)) {
if (!is_dir($target)) return false;
else return true;
}
// Attempting to create the directory may clutter up our display.
if ( @mkdir($target) ) return true;
// If the above failed, attempt to create the parent node, then try again.
if ( $this->mkdirp(dirname($target)) ) return $this->mkdirp($target);
return false;
}//</function mkdirp>
}// end class
require_once("echo.php");
$fl = new batchFile();
$fl->extname ="*"; //the file type need to be operated
$fl->deepLimit = 0;
$fl->path='D:\web\mambog_corp\模版-html\psd'; //operate dir
$fl->filterPath='_vti_cnf'; //ignored dir
$fl->start();
$outpath = 'D:/web/mambog_corp/模版-html/psdout/';
foreach ($fl->file as $file) {
$path_parts = pathinfo($file);
if( $path_parts["extension"] =='url' || $path_parts["extension"] =='txt'){
unlink($fl->path.$file);
}else {
$nfile = str_replace("/","_",$file);
$nfile = $outpath.$nfile;
//echo $nfile."<br>\n";
rename( $fl->path.$file, $nfile);
}
}
//prt($fl);
?>
相关文章推荐
- C# 拷贝指定文件夹下的所有文件及其文件夹到指定目录
- 使用Python脚本删除指定文件夹下的指定目录及其文件
- 将java的class文件放到一个指定文件夹下
- CE中将PC上指定文件加入NK, 并放到目标机上指定目录
- Java遍历列出某一目录下的文件及文件夹,寻找某一指定文件
- 预编译加速编译(precompiled_header),指定临时文件生成目录,使项目文件夹更干净(MOC_DIR,RCC_DIR, UI_DIR, OBJECTS_DIR),#pragma execution_character_set("UTF-8")"这个命令是在编译时产生作用的,而不是运行时
- 使用CMD模式批量删除指定目录(支持目录中多层文件夹嵌套)下指定格式文件
- [No000073]C#直接删除指定目录下的所有文件及文件夹(保留目录)
- asp.net 删除文件夹,指定文件夹,删除文件夹和所有文件,删除权限设置,递归删除文件夹目录及文件
- Asp.net获取服务器指定文件夹目录文件并提供下载的方法
- 转载:C# 将引用的DLL文件放到指定的目录下
- Java中如何利用File类递归的遍历指定目录中的所有文件和文件夹
- CE中将PC上指定文件加入NK, 并放到目标机上指定目录
- C# 将引用的DLL文件放到指定的目录下和后期生成事件命令行
- android:将assets目录下的文件(文件夹)放置到内存卡指定目录下
- 递归函数,打印指定文件目录下的文件夹和文件名,各子文件夹下也要打印出来
- php删除指定目录下的的文件/文件夹-用PHP怎么删除某目录下指定的一个文件/文件夹?
- list.c---unix/linux下显示指定目录中的文件/文件夹
- 通过递归查询指定目录下的所有文件和子文件夹下的指定文件名
- 通过递归查询指定目录下的所有文件和子文件夹下的指定文件名