Tom's Guide | Tom's Hardware | Tom's Games
![]() |
![]() |
![]() |
Wondering if some one can help me write a batch job to execute the following.
Need to point script to a root folder.
Script scans all sub-folders.
Searches for the period character (.) and replaces it with dash character (-) however ONLY on FOLDER NAMES.
Script MUST NOT rename files ONLY FOLDERS NAMES.
Ideally can specify what the search character is, even possibility of specifying multiple characters. E.g replace (.) (:) (;) all with (-)

Is this a homework assignment?
=====================================
If at first you don't succeed, you're about average.M2

No not at all, we have a mixed environment (Mac & PC). I have an automated file/folder delete routine whereby if file date over 30 days old it is deleted. However system has issues deleting folders if the folder name contains any period characters. Which is why i want to run a script to search and replace these characters in folder names first, before file/folder deletion is executed.

@echo off
setLocal EnableDelayedExpansionfor /f "tokens=* delims= " %%a in ('dir/b/s/ad ^| find "."') do (
set str=%%~NXa
set str=!str:.=-!
echo ren %%a !str!
)
=====================================
If at first you don't succeed, you're about average.M2

on the unix command line:
find . -type d -exec sed -i.ori 's/[.:;]/-/g' {} \;
This should find all directories starting at your current directory and if it finds the regex in the character class it will replace it.
Correct me if I'm wrong but I believe even if there is both a ':' and a ';' it will replace both with a '-'
Suppose the regex to search for was longer, is there another way to replace multiple matches other than using the -e option and retyping the s/old/new command again? For example:
sed -e 's/dog/cat/g'; 's/moose/bear/g' file

Sorry A little lost as to how do I use these commands, I have created a batch file 'RemoveUnwantedCharacetrs.cmd' and copied this text string into it, how do I specify the root folder where i want this to execute from?

pushd d:\mystuff
=====================================
If at first you don't succeed, you're about average.M2

![]() |
![]() |
![]() |

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.
| Ads by Google |