Solved

Batch File: Short Name of Long File Name

Posted on 2010-08-18
7
503 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
  • 4
  • 3
7 Comments
 
LVL 53

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
DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

 
LVL 53

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 53

Expert Comment

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

~bp
0

Featured Post

3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

Question has a verified solution.

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

Suggested Solutions

Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
This article will inform Clients about common and important expectations from the freelancers (Experts) who are looking at your Gig.
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …

821 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