Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Batch File: Short Name of Long File Name

Posted on 2010-08-18
7
Medium Priority
?
516 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 57

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
Build and deliver software with DevOps

A digital transformation requires faster time to market, shorter software development lifecycles, and the ability to adapt rapidly to changing customer demands. DevOps provides the solution.

 
LVL 57

Accepted Solution

by:
Bill Prew earned 2000 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 57

Expert Comment

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

~bp
0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering 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

In this post we will learn how to make Android Gesture Tutorial and give different functionality whenever a user Touch or Scroll android screen.
This is a fine trick which I've found useful many times, when you just don't want to accidentally run a batch script or the commands needs administrator rights.
Progress
Starting up a Project

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