Solved

Batch File: Short Name of Long File Name

Posted on 2010-08-18
7
506 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
Industry Leaders: 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!

 
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

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

This article will show, step by step, how to integrate R code into a R Sweave document
Does the idea of dealing with bits scare or confuse you? Does it seem like a waste of time in an age where we all have terabytes of storage? If so, you're missing out on one of the core tools in every professional programmer's toolbox. Learn how to …
In this fourth video of the Xpdf series, we discuss and demonstrate the PDFinfo utility, which retrieves the contents of a PDF's Info Dictionary, as well as some other information, including the page count. We show how to isolate the page count in a…

749 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