Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/batch-file/6.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Windows 转换文件夹中的文件列表。。。将逗号分隔转换为管道分隔_Windows_Batch File_Powershell_Csv_Powershell V3.0 - Fatal编程技术网

Windows 转换文件夹中的文件列表。。。将逗号分隔转换为管道分隔

Windows 转换文件夹中的文件列表。。。将逗号分隔转换为管道分隔,windows,batch-file,powershell,csv,powershell-v3.0,Windows,Batch File,Powershell,Csv,Powershell V3.0,我正在编写一个windows批处理脚本,以将管道分隔的文件转换为逗号分隔的文件。当我为单个文件运行它时,它会进行转换,但当我为文件夹中的文件运行它时,它不会 我有为单个文件编写的代码,但它不会在文件夹中循环 @echo off set "INPUT=%C:\temp\source\*.csv" set "OUTPUT=%C:\temp\dest\" setlocal EnableExtensions DisableDelayedExpansion > "%OUTPUT%" (

我正在编写一个windows批处理脚本,以将管道分隔的文件转换为逗号分隔的文件。当我为单个文件运行它时,它会进行转换,但当我为文件夹中的文件运行它时,它不会

我有为单个文件编写的代码,但它不会在文件夹中循环


@echo off

set "INPUT=%C:\temp\source\*.csv"
set "OUTPUT=%C:\temp\dest\"

setlocal EnableExtensions DisableDelayedExpansion



> "%OUTPUT%" (
for %%F in (%*) do
(
    delims^=^ eol^= %%L in ("%INPUT%") do (
        set "LINE=%%L"
        setlocal EnableDelayedExpansion
        echo(!LINE:^|^=,!
        endlocal
    )
)
)
endlocal
exit /B
我想在文件夹中的所有文件上运行脚本

以下是我的两条注释,扩展为多个文件:

$folderPath='C:\temp\source'
$folderPathDest='C:\temp\dest'
获取ChildItem$folderPath-Name-Filter*.csv|
ForEach对象{
$filePath=$folderPath+$_
$filePathdest=$folderPathDest+$_
导入Csv-路径$filePath-分隔符“|”|
导出Csv-路径$filePathDest–非类型信息
}
$folderPath='C:\temp\source'
$folderPathDest='C:\temp\dest'
#由于管道是一个特殊字符,我们需要用反斜杠将其转义
$stringToReplace='\\\'
$stringToAdd=','
获取ChildItem$folderPath-Name-Filter*.csv|
ForEach对象{
$filePath=$folderPath+$_
$filePathdest=$folderPathDest+$_
(获取内容-路径$filePath)-替换$stringToReplace、$stringToAdd|
设置内容-路径$filePathdest
}

在后者中,如果使用+还可以包括
-Raw
选项以
获取内容
,即
(获取内容-Path$filePath-Raw)

,我建议您先修复代码,使其适用于一个文件,然后再扩展为适用于多个文件。另外,由于您得到的文件是
.csv
,因此我建议您使用的
导入csv
导出csv
来执行此任务:
导入csv-路径“”-分隔符“|”|导出csv-路径“”-NoTypeInformation
。即使您的文件不是真的<代码> .CSV ,(分开的双引号字符串),您仍然可以考虑使用<代码> PosithSeal.exe < /C> >:“代码>(获取内容-路径)”-替换“\”、“”、“设置内容-路径”< /代码>。它适用于单个文件。。我希望它在文件夹中运行,并对文件夹中的所有文件执行相同的操作