[Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

Renaming files

Posted on 2012-04-10
7
Medium Priority
?
477 Views
Last Modified: 2012-04-10
I have received about 100 files from a customer, they are jpg images for storing on a web site. My computer is Windows XP. Also about the same number of pdf.

For whatever reason, they are named <filename>.jpg.jpg. The extension jpg is there twice. Same for the pdf's.

I tried using dos command line old "ren" command, like this : ren *.jpg.jpg *.jpg

It didn't work.

Is there some way to do all at once?

Thanks
0
Comment
Question by:Richard Korts
  • 4
  • 2
7 Comments
 
LVL 59

Accepted Solution

by:
Bill Prew earned 2000 total points
ID: 37830582
At a command line you could do:
for %A in (*.jpg.jpg) do ren "%~A" "%~nA"
for %A in (*.pdf.pdf) do ren "%~A" "%~nA"

Open in new window

Or in a BAT file do:
for %%A in (*.jpg.jpg) do ren "%%~A" "%%~nA"
for %%A in (*.pdf.pdf) do ren "%%~A" "%%~nA"

Open in new window

~bp
0
 

Author Comment

by:Richard Korts
ID: 37830618
To billprew,

Great , that did MOST of them (but not all).

I noticed that the ones that DIDN'T get changed were either duplicates or had the letter "A" as part of the filename.

But that's a HUGE help.
0
 
LVL 59

Expert Comment

by:Bill Prew
ID: 37830623
The dupes make sense they would have failed.  Don't see any reason why having an A in the name would have caused a failure though.  Anyway, glad that helped.

~bp
0
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 

Expert Comment

by:jennifer636
ID: 37830802
can you explain the solution  further? with explanation of %% and ~ and A and what each is doing.
0
 
LVL 59

Expert Comment

by:Bill Prew
ID: 37830821
The tilde is used when referencing loop variables to alter the value that is substituted inline.

If you do FOR /? at a command prompt you can see what capabilities exist.  Here's an excerpt from that.

In addition, substitution of FOR variable references has been enhanced.
You can now use the following optional syntax:

    %~I         - expands %I removing any surrounding quotes (")
    %~fI        - expands %I to a fully qualified path name
    %~dI        - expands %I to a drive letter only
    %~pI        - expands %I to a path only
    %~nI        - expands %I to a file name only
    %~xI        - expands %I to a file extension only
    %~sI        - expanded path contains short names only
    %~aI        - expands %I to file attributes of file
    %~tI        - expands %I to date/time of file
    %~zI        - expands %I to size of file
    %~$PATH:I   - searches the directories listed in the PATH
                   environment variable and expands %I to the
                   fully qualified name of the first one found.
                   If the environment variable name is not
                   defined or the file is not found by the
                   search, then this modifier expands to the
                   empty string

The modifiers can be combined to get compound results:

    %~dpI       - expands %I to a drive letter and path only
    %~nxI       - expands %I to a file name and extension only
    %~fsI       - expands %I to a full path name with short names only
    %~dp$PATH:I - searches the directories listed in the PATH
                   environment variable for %I and expands to the
                   drive letter and path of the first one found.
    %~ftzaI     - expands %I to a DIR like output line

Open in new window

0
 

Expert Comment

by:jennifer636
ID: 37830917
thank you so much for the explanation.
0
 
LVL 59

Expert Comment

by:Bill Prew
ID: 37830923
Very welcome.

~bp
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

We have adopted the strategy to use Computers in Student Labs as the bulletin boards. The same target can be achieved by using a Login Notice feature in Group policy but it’s not as attractive as graphical wallpapers with message which grabs the att…
Sometimes people don't understand why download speed shows differently for Windows than Linux.Specially, this article covers and shows the solution for throughput difference for Windows than a Linux machine. For this, I arranged a test scenario.I…
Two types of users will appreciate AOMEI Backupper Pro: 1 - Those with PCIe drives (and haven't found cloning software that works on them). 2 - Those who want a fast clone of their boot drive (no re-boots needed) and it can clone your drive wh…
Look below the covers at a subform control , and the form that is inside it. Explore properties and see how easy it is to aggregate, get statistics, and synchronize results for your data. A Microsoft Access subform is used to show relevant calcul…
Suggested Courses

864 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