Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

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

Posted on 2014-03-11
8
Medium Priority
?
704 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
Prepare for your VMware VCP6-DCV exam.

Josh Coen and Jason Langer have prepared the latest edition of VCP study guide. Both authors have been working in the IT field for more than a decade, and both hold VMware certifications. This 163-page guide covers all 10 of the exam blueprint sections.

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

Visualize your virtual and backup environments

Create well-organized and polished visualizations of your virtual and backup environments when planning VMware vSphere, Microsoft Hyper-V or Veeam deployments. It helps you to gain better visibility and valuable business insights.

Question has a verified solution.

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

If like me you are one who spends a lot of time working and scripting with cmd.exe, sometimes it is handy to be able to quickly view a calendar for a given month and year. This script will quickly do just that!  Save the code posted below to a .bat …
This article was inspired by a question here at Experts Exchange (http://www.experts-exchange.com/Software/Photos_Graphics/Images_and_Photos/Q_28629170.html). The requirements stated in that question are (1) reduce the file size of a large number of…
Want to learn how to record your desktop screen without having to use an outside camera. Click on this video and learn how to use the cool google extension called "Screencastify"! Step 1: Open a new google tab Step 2: Go to the left hand upper corn…
We’ve all felt that sense of false security before—locking down external access to a database or component and feeling like we’ve done all we need to do to secure company data. But that feeling is fleeting. Attacks these days can happen in many w…
Suggested Courses

927 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