E=mc2
asked on
Specifying immediate parent folder in a batch file
Within a batch file, I would like to tell the batch to copy the files to the folder which is found just outside where the batch is running.
Is there a command that will allow this to happen?
Is there a command that will allow this to happen?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
copy somefile .\somefolder_next_to_this_batch\
McKnife,
for one thing, that might target the batch script's current folder under the right conditions, but not its parent (see the title, it's not so clear in the question.
But more importantly, this would target the current working directory, but not the script folder. They might be the same, but this is not a given.
Save this as C:\Temp\Whatever.cmd
Open a command prompt, use "cd C:\" to change to the root of the drive (or change to any other folder that is not C:\Temp) , then run
C:\Temp\Whatever.cmd
to see the difference (assumes an English Windows version).
for one thing, that might target the batch script's current folder under the right conditions, but not its parent (see the title, it's not so clear in the question.
But more importantly, this would target the current working directory, but not the script folder. They might be the same, but this is not a given.
Save this as C:\Temp\Whatever.cmd
Open a command prompt, use "cd C:\" to change to the root of the drive (or change to any other folder that is not C:\Temp) , then run
C:\Temp\Whatever.cmd
to see the difference (assumes an English Windows version).
echo Working directory using '.':
dir /a:d .\*.foo 2>NUL | find "Directory"
echo Script folder using %%~dp0:
dir /a:d %~dp0*.foo 2>NUL | find "Directory"
Yes. I have no doubt that your solution is better. It's just my way of throwing in a one-liner that some people who (possibly) don't even know the meaning of .\ might find interesting, short and handy. Anything needs testing, even a one-liner.
reference : https://wiert.me/2011/08/09/batch-files-getting-directory-and-parent-directory/
Open in new window