Solved

Help with batch file syntax - grab current file name with extension and put in a variable.

Posted on 2014-03-11
8
665 Views
Last Modified: 2014-03-11
All, please note the following code:

REM That if a certain command does not work put in ... pause 
which will pause after the command is run...

Set Extension=.dll
set SourceDB=%0%Extension

PAUSE

xcopy "C:\Program Files\Autodesk\Revit 2014\PlugIns\SMW\%SourceDB%" "\\NY-APP\Software Development\Transfer\REVIT" /d /y

Open in new window


I am trying to take the name of the batch file (0%) and use that in a variable (Extension) to copy from a local folder to a network folder.    But when I review what's it is copying it still doesn't grab the current name combining with another variable that throws in .dll at the end as an extension.  Please note picture attachment that shows the actual error.

Please let me know the syntax I should use to do an xcopy within a batch file!
batch-error-actual.PNG
0
Comment
Question by:stephenlecomptejr
  • 5
  • 3
8 Comments
 
LVL 8

Expert Comment

by:jpgobert
ID: 39922224
I won't lie, I'm pretty confused at what you're doing here.

I get that you're trying to copy some files from a local drive to a network share... but what about this process is requiring you to write a batch file with variables?

Also, you're using /D /Y as two switches at the end of your xcopy command but that's not correct syntax.
0
 
LVL 1

Author Comment

by:stephenlecomptejr
ID: 39922251
The variable is needed to grab the name of the batch file.   When I create a new dll file all I would have to do is copy/rename the batch file as the name of the dll file and run the script
0
 
LVL 8

Expert Comment

by:jpgobert
ID: 39922260
Will the DLL files always be in the same source directory, and then need to be copied to the same target directory?

If you're just looking for a way to make sure your new DLL's that are populated locally are regularly backed up you can do that without having to create and rename batch files for every new DLL.

Am I missing something or is this right?
0
 
LVL 1

Author Comment

by:stephenlecomptejr
ID: 39922276
I'm not backing it up.  I'm sending it forward for that specific file for that specific time.

Do you know how I may adjust the syntax to accept the current name of the batch file (without extension) and then concatenate ".dll" on the end of the variable so I can make this work?

I'm sorry but  not looking for another way to do this but want answer to this specific question.
0
3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

 
LVL 8

Accepted Solution

by:
jpgobert earned 500 total points
ID: 39922294
Hey man I apologize... was only trying to help you.

In your batch file you can set the variable to the batch file name as follows:

set SourceDB=%~n0.DLL

That will set SourceDB to the filename of the batch file being run (without the extension) and then adds .DLL as the new extension.

Just make sure to enclose SourceDB in quotes if the file name has spaces which you already seem to know.
0
 
LVL 1

Author Comment

by:stephenlecomptejr
ID: 39922388
I copied and pasted it above into the batch file and got the following error:  file not found.
Please note attached file image of what it shows as the filename.

Instead of Copy View.dll it shows
ExpertsExchange4.PNG
0
 
LVL 1

Author Comment

by:stephenlecomptejr
ID: 39922392
Sorry nevermind.

The file was named Copy View to local.....

I appreciate the comment in getting to the answer.
0
 
LVL 1

Author Comment

by:stephenlecomptejr
ID: 39922399
"Also, you're using /D /Y as two switches at the end of your xcopy command but that's not correct syntax. "

Then what should be the correct syntax - btw?
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

How to remove superseded packages in windows w60 or w61 installation media (.wim) or online system to prevent unnecessary space. w60 means Windows Vista or Windows Server 2008. w61 means Windows 7 or Windows Server 2008 R2. There are various …
Use this article to create a batch file to backup a Microsoft SQL Server database to a Windows folder.  The folder can be on the local hard drive or on a network share.  This batch file will query the SQL server to get the current date & time and wi…
This Micro Tutorial will teach you how to censor certain areas of your screen. The example in this video will show a little boy's face being blurred. This will be demonstrated using Adobe Premiere Pro CS6.
Video by: Mark
This lesson goes over how to construct ordered and unordered lists and how to create hyperlinks.

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

15 Experts available now in Live!

Get 1:1 Help Now