Batch script (windows) for remove folder charecter length after x number character

Status
Not open for further replies.

Gon

Active Member
538
2014
149
14,110
there is multiple folder which character length is more than 200. can we remove all character after x number character using batch script?
 
3 comments
Code:
#powershell
$folder_path = "C:\Users\Admin\Desktop\temp"
$max_name_length = 200

#get all objects of type directoy from path
Get-ChildItem -path $folder_path -Directory | % {
    $folder_object = $_

    #check if foldername too long
    if($folder_object.Name.Length -gt $max_name_length){
        $folder_path_destination = $folder_object.Parent.FullName + "\" + $folder_object.Name.substring(0,$max_name_length)
        $folder_object | move-Item -Destination $folder_path_destination
    }
}
 
Code:
#powershell
$folder_path = "C:\Users\Admin\Desktop\temp"
$max_name_length = 200

#get all objects of type directoy from path
Get-ChildItem -path $folder_path -Directory | % {
    $folder_object = $_

    #check if foldername too long
    if($folder_object.Name.Length -gt $max_name_length){
        $folder_path_destination = $folder_object.Parent.FullName + "\" + $folder_object.Name.substring(0,$max_name_length)
        $folder_object | move-Item -Destination $folder_path_destination
    }
}

Nice one, I save it too, maybe I will need it in future.
 
Status
Not open for further replies.
Back
Top