---
# System prepended metadata

title: DOS 指令
tags: [DOS語法]

---

# DOS 指令
###### tags: `DOS語法`

### 情境：
單一 Folder 下又有很多小Folder，每個小 Folder 又有各自的 CSV 檔案，要根據每個小 Folder 檔名帶有的日期去做截取，然後拿來做更改小 Folder 檔名用。
```
$folder_path = "C:\Users\andy_chen\Desktop\TEST"
$path = get-childitem -path $folder_path

foreach ($folder in $path)
{
	$new_folder_path = $folder
	$new_path = get-childitem -path $new_folder_path
	
	foreach ($file in $new_path){
		$time = $folder.name
		$time = $time.substring($time.IndexOf("_"), 9)
		$newFileName = $file.BaseName + $time +".txt"
		Rename-Item   $file.FullName $newFileName
	}
}

```
![](https://i.imgur.com/iUsbIPQ.png)

