第一篇文章在这里…如果这格式不正确,我道歉…我将继续努力.我正在开发一个Power shell脚本,它将获取以下信息,以便我可以使用另一个完全适用于此点的批处理文件.随着我对Powershell的
TL:DR Newb与Powershell合作需要帮助
我希望Powershell为不包含任何子文件夹的文件夹中的每个文件输出单行信息.我希望我的txt文件看起来像这样:
file creation date_full path to filename
每行一个文件.稍后将将其解析为文本文件
这是我到目前为止…似乎我只需要一个for循环来运行类似这个psuedocode的东西,我应该很高兴去.在这一点上,任何帮助将不胜感激.
谢谢大家,我希望我不会用格式化来杀死你.
$USS_Folder="path\USS_Files\" $uss_year=#4 digit year of file creation date $uss_month=#2 digit year of file creation date $uss_file=# Full filename including path and Creation_Date New-Item -ItemType directory -Path $USS_Folder\$uss_year\$uss_month Move-Item $uss_file $USS_Folder\$uss_year\$uss_month因此,花了一些时间倾注了许多填充脚本的页面……我想出了下面的解决方案并进行了修改以满足我的需求……我将它用于生产并且效果很好.告诉我你的想法.
<# File modified by Joshua as taken from http://www.marcvalk.net/2012/06/powershell-moving-files-into-subfolder-based-on-date/ Set Variables of Source folder and Destination folder Assign variable of files to be the files with uss extension For each file with uss extension assign the Directory variable the information for file creation year and month if the year and month folder do not exist, then create them from file creation information Move file to sub-folder of year and month from file creation information passed into Directory variable #> $SourceDir = "path to uss files\USS_Files\" $DestinationDir = "path to uss files\USS_Files\" $files = get-childitem $SourceDir *.uss foreach ($file in $files) { $Directory = $DestinationDir + "" + $file.CreationTime.Date.ToString('yyyy') + "\" + $file.CreationTime.Date.ToString('MM-MMM') if (!(Test-Path $Directory)) { New-Item $directory -type directory } Move-Item $file.fullname $Directory }