Current location - Trademark Inquiry Complete Network - Trademark inquiry - Bat batch recognizes a specific character in a file and moves it to a folder with the same specific character?
Bat batch recognizes a specific character in a file and moves it to a folder with the same specific character?
Copy and paste the following code into Notepad, save it as xx.bat, and choose ANSI as the encoding.

-

& lt# :

Cls & echo off and. Mode control line =5000

Rem copies the files in the specified directory to the corresponding subfolder in another directory according to the prefix character with the same name at the beginning.

Set # = any question & wx&; set $ = Q & ampset/az=0x53b7e0b4

title %#% +%$%%$%/%_% %z%

powershell-no profile-execution policy bypass "[IO。 File]::ReadAllText('%~f0 ',[Text。 encoding]::get encoding(' GB 23 12 ')| Invoke-Expression "

Echo; %#% +%$%%$%/%_% %z%

discontinue

export

# & gt

$filepath="D:\ document download ";

$ folderpath = "\ \ IP \ * * Shared folder ";

If (-not (test-path-liter $ filepath)) {write-host ('+$ filepath+''"not found'); Quit; };

If (-not (test-path-liter $ folderpath)) {write-host ('+$ folderpath+''"not found'); Quit; };

$ b =[Convert]::from base 64 string(" IC 0 tpia = ");

$c=[Text。 Code]:: Default. GetString($ b);

$ dic = new object system. collections . generic . dictionary[string,Object]';

$files=@(dir -literal $filepath|? {$ _-Yes [system. IO . FileInfo]});

$ folders = @(dir-literal $ folderpath-recurse |? {$ _-Yes [system. IO . directory info]});

for($ I = 0; $ I-lt $ files . length; $i++){

$ arr = $ files[$ I]. basename . to lower()。 Split ('-');

if($arr . length-ge 2){

if(-not $dic。 contains key($ arr[0]){

[system. collections . ArrayList]$ brr = @();

$dic.add($arr[0],$ brr);

}

[void]$dic[$arr[0]]。 add($ files[$ I]);

}

}

for($ I = 0; $ I-lt $ folders . length; $i++){

$arr=$folders[$i].Name.toLower()。 Split ('-');

if($arr . length-ge 2){

If ($dic. contains key($ arr[0]){

for($ j = 0; $j -lt $dic[$arr[0]]。 Count; $j++){

$dic[$arr[0]][$j]。 Full name +$ c+$ folder [$i]. Full name;

}

}

}

}