Solved

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

Posted on 2014-03-11
8
674 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
 [eBook] Windows Nano Server

Download this FREE eBook and learn all you need to get started with Windows Nano Server, including deployment options, remote management
and troubleshooting tips and tricks

 
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
 
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

On Demand Webinar: Networking for the Cloud Era

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

Question has a verified solution.

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

YESTERDAY YESTERDAY.BAT is inspired by a previous article I wrote entitled: TOMORROW.BAT (http://www.experts-exchange.com/OS/Microsoft_Operating_Systems/MS_DOS/A_4196-Advanced-Batch-File-Programming-TOMORROW-BAT.html). The crux of this batch f…
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…
In this video we outline the Physical Segments view of NetCrunch network monitor. By following this brief how-to video, you will be able to learn how NetCrunch visualizes your network, how granular is the information collected, as well as where to f…
NetCrunch network monitor is a highly extensive platform for network monitoring and alert generation. In this video you'll see a live demo of NetCrunch with most notable features explained in a walk-through manner. You'll also get to know the philos…

630 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