Computing.Net > Forums > Programming > Srch Rplce Characters in FOLDER Nam

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.

Srch Rplce Characters in FOLDER Nam

Reply to Message Icon

Name: Barnster
Date: June 4, 2008 at 18:47:40 Pacific
OS: Win XP
CPU/Ram: 3Ghz 2GB RAM
Product: Compaq
Comment:

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 (-)



Sponsored Link
Ads by Google

Response Number 1
Name: Mechanix2Go
Date: June 4, 2008 at 19:26:11 Pacific
Reply:

Is this a homework assignment?


=====================================
If at first you don't succeed, you're about average.

M2


0

Response Number 2
Name: Barnster
Date: June 4, 2008 at 19:32:59 Pacific
Reply:

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.


0

Response Number 3
Name: Mechanix2Go
Date: June 4, 2008 at 20:08:17 Pacific
Reply:

@echo off
setLocal EnableDelayedExpansion

for /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


0

Response Number 4
Name: ShaqDiesel
Date: June 6, 2008 at 22:31:12 Pacific
Reply:

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


0

Response Number 5
Name: Barnster
Date: June 9, 2008 at 18:22:03 Pacific
Reply:

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?


0

Related Posts

See More



Response Number 6
Name: Mechanix2Go
Date: June 10, 2008 at 00:45:17 Pacific
Reply:

pushd d:\mystuff


=====================================
If at first you don't succeed, you're about average.

M2


0

Sponsored Link
Ads by Google
Reply to Message Icon






Post Locked

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


Go to Programming Forum Home


Sponsored links

Ads by Google


Results for: Srch Rplce Characters in FOLDER Nam

Null Character in C? (NOT '\0') www.computing.net/answers/programming/null-character-in-c-not-0/3201.html

ASP: Newline characters in bodyText www.computing.net/answers/programming/asp-newline-characters-in-bodytext/9085.html

count # of characters in file + EOF www.computing.net/answers/programming/count-of-characters-in-file-eof/4457.html