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

Status
Not open for further replies.

Gon

Active Member
537
2014
149
13,900
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
 
.
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.
Back
Top