Solved

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

Posted on 2014-03-11
8
671 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
How our DevOps Teams Maximize Uptime

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

 
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

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

TOMORROW TOMORROW.BAT is inspired by a question I get asked over and over again; that is, "How can I use batch file commands to obtain tomorrow's date?" The crux of this batch file revolves around the XCOPY command - a technique I discovered w…
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 …
If you're a developer or IT admin, you’re probably tasked with managing multiple websites, servers, applications, and levels of security on a daily basis. While this can be extremely time consuming, it can also be frustrating when systems aren't wor…
If you’ve ever visited a web page and noticed a cool font that you really liked the look of, but couldn’t figure out which font it was so that you could use it for your own work, then this video is for you! In this Micro Tutorial, you'll learn yo…

734 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