Solved

Renaming files

Posted on 2012-04-10
7
451 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 2
7 Comments
 
LVL 55

Accepted Solution

by:
Bill Prew earned 500 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 55

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
What Is Transaction Monitoring and who needs it?

Synthetic Transaction Monitoring that you need for the day to day, which ensures your business website keeps running optimally, and that there is no downtime to impact your customer experience.

 

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 55

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 55

Expert Comment

by:Bill Prew
ID: 37830923
Very welcome.

~bp
0

Featured Post

On Demand Webinar: Networking for the Cloud Era

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

Question has a verified solution.

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

Ok I have been working on this for some time having learned and gained certification in XenDesktop 4 along came version 5 which was released last month. Since then I have been working to deploy XenDesktop 5 in a small environment with only 2 virt…
When you start your Windows 10 PC and got an "Operating system not found" error or just saw  "Auto repair for startup" or a blinking cursor with black screen. A loop for Auto repair will start but fix nothing.  You will be panic as there are no back…
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…
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …

688 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