Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

Rename Files Instantaneously

Posted on 2006-05-25
11
Medium Priority
?
1,412 Views
Last Modified: 2013-12-28
I have a folder in which so many files
and there are all files name starting with "COMPACT -"
its mean all files names are like this..
COMPACT - *************
COMPACT - XXXXXXXXXXXX
COMPACT - YYYYYYYYYYYY
COMPACT - ZZZZZZZZZZZZ

I want to remove COMPACT - FROM THE ALL FILES
I dont want to use any third party software
I want to ask any command or batch file method?

Thanks
Rashid
0
Comment
Question by:Mateen
  • 4
  • 4
  • 2
  • +1
11 Comments
 
LVL 29

Expert Comment

by:blue_zee
ID: 16764468
Free tools:

Renamer v6.0
http://www.albert.nu/programs/renamer/main.htm

1-4a-rename
http://www.1-4a.com/rename/

Irene - Rename Wizard
http://www.gomiller.com/downloads/irene.html

Hope one of these fits your plan.

Cheers,

Zee
0
 

Author Comment

by:Mateen
ID: 16766809
Thanks for your reply but,
I dont want to use any tools , I want to use any rename command or replace command.
if this were text in Ms Word we can easily replace it with replace (F5) command.
just like this
Find What     =  COMPACT -
Replace with =  ''

Thanks
Rashid
0
 
LVL 3

Expert Comment

by:BenReynolds
ID: 16768233
Try these links
http://www.computing.net/dos/wwwboard/forum/14607.html
and
http://www.computing.net/dos/wwwboard/forum/14574.html (need to scroll down some ways to the good stuff)

Why don't you want to use tools?
0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
LVL 30

Accepted Solution

by:
callrs earned 2000 total points
ID: 16770734
OK. It took all night -- over 6 hours. But here they are. One to add & one to subtract a prefix/delimiter combination.
Sample use, assuming the file extension is ".txt":
Subtract:  renlef- COMPACT - txt
Add back: renlef+ COMPACT - txt 1

=================================================renlef+.bat
:: renlef+.bat
:: Prefix ADD utility for file names: Adds the specified prefix and delim (& optionally isolates delim by spaces) to all files that have specified extension
:: Doesn't perform the rename, but generates &  writes the commands to a bat file
:: If prefix+delim is already in the original name, then ignores the file unless doall=1
::
:: Arguments:
::   %1 - Prefix to add
::   %2 - Delimiter to add
::   %3 - Extension of file
::   %4 - Space - Set to 1 to add space to both sides of delim
::   %5 - Doall - See "If prefix+delim..." note above
::
:: v1.0  Written by Ravinder Singh ('wiz' on the quickmacros forum), May 26, 2006
::
::
:: if exists renlef+_.bat goto FILEEXISTS
@echo off
setlocal
set outfile=renlef+_
if exist "%outfile%.bat" del "%outfile%.bat"
if %1.==. (set /a exitcode=98&goto USAGE)
if %2.==. (set /a exitcode=98&goto USAGE)
set adn=%1&set delm=%2&set ext=%3&set space=%4&set doall=%5&&set count=0
if %doall%.==1. goto SIMPLE

for %%a in (*.%ext%) do (
if %space%.==1. (
      echo %%a| find "%adn% %delm% "
      if errorlevel 1 (set /a count+=1&echo ren "%%a" "%adn% %delm% %%a"  >> "%outfile%.bat" ))
if NOT %space%.==1. (
       echo %%a | find "%adn%%delm%"
      if errorlevel 1 (set /a count+=1&echo ren "%%a" "%adn%%delm%%%a" >> "%outfile%.bat"      ))
)
goto :DONE
:SIMPLE
::  separated routine here because wasn't able to integrate because of weird behaviour in msdos on Win2K
:: e.g. if you SET XX=YY, then echo "%XX%" doesn't give us XX's value within a FOR loop, but only on exit from loop
for %%a in (*.%ext%) do (
      set /a count+=1
      if %space%.==1. echo ren "%%a" "%adn% %delm% %%a"  >> "renlef+_.bat"
      if NOT %space%.==1.       echo ren "%%a" "%adn%%delm%%%a" >> "renlef+_.bat")

:DONE
if %count%==0 (
      echo No files found that match criteria.&echo.
      set /a exitcode=97
      goto usage
      )
type renlef+_.bat
echo.
echo type: %outfile%         To rename the above %count% files files! Or edit %outfile%.bat
goto :EOF

:USAGE
echo USAGE: %~nx0  WHAT-TO-APPEND-TO-LEFT   DELIMETER   EXTENSION  SPACE? ALL?
exit /B %exitcode%

:FILEEXISTS
echo renall.bat exists. (Check & ) Delete file first.
exit /B 99

