Skip to content
WJunction - Webmaster Forum

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

Status
Not open for further replies.

Gon

Active Member
581
2014
159
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.

About the author

G
Active Member · Joined
581
Messages
159
Reactions
43
Points

Advertise on WJunction

Reach 1000's of webmasters, hosts & affiliates. Banner & sponsored-thread slots available.

Contact us
Back
Top Bottom