Skip to content
WJunction - Webmaster Forum

Batch/Shell script (windows) for remove name from folder help

Status
Not open for further replies.

Gon

Experienced Member
582
2014
159
I have very basic knowledge about batch/shell script. i googled a bit if there is any tutorial how to remove name from folder , but i could not find any. i have few folder e.g

Random Folder [WJ]
Random Folder 2 [WJ]
Random Folder 3 [WJ]
i want to remove [WJ] from the folder name. it will be really helpful if someone could help me.
 

4 comments

1) Download Bulk Rename Utility (freeware)
2) Right-click in the root folder which contains the folders you want to rename and choose "Bulk Rename Here"
3) Select all the folders you want to rename and in the field "Replace (3)" write:
Replace --> [WJ]
With --> Don't write anything
 
i know there is renamer app available but which i am looking is shell/batch script to do that.
 
.
Post automatically merged:

Code:
#powershell
$folder_path = "C:\Users\Admin\Desktop\temp"
$replace_search = "\[WJ\]" #\ for escaping special chars
$replace_with= ""

#get all obejcts of type directoy
Get-ChildItem -path $folder_path -Directory | % {
    $folder_object = $_
    $folder_path_destination = $folder_object.Parent.FullName + "\" + $folder_object.Name -replace $replace_search,$replace_with
    
    #check if new path different from the old path
    if($folder_object.FullName -ne $folder_path_destination){
        $folder_object | move-Item -Destination $folder_path_destination
    }
}
 
Last edited:
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