Solved

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

Posted on 2014-03-11
8
663 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
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 
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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Suggested Solutions

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 …
VALIDATING DATES One method of validating dates is to jam the date into the DATE command and see if it accepts it by examining the system's errorlevel value. A non-zero result indicates failure. A typical example might look something like the fol…
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.
This video explains how to create simple products associated to Magento configurable product and offers fast way of their generation with Store Manager for Magento tool.

759 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

22 Experts available now in Live!

Get 1:1 Help Now