1.

Solve : how to change xls files that have specific seequens of caracters with batch file?

Answer»

hello,
i get every day 16 excell files that have the name of the city they come from and some subject
example to file name miami profit.xls, newyork profits.xls
the problem is the subject is not written the same way
is there abatch file code that can erease all the caractor except what i define him.
for example the result of abatch file will change the name of the exell files to miami.xls and newyork.xls.
This will remove " profit" and " profits" from the filenames.

If you have a known number of variations that you need to remove then you can add them to the BATCH file.

In the case below " profits" is removed first, and then " profit" so that you don't end up with a single "s" that wasn't removed if it was done in the reverse order.
If the words don't exist then it will not do anything,

Code: [Select]@echo off
setlocal enabledelayedexpansion
For %%a in (*.xls) do (
set "name=%%a"
set "name=!name: profits=!"
set "name=!name: profit=!"
ren "%%a" "!name!.tmp"
)
ren *.xls.tmp *.hello,
thanks for your answer
the problem is i dont know the number of caractor that need to be remove becouse each time its diffrent subject
i have list of names that need to be stay.
so let say all xls files in aspecific folder that have part of the file name miami or new york or other which i DECIDE in the batch file remove all caracture in that files except thos that need d to be stay.
for exmaple i got two files miami salary and new york oppertunities.
after operate the batch file i just want to see in the folder ONE file name miami and one file name new new york

Is the state name always at the front? Is it always a US state name?the state name is always in back.
i work with hebrew caracture so fisrt come the subject then the name of the city
Quote from: regev78 on March 15, 2014, 09:20:22 AM

i work with hebrew caracture so fisrt come the subject then the name of the city

When you ask for free help, you really should give accurate details about the task.

I don't know how cmd handles Hebrew characters.I think what I would do is make a file with a list of the city names. One city per LINE. Use a for loop to parse that list and match that to the files in your directory and do a rename of the files. But then what are we supposed to do if you have two files with the same city name within a LARGER file name?its not possible to have two files with the city name in the same folder.
foxdirve im new in this forum, will try to be more accurate in my questions.

[recovering disk space, attachment deleted by admin]You are using Unicode formatting in the text file and unicode characters can be a huge problem for batch. Or at least I am totally unfamiliar with good ways to handle them.
The last time I dealt with some unicode I had to resort to a VBS script.

It will be interesting to see if anyone has some ideas...Quote from: foxidrive on March 16, 2014, 03:10:09 AM
You are using Unicode formatting in the text file and unicode characters can be a huge problem for batch. Or at least I am totally unfamiliar with good ways to handle them.
The last time I dealt with some unicode I had to resort to a VBS script.

It will be interesting to see if anyone has some ideas...

I ran a quick test, and I'm relatively sure you will have to resort to VB script.

Code: (cmd) [Select]T:\>type cities.txt
??????
?????
??????
??? ???
????
?????
????
?????
???
??????
???
????
????
???
?????
?????
?????
??? ??

T:\>type cities.txt >end.txt

T:\>notepad end.txt

T:\>

Code: (end.txt) [Select]??????
?????
??????
??? ???
????
?????
????
?????
???
??????
???
????
????
???
?????
?????
?????
??? ??



Discussion

No Comment Found