Solved

.bat file relative file paths

Posted on 2014-09-03
5
272 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
ID: 40301490
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 83

Expert Comment

by:oBdA
ID: 40301497
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
ID: 40301547
How do you generate the short names? Manually?
0
 
LVL 83

Expert Comment

by:oBdA
ID: 40301554
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
ID: 40302088
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Entering a date in Microsoft Access can be tricky. A typo can cause month and day to be shuffled, entering the day only causes an error, as does entering, say, day 31 in June. This article shows how an inputmask supported by code can help the user a…
Resolve Outlook connectivity issues after moving mailbox to new Exchange 2016 server
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 …

911 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

20 Experts available now in Live!

Get 1:1 Help Now