Solved

Renaming files

Posted on 2012-04-10
7
358 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 51

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 51

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
Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

 

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 51

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 51

Expert Comment

by:Bill Prew
ID: 37830923
Very welcome.

~bp
0

Featured Post

Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

Join & Write a Comment

cPanel is a Unix based web hosting control panel that provides a graphical interface and automation tools designed to simplify the process of hosting a web site. cPanel utilizes a 3 tier structure that provides functionality for administrators, rese…
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…
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…
In this tutorial you'll learn about bandwidth monitoring with flows and packet sniffing with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're interested in additional methods for monitoring bandwidt…

759 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

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now