Join the Stack Overflow Community
Stack Overflow is a community of 6.8 million programmers, just like you, helping each other.
Join them; it only takes a minute:
Sign up

I have list of files like first.js#19 edit, traval.jsp#233 edit, run.css#25 edit. I want to remove part from #, I just want file name ie first.js, traval.jsp, run.css How can do it using batch programming. Please share your code. Thanks for help

share|improve this question

try:

for /f "tokens=1*delims=#" %%a in ('dir /b /a-d') do ren "%%~a#%%~b" "%%~a"

this doesn't work, if the first # is followed by another #.

share|improve this answer

Try this:

for /r %%a in (*) do (for /f "delims=#" %%z in ("%%~a") do (ren %%a %%z)

And that should work. Not sure about spaces, but your example didn't include any.

Mona

share|improve this answer

Try this code (assuming that you the batch script is located in the same directory as the file):

@echo off
SetLocal EnableDelayedExpansion

for /f "delims=# tokens=1*" %%a in ('dir /b') do (
    set "oldName=%%a#%%b"
    set "newName=%%a"

    ren "!oldName!" "!newName!"
)

Hope this helps.

share|improve this answer
    
Thanks for your answers. But I am new to batch programming. I have a text file which consist of all these file names. I want to travels that text file and show file name one by one – user2918831 Oct 25 '13 at 8:42
    
can you show me the text file that you are working on so that I will be able to help you better. – Dale Oct 25 '13 at 8:51

You can do that directly from the command line:

for /f "delims=#" %a in (theTextFile.txt) do echo %a

This works as long as the file names are placed in individual lines of the text file. If you want to make a Batch file with this line, double the percents.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.