.bat file relative file paths

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
tike55Asked:
Who is Participating?
 
Brad GrouxConnect With a Mentor Senior Manager (Wintel Engineering)Commented:
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
 
oBdACommented:
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
 
tike55Author Commented:
How do you generate the short names? Manually?
0
 
oBdACommented:
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
 
Steve KnightIT ConsultancyCommented:
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
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.