将文件移到包含部分文件名的现有文件夹中 [英] Move files into existing folders containing part of the filename

查看:52
本文介绍了将文件移到包含部分文件名的现有文件夹中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您可能认为这是重复的帖子,但是我已经发表了两天了.我尝试了filebot,filejuggler,robobasket,moveout和高级重命名器.我在网上搜索了所有内容,但没有任何解决方法可以解决我的问题.

You would think that this is a duplicate post, but I have been on this for 2 days now. I have tried filebot, filejuggler, robobasket, moveout and advanced renamer. I have searched all over the web, and nothing fixes my problem.

我有一个名为 12345678.txt 的文件,并希望将其移至目录 C:\ folders \ 12345678-bla bla bla \

I have a file named 12345678.txt, and want to move it into the directory C:\folders\12345678-bla bla bla\

我尝试过的所有操作都将文件移动到与文件名完全相同的文件夹中.但是,我的文件夹在文件名之后还有其他角色.

Everything I tried moved the file into a folder it created with the exact same name as the file. However my folder has other caracters after the name of the file.

这是确切的实际情况:

在此目录中: C:\ F \Répertoires\ FISCALITE \ T2 \ 2020 我有一些文件,其客户端编号例如 75063420.txt .我需要将该文件移到该文件夹​​中: C:\ F \Répertoires\ CLIENTS \ 750634_Entreprises nameofcompany \

In this directory: C:\F\Répertoires\FISCALITE\T2\2020 I have files named with the client number e.g. 75063420.txt. I need to move that file into this folder: C:\F\Répertoires\CLIENTS\750634_Entreprises nameofcompany\

因此,只需要文件名的前 6 个字符即可匹配名称比文件名更多的现有文件夹.

So only the first 6 characters of the filename are needed to match the existing folder where the name has more characters than the filename.

我可能要移动5000个文件,并且需要一种自动化的方式.

I have maybe 5000 files to move and need an automated way of doing it.

推荐答案

这是执行此操作的强大方法,而没有任何错误或冲突处理,例如具有相同的六个起始字符的多个客户端目录或客户端文件夹中已经存在的文件

This is a powershell way to do this without any error or conflict handling like multiple client directories with the same six starting characters or files that exist already in the client folder.

$FilesToMove = 'C:\F\Répertoires\FISCALITE\T2\2020'
$TargetPath = 'C:\F\Répertoires\CLIENTS'

$Files = Get-ChildItem -Path $FilesToMove -File

foreach ($File in $Files) {
    $PathToMove = Get-ChildItem -Path $TargetPath -Directory -Filter "$(($File.Basename).Substring(0,6))*" | Select-Object -First 1
    Write-Output "Moving File $File to $PathToMove"
    Move-Item -Path $File.FullName -Destination "$($PathToMove.Fullname)\$($File.Name)"
}

这篇关于将文件移到包含部分文件名的现有文件夹中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