Ragman
Ragman

Reputation: 11

How reference source without having to use the entire destination path?

I'm making a file that copies itself using:

/y C:\Users\user\Desktop\big.bat F:\

I would like to be able to copy the file without having to refer to the entire path in case the file is in a different place.

Thank you in advance anyone who decides to help me.

Upvotes: 1

Views: 61

Answers (2)

Hackoo
Hackoo

Reputation: 18847

If your destination is always F:\ :

@echo off
echo My working directory is : "%~dp0"
echo(
echo The Full Path of this file is :   "%~f0"
echo(
echo My Name is without extenstion is : "%~n0"
echo(
echo My Name is with extenstion is    : "%~nx0"
echo(
pause
cls
echo(
echo Copy /y "%~f0" F:\
echo(
If exist F:\ Copy /y "%~f0" F:\
echo(
pause

Upvotes: 0

Stephan
Stephan

Reputation: 56208

Inside a batchfile, you can reference it's name with %~f0:

@echo off
echo My name is %~f0

It's directory is %~dp0, it's name.extension is %~nx0...

You can read about other modifiers with help call

Upvotes: 1

Related Questions