移动后重命名文件

编程入门 行业动态 更新时间:2024-10-26 13:31:48
本文介绍了移动后重命名文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我正在尝试使用.cmd文件和.php文件将文件移动到旧文件夹时重命名文件。此文件正在批处理作业中通过电子邮件发送,然后移动到报告结束时的上一个月和当前年份的旧文件夹中。现在:文件正在正确的电子邮件,并移动到旧的文件夹,但文件名不输入旧文件夹时重命名。任何人都可以对我的代码提出任何建议?我似乎找不到错误在哪里。感谢

I'm trying to rename a file while it is being moved into an "old" folder using a .cmd file and a .php file. This file is being e-mailed in a batch job and then moved into the old folder with the previous month and current year at the end of the report. Right now: The files are being e-mail correctly, and moved into the old folder, however the file name is not being renamed when it enters the "old" folder. Can anyone make any suggestions to my code? I can't seem to find out where the error is. Thanks

我的代码为.CMD文件:

My code for .CMD file:

REM Email the 2 monthly stats files regarding gtwinapps REM The report is sent at 9:20 AM every first monday of every month REM in C:\Smurf_Reports\gtwinapps\Monthly_Stats "c:\Program Files\xampp\php\php.exe" d:\batch\monthly_smurfreport_gtwinapps.php move C:\Smurf_Reports\gtwinapps\Monthly_Stats\gtwinapps_statsmonthly.csv C:\Smurf_Reports\gtwinapps\Monthly_Stats\old

我的.PHP文件的代码:

My code for .PHP file:

/*This application pickups up *.csv files from Monthly_Stats folder and then sends email to ops Support at ops.support@scotiabank. The command file associated with this php file moves the .csv file into the "OLD" folder in the same directory */ $dirpath = "C:/Smurf_Reports/gtwinapps/Monthly_Stats/"; /* Renaming the batch job file to display the previous month and year once it is moved into the "OLD" folder for clarity purposes */ rename ("C:\Smurf_Reports\gtwinsapps\Monthly_Stats\gtwinapps_statsmonthly.csv", "C:\Smurf_Reports\ gtwinapps\Monthly_Stats\old\monthly_gtwinapps_" . date("F_Y", strtotime("-1 month")) . ".csv"); rename ("C:\Smurf_Reports\gtwinsapps\Monthly_Stats\monthly.csv", "C:\Smurf_Reports\gtwinapps\Month ly_Stats\old\gtwinapps_statsmonthly_" . date("F_Y", strtotime("-1 month")) . ".csv"); if ($handle = opendir($dirpath )) { $semi_rand = md5(time()); $mime_boundary = "==Multipart_Boundary_x{$semi_rand}x"; $headers .= "\nMIME-Version: 1.0\n" . "Content-Type: multipart/mixed;\n" . " boundary=\"{$mime_boundary}\""; $email_message = "This is a multi-part message in MIME format.\n\n" . "--{$mime_boundary}\n" . "Content-Type:text/html; charset=\"iso-8859-1\"\n" . "Content-Transfer-Encoding: 8bit\n\n" . $message_text . "\n\n"; $email_message .= "--{$mime_boundary}\n"; /* This is the correct way to loop over the directory. */ while (false !== ($entry = readdir($handle))) { if (strpos($entry, '.csv',1)) { $filepath = ""; $filesize = 0; $filepath = $dirpath."".$entry; $filesize = filesize ($filepath); if (file_exists($filepath) && $filesize > 1) { $fileatt = $filepath; $fileatt_name = $entry; $fileatt_type = "application/octet-stream"; $message_text .= "<P>Hi</P>"; $file = fopen($fileatt,'rb'); $data = fread($file,filesize($fileatt)); fclose($file); $data = chunk_split(base64_encode($data)); $email_message .= "Content-Type: {$fileatt_type};\n" . " name=\"{$fileatt_name}\"\n" . "Content-Disposition: attachment;\n" . //" filename=\"{$fileatt_name}\"\n" . "Content-Transfer-Encoding: base64\n\n" . $data . "\n\n"; $email_message .= "--{$mime_boundary}\n"; } $email_from = "ops.support@yahoo"; // $email_to = "ops.support@yahoo"; $email_to = "k.j@yahoo,g.h@yahoo"; $lastMonth = date('F-Y',strtotime('last month')); $email_subject = "($lastMonth) Monthly Smurf Report for GTWINAPPS."; $headers .= "From: ".$email_from."\r\n"; echo $filepath."</br>"; } } closedir($handle); $ok = @mail($email_to, $email_subject, $email_message, $headers); }

推荐答案

c> rename 函数,您需要(A)转义反斜杠( \\ ),或者目录分隔符

In your rename function, you need to either (A) escape your backslashes (\\), or (B) use forward slashes for directory separators

更多推荐

移动后重命名文件

本文发布于:2023-08-01 20:13:01,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1271348.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:重命名   文件

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!