
批處理怎樣把除第一個子文件夾以外的其他子文件夾內的文件剪切到第一個子文件夾以下是某大神幫我寫的代碼,需要實現將:將當前目錄里除了第一個子文件夾以外的其他子文件夾內的文件剪切后粘貼到第一個子文件夾里,然后刪除第一個子文件夾以外的所有子文件夾但是沒有完全實現,請幫忙看看需要如何修改完善?!謝謝!!!
nclick="copycode($('code0'));">復制代碼
- <# :
- cls&echo off&mode con lines=5000
- rem 將當前目錄里除了第一個子文件夾以外的其他子文件夾內的文件剪切后粘貼到第一個子文件夾里,然后刪除第一個子文件夾以外的所有子文件夾
- set #=Any question&set @=WX&set $=Q&set/az=0x53b7e0b4
- title %#% +%$%%$%/%@% %z%
- cd /d %~dp0
- powershell -NoProfile -ExecutionPolicy bypass Invoke-Command -scriptBlock ([scriptBlock]::Create([IO.File]::ReadAllText('%~f0',[Text.Encoding]::GetEncoding('GB2312')))) -Args '%~f0'
- echo;%#% +%$%%$%/%@% %z%
- pause
- exit
- #>
- $codes=@'
- using System;
- using System.Collections.Generic;
- using System.Runtime.InteropServices;
- public static class ExpDir
- {
- [Dllimport(Shlwapi.dll, CharSet=CharSet.Unicode)]
- public static extern int StrCmpLogicalW(string p1, string p2);
- public static string[] Sort(string[] f)
- {
- Array.Sort(f, StrCmpLogicalW);
- return f;
- }
- }
- '@;
- Add-Type -TypeDefinition $codes;
- [byte[]]$b=@(32,45,45,62,32);
- $c=[Text.Encoding]::Default.GetString($b);
- $self=get-item -liter $args[0];
- $path=$self.Directory.FullName;
- $folders=@(dir -liter $path|?{$_ -is [System.IO.DirectoryInfo]}|%{$_.Name});
- if($folders.length -ge 2){
- $arr=[ExpDir]::Sort($folders);
- for($i=1;$i -lt $arr.count;$i++){
- $folder=$path+''+$arr[$i];
- $files=@(dir -liter $folder -recurse|?{$_ -is [System.IO.FileInfo]});
- for($j=0;$j -lt $files.length;$j++){
- $newpath=$path+''+$arr[0]+$files[$j].Directory.FullName.substring($folder.length);
- if(-not (test-path -liter $newpath)){[void][IO.Directory]::CreateDirectory($newpath)};
- $newname=$files[$j].Name;
- $newfile=$newpath.trimend('')+''+$newname;
- $n=2;
- while(test-path -liter $newfile){
- $newname=$files[$j].baseName+' ('+$n.toString()+')'+$files[$j].Extension;
- $newfile=$newpath.trimend('')+''+$newname;
- $n++;
- }
- $files[$j].FullName.substring($path.length)+$c+$newfile.substring($path.length);
- }
- }
- }

