Solved

Batch File: Short Name of Long File Name

Posted on 2010-08-18
7
509 Views
Last Modified: 2012-05-10
Hi there,

I need to copy files as their short file name.

@echo off
for /f "delims=" %%A in (dir /b /s .\Documents') do xcopy /y %%?A Z:\Documents
exit

Thanks for your help,
Rene
0
Comment
Question by:ReneGe
[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
  • 3
7 Comments
 
LVL 54

Expert Comment

by:Bill Prew
ID: 33464275
In a FOR loop you can get the short names via the "S" modifier, so perhaps:

for /f "delims=" %%A in (dir /b /s .\Documents') do xcopy /y %%~sA Z:\Documents

You can do FOR /? at a command prompt to see all the modifiers...

~bp
0
 
LVL 10

Author Comment

by:ReneGe
ID: 33464303
Hey billprew !!

I clicked on the send button to quickly. So while I was editing my question you answered... Yr quicker than a speeding bullet...

It must be done by excluding the drive infos.
So insted of: C:\Documents\mydocu~1
I would get: \mydocu~1

Thanks,
Rene
0
 
LVL 10

Author Comment

by:ReneGe
ID: 33464366
Correction:
It must be done by excluding the drive infos.
So insted of: C:\Docume~1\mydocu~1
I would get: \mydocu~1   or   mydocu~1
0
Business Impact of IT Communications

What are the business impacts of how well businesses communicate during an IT incident? Targeting, speed, and transparency all matter. Find out more in this infographic.

 
LVL 54

Accepted Solution

by:
Bill Prew earned 500 total points
ID: 33467773
I'm not quite sure I understand what you want, but how about these?

for /f "delims=" %%A in ('dir /b /s .\Documents') do xcopy /y %%~spnxA Z:\Documents

or

for /f "delims=" %%A in ('dir /b /s .\Documents') do xcopy /y %%~snxA Z:\Documents

Also, you don't even need the DIR command in this case, and can get faster results via:

for /R ".\Documents" %%A in (.) do xcopy /y %%~spnxA Z:\Documents

~bp
0
 
LVL 10

Author Comment

by:ReneGe
ID: 33471452
billprew,

You answered two questions at once, the one I just asked and the one I was just about to ask... cool!!!

Thanks man...

Cheers,
Rene

0
 
LVL 10

Author Closing Comment

by:ReneGe
ID: 33471462
billprew is the coolest!
0
 
LVL 54

Expert Comment

by:Bill Prew
ID: 33471474
Thanks Rene, glad that was useful.

~bp
0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

A short article about problems I had with the new location API and permissions in Marshmallow
Although it can be difficult to imagine, someday your child will have a career of his or her own. He or she will likely start a family, buy a home and start having their own children. So, while being a kid is still extremely important, it’s also …
With the power of JIRA, there's an unlimited number of ways you can customize it, use it and benefit from it. With that in mind, there's bound to be things that I wasn't able to cover in this course. With this summary we'll look at some places to go…

739 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