=========================================================renlef-.bat
:: renlef-.bat
::  - Prefix REMOVAL utility for file names: Cuts the specified prefix that precedes a space and/or the specified delimiters in a file name
:: As a precaution:
:: -- All rename commands are generated & then displayed on screen
:: -- All rename commands are written to a file which can be run  (after any optional or required user's edits)
::
:: Arguments:
::    %1 - Word to remove
::    %2 - Optional delimiters, in addition to the default space, that separate %1 from the part you want to keep
::    %3 - Extension of file
::
:: E.g. to remove initial "PART" from all files that start with "PART # ":
::     renlef- PART #
::
:: v1.0  Written by Ravinder Singh ('wiz' on the quickmacros forum), May 26, 2006
::
@echo off
setlocal
if %1.==. (set /a exitcode=98&goto usage)
set cut=%1&set delims=%2&set ext=%3&set outfile=renlef-_&set count=0
if exist "%outfile%.bat" del "%outfile%.bat"
::if not exist  "%outfile%.bat" set writeToFile=1
set writeToFile=1

:: Let user see and verify all rename commands before we execute them
for /f "usebackq delims=" %%i in (`dir /b %cut%*.%ext%`) do @call :TEST "%%i"

if %count%==0 (
      echo No files found that match criteria.&echo.
      set /a exitcode=97
      goto usage
      )
echo.
echo type: %outfile%           To rename the above %count% files! Or edit %outfile%.bat
goto :EOF
::1*

:TEST
set /a count+=1
set name=%1
FOR /f  "usebackq tokens=1,2,3 delims=%delims% " %%j IN (`echo %name%`) DO @set mycommand=ren %name% "%%k
echo %mycommand%
if %writeToFile%==1 echo %mycommand% >> %outfile%.bat
goto :EOF

:usage
echo usage: %~nx0   LEFT-TRIM-STRING   DELIMS    EXTENSION
exit /B %exitcode%

:: Other notes
::
:: original basic routine, with delimiters being "- "
::for /f "usebackq tokens=1,2,3  delims=- " %%i in (`dir /b %1*`) do echo ren "%%i - %%j" "%%j"
::
:: 1* -- Optional code, can use if you don't want to create %output%.bat
:: Now prompt whether or not to do the batch rename
echo (1) Hit CTRL-C  (2) Hit Y to end program, or N to execute the above rename commands!
for /F "tokens=*" %%A in ('more') DO set input=%%A
for /f "usebackq delims=" %%i in (`dir /b %cut%*.%ext%`) do @call :RENAMEALL "%%i"
goto :EOF
:RENAMEALL
set name=%1
FOR /f  "usebackq tokens=1,2,3 delims=%delims% " %%j IN (`echo %name%`) DO ren %name% "%%k
goto :EOF

:: Like what you see? Pay back the earth that fed me :)  Compost, eat less meat, ride a bike...
0
 
LVL 30

Expert Comment

by:callrs
ID: 16772303
Thanks for the grade.
But the code above doesn't work on Win98. It uses advanced syntax that will work on Win2K and XP (and on NT? I don't know)
What you want done may be impossible, or would require a lot more MSDOS knowledge than most people have, to do in Win98 using just pure MSDOS -- You'd need to use another language like Windows Scripting Host (WSH) or make a compiled program using C, C++, VB, etc. which are actually so much easier to code in than in MSDOS.
I could try to do the WSH solution, since WSH is part of Win98 and can be run almost like an MSDOS script. I'll have to bit of learning to do to do it, but I love learning.

I'll post elsewhere later other MSDOS renaming code & info.

Did you need a solution for Win2k or XP? If you need a solution for Win98 as well, let me know...

0
 
LVL 29

Expert Comment

by:blue_zee
ID: 16772377

It is impossible in "oldish" MS-DOS.

Zee
0
 
LVL 29

Expert Comment

by:blue_zee
ID: 16772398

But it fails my understanding why poster does not want to use one of the many FREE available tools...

Zee
0
 
LVL 30

Expert Comment

by:callrs
ID: 16772519
One reason for a non-third-party solution:

"Adam314, it works great. Thanks a ton! Full points to you.

"MahmoudAbdElSattar, we did try some software already and didn't have any luck. I bet the software you mentioned is more robust, but we want to be able to do this in the future from many machine without having to install any software, hense the request for a batch. Thank you for the suggestion though."
From http://www.experts-exchange.com/Programming/Q_21506296.html     Programming: Batch renaming

In which the post also mentions "Lupas Rename 2000" http://www.azheavymetal.com/~lupasrename/lupasrename.php
0
 
LVL 29

Expert Comment

by:blue_zee
ID: 16772552

IMO, forgive me, not a good enough reason, and even less important inthis specific question, but then it's only me thinking and typing...
;-)
0
 

Author Comment

by:Mateen
ID: 16780200
This is very easy to search , install and rename with any third-party solution, so
if i need any tools for renaming i dont post this question here.
Thanks callrs you gave me very constructive information


0
 
LVL 30

Expert Comment

by:callrs
ID: 16825585
http://www.experts-exchange.com/Operating_Systems/MSDOS/Q_21873735.html     "RENAME FILES USING PURE MS-DOS"
Version 1.01 posted there vs. v1.0 here:
1) echoing the '&' sign:        echo ...&...   must instead be:  echo ...^&...
2) Better user-input method: set /p input=Enter y to execute the above commands, anything else to quit:





0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This is an article on how to answer questions, earn points and become an expert.
This article is about my experience upgrading my consulting machine to Windows 10 Version 1709 (The Fall 2017 Creator Update)
In this video, we discuss why the need for additional vertical screen space has become more important in recent years, namely, due to the transition in the marketplace of 4x3 computer screens to 16x9 and 16x10 screens (so-called widescreen format). …
In this video, viewers are given an introduction to using the Windows 10 Snipping Tool, how to quickly locate it when it's needed and also how make it always available with a single click of a mouse button, by pinning it to the Desktop Task Bar. Int…

580 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question