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

Experienced Member
582
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
Experienced Member · Joined
582
Messages
159
Reactions
171
Points
Grow your business

Advertise on WJunction

Connect with an established international community of webmasters, hosting providers, developers and online entrepreneurs.

  • Premium & Premium+ Sticky
  • Dedicated section banners
  • Site-wide banner advertising
Explore advertising options
Back
Top Bottom