在遍历文件夹路径时编辑 vbscript - PHP
Editing vbscript while looping through folder path - PHP
我有一个 php 代码,它会循环遍历我的文件夹并同时编辑我的 vbscript。我的代码可以正常工作,但不是我预期的那样。
这是我的 Samplefolders 的内容:
这是我的VB脚本代码:
Option Explicit
Dim oFSO, myFolder
Dim xlCSV
myFolder= "C:/Users/user/Desktop/SampleFolders/20170503/Users/user/Desktop/SampleFolders/20170502/Users/user/Desktop/SampleFolders/20170501"
Set oFSO = CreateObject("Scripting.FileSystemObject")
xlCSV = 6 'Excel CSV format enum
Call ConvertAllExcelFiles(myFolder)
Set oFSO = Nothing
我只希望变量 myFolder 为:
myFolder= "C:/Users/user/Desktop/SampleFolders/20170503"
因为它已经遍历了所有文件夹,这应该是我的最终输出。
你能给我一些提示吗?我认为这与我的循环有关,但我似乎找不到哪里出错了。
这是我的php代码:
$path = "C:/Users/user/Desktop/SampleFolders";
if ($handle = opendir($path)) {
while (false !== ($file = readdir($handle))) {
if ('.' === $file) continue;
if ('..' === $file) continue;
// Read file into array
$data = file('C:/Users/user/Desktop/changecsv.vbs');
// This is the location we want
$newLocation = "C:/Users/user/Desktop/SampleFolders/$file";
// Read each line and try to find the myFolder string
$data = array_map(function($line) use ($newLocation) {
// If we have myFolder make sure it's followed by a path of some kind,
capture
// this path into $matches
preg_match('/myFolder="([A-Za-z:.\\]+)/', $line, $matches);
// Replace old path with new path
if (count($matches)) {
$line = str_replace($matches[1], $newLocation, $line);
}
return $line;
}, $data);
// Replace contents of file with new location
file_put_contents('C:/Users/user/Desktop/changecsv.vbs', implode('', $data));
}
echo "editted";
closedir($handle);
尝试如下修改您的正则表达式,因为您还需要数值和 /
preg_match('#myFolder="([A-Za-z0-9:.\\/]+)#', $line, $matches);
我有一个 php 代码,它会循环遍历我的文件夹并同时编辑我的 vbscript。我的代码可以正常工作,但不是我预期的那样。
这是我的 Samplefolders 的内容:
这是我的VB脚本代码:
Option Explicit
Dim oFSO, myFolder
Dim xlCSV
myFolder= "C:/Users/user/Desktop/SampleFolders/20170503/Users/user/Desktop/SampleFolders/20170502/Users/user/Desktop/SampleFolders/20170501"
Set oFSO = CreateObject("Scripting.FileSystemObject")
xlCSV = 6 'Excel CSV format enum
Call ConvertAllExcelFiles(myFolder)
Set oFSO = Nothing
我只希望变量 myFolder 为:
myFolder= "C:/Users/user/Desktop/SampleFolders/20170503"
因为它已经遍历了所有文件夹,这应该是我的最终输出。
你能给我一些提示吗?我认为这与我的循环有关,但我似乎找不到哪里出错了。
这是我的php代码:
$path = "C:/Users/user/Desktop/SampleFolders";
if ($handle = opendir($path)) {
while (false !== ($file = readdir($handle))) {
if ('.' === $file) continue;
if ('..' === $file) continue;
// Read file into array
$data = file('C:/Users/user/Desktop/changecsv.vbs');
// This is the location we want
$newLocation = "C:/Users/user/Desktop/SampleFolders/$file";
// Read each line and try to find the myFolder string
$data = array_map(function($line) use ($newLocation) {
// If we have myFolder make sure it's followed by a path of some kind,
capture
// this path into $matches
preg_match('/myFolder="([A-Za-z:.\\]+)/', $line, $matches);
// Replace old path with new path
if (count($matches)) {
$line = str_replace($matches[1], $newLocation, $line);
}
return $line;
}, $data);
// Replace contents of file with new location
file_put_contents('C:/Users/user/Desktop/changecsv.vbs', implode('', $data));
}
echo "editted";
closedir($handle);
尝试如下修改您的正则表达式,因为您还需要数值和 /
preg_match('#myFolder="([A-Za-z0-9:.\\/]+)#', $line, $matches);