Solved

Batch File: Short Name of Long File Name

Posted on 2010-08-18
7
499 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 51

Expert Comment

by:Bill Prew
Comment Utility
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
Comment Utility
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
Comment Utility
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
What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

 
LVL 51

Accepted Solution

by:
Bill Prew earned 500 total points
Comment Utility
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
Comment Utility
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
Comment Utility
billprew is the coolest!
0
 
LVL 51

Expert Comment

by:Bill Prew
Comment Utility
Thanks Rene, glad that was useful.

~bp
0

Featured Post

Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

Join & Write a Comment

I have published numerous articles here at Experts Exchange that present programs/scripts written in a language called AutoHotkey. Each of those articles has a brief paragraph describing where to download the product and how to install it. I have al…
Whether you've completed a degree in computer sciences or you're a self-taught programmer, writing your first lines of code in the real world is always a challenge. Here are some of the most common pitfalls for new programmers.
An introduction to basic programming syntax in Java by creating a simple program. Viewers can follow the tutorial as they create their first class in Java. Definitions and explanations about each element are given to help prepare viewers for future …
In this fifth video of the Xpdf series, we discuss and demonstrate the PDFdetach utility, which is able to list and, more importantly, extract attachments that are embedded in PDF files. It does this via a command line interface, making it suitable …

762 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

11 Experts available now in Live!

Get 1:1 Help Now