本文介绍了获取文件名,并追加到行首的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想获得一个文本文件并排侧文​​件的路径和文件名,这样我就可以使插入到数据库更容易。我已经采取了看周围的SO其他的例子,但我一直无法理解到底是怎么回事。比如,我看到这个batch文件追加文件名结束,但想通,我不应该要求澄清行,因为它是0-1.5岁。

I'm trying to get a side-by-side file path and file name in a text file so I can make inserting into a database easier. I've taken a look at other examples around SO, but I haven't been able to understand what is going on. For instance, I saw this batch file to append file names to end of lines but figured that I shouldn't ask for clarification because it's 1.5 years old.

我有什么是文件路径的文本文件。他们看起来是这样的:

What I have is a text file of file paths. They look like this:

\\\\ PROE \\ igi_files \\ TIFF格式\\ AD \\ 1_SIZE_AD \\ 1AD0019.tif

我希望它看起来就像是这样的:

What I want it to look like is this:

1AD0019.tif \\\\ PROE \\ igi_files \\ TIFF格式\\ AD \\ 1_SIZE_AD \\ 1AD0019.tif

,这样我可以将其插入到数据库中。有没有一种简单的方法通过批处理文件来做到这一点在Windows?

so that I can insert it into a database. Is there an easy way to do this on Windows via Batch files?

推荐答案

在PowerShell中,这个脚本应该做的伎俩。在第一行中,只是指定包含全部文件路径的文本文件的名称

In powershell, this little script should do the trick. In the first line, just specify the name of the text file that contains all the file paths.

$filelist="c:\temp\filelist.txt"
foreach($L in Get-Content $filelist) {
  $i = $L.length - $L.lastindexof('\') -1
  $fname=$L.substring($L.length - $i, $i)
  echo ($fname + ' ' + $L)
}

如果你没有你的机器上安装了PowerShell,请。

If you don't have powershell installed on your machine, check out http://technet.microsoft.com/en-us/library/hh847837.aspx.

这篇关于获取文件名,并追加到行首的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-05 23:20