Solved

.bat file relative file paths

Posted on 2014-09-03
5
266 Views
Last Modified: 2014-09-09
Can you tell me How the "custom~1" reference is used here?  I dont see where it is defined anywhere in the code besides the example below.


net use w: \\10.0.4.6\Customer_Displays  /user:cm\user csrts


   REM *** COPY FILE FROM SERVER TO LOCAL FOLDER
xcopy /y W:\custom~1\current\wes\cust1.bmp C:\Customer display
xcopy /y W:\custom~1\current\wes\cust1_JB.bmp C:\Customer display
0
Comment
Question by:tike55
5 Comments
 
LVL 14

Accepted Solution

by:
Brad Groux earned 500 total points
Comment Utility
It looks to me like they are simply dictating a file path utilizing the short name. The tilde ~ character is used to convert long filenames to short filenames on legacy systems (known as 8.3 filenames), so the actual folder name is probably much longer. Explained - http://support.microsoft.com/kb/142982

Example:
C:\Documents and Settings\Brad
Could also be...
C:\Docume~1\Brad

Open in new window

NOTE: The use of ~ is considered a huge security risk.
0
 
LVL 82

Expert Comment

by:oBdA
Comment Utility
That's not a relative file path; are you thinking of variables like "%~dp0", which expands to the script's Drive and Path?
The "custom~1" is just the short file name for a folder probably named something like "Customer Display", and is used to prevent issues with the space in the name. The same could be done by using the folder's full name and quoting the path (which should happen for the target folder as well; this script probably isn't working as it should):
xcopy /y "W:\Customer display\current\wes\cust1.bmp" "C:\Customer display"
xcopy /y "W:\Customer display\current\wes\cust1_JB.bmp" "C:\Customer display"

Open in new window

0
 

Author Comment

by:tike55
Comment Utility
How do you generate the short names? Manually?
0
 
LVL 82

Expert Comment

by:oBdA
Comment Utility
Nope, they're automatically generated by Windows (if not disabled).
You can see them in a command prompt with the "dir /x" command.
Do not use them (as in "ever"), you can't rely on them really pointing to where you expect them to. They especially can differ from system to system, even for the same long name.
0
 
LVL 43

Expert Comment

by:Steve Knight
Comment Utility
Agreed with all that.  Don't use them!

Would also suggest adding the /D option to your command line xcopy next to /Y.  Then the file will only copy if it is newer on the server, presumably this is to make sure it is the latest version locally, i.e. something along the lines of:


set dest=C:\Customer display
if not exist "%dest%\nul" md "%dest%"
xcopy /y /d "W:\Customer display\current\wes\cust1.bmp" "%dest%"
xcopy /y /d "W:\Customer display\current\wes\cust1_JB.bmp" "%dest%"

Steve
0

Featured Post

Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

Join & Write a Comment

Suggested Solutions

A short article about problems I had with the new location API and permissions in Marshmallow
Resolve Outlook connectivity issues after moving mailbox to new Exchange 2016 server
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 …
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…

772 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