How do I find current directory for my Batch file? - windows

I am currently working on a batch file (let's call it temp.bat). I am trying to move the batch file to my desktop, but I can't find my batch file location / directory. I am asking if there is an extension or something that can use to automatically identify the directory, instead of entering it every time. In other words, I can still move the file to another place even in another directory. Example:
temp.bat is currently on my Downloads file. I use the move command to move the file to Desktop. Now temp.bat is currently on my Documents file. I try to use the same command to move the file to Desktop.
Is there any parameter extensions for it?
This is what I have now:
#echo off
move /y [The directory of temp.bat] C:\Users\69Swag\Desktop
All answers appreciated! Thanks :)

You don't need the current directory to move a file.
move temp.bat C:\Users\69Swag\Desktop
If you still want the current directory, use this:
echo %cd%

Related

Shell script to copy and paste a particular file from one directory to another?

As part of a Windows software project I'm working on I need to copy and paste a particular DLL file from directory A to directory B. In the process, I need to overwrite any previous version of this file in directory B.
Directory A is: Documents/Visual Studio/2015/Project/MyProject/MyProject/bin/Debug
Directory B is: This PC/Windows(C:)/Users/Public/Public Documents/B
Is there a shell script that can perform this operation?
Any help would be greatly appreciated!
Described goal can be achieved by single cmd command:
copy /Y "%USERPROFILE%\Documents\Visual Studio\2015\Project\MyProject\MyProject\bin\Debug\libName.dll" "C:\Users\Public\Public Documents\B"
So you can put this command into scriptName.bat file and execute. Put pause at the end of the file to prevent window closing if you want to check script output.

How to change the extention to all file in a directory using windows batch script

I need to change the file extensios of a directoy. If I do it manually so it will take more time. So is there any windows shell command or batch file to do this?
Like all .html file in a folder will be .php?
make a .bat in a folder and put in it this code
#ren *.Old_extension *.New_Extension
Also if you want to change more extensions just copy the lane and paste it under edited like this
#ren *.Old_extension *.New_Extension
#ren *.Old_extension2 *.New_Extension2
Yes, You can easily do this Command Prompt
Suppose, You have a Folder so many .TXT files in your folder.
Open that folder and just press SHIFT + RIGHT click and select Open Command Windows here
After that type the following command to change all .txt file to .doc
ren *.txt *.doc
It will change all text files in doc file
That's all

Get location (path) of the shorctut calling a batch file

I have an ongoing list of 'Enquiry' folders within a directory. I'm trying to create a batch file that can sit within each of these folders that, when run, will move the folder it resides in to a 'Projects' folder.
From my attempts, and as half expected, I'm realising it's not possible to move the folder containing the batch file (or copy folder and then delete source folder containing the batch), so my second thought is to position a single 'master' batch file outside of the 'Enquiry' folders, and have a shortcut within each Enquiry folder that links to that 'external' batch file.
For this, I'd need to obtain the location path of the shortcut calling the batch, is this possible?
Or is there a better way to achieve my aim?
Just an extra note in case it helps anyone, I had to make the following changes to ensure file path with space was ok (putting %enqfolder% in quotes) and I also need to a '\' after 'projects' in the move command. Thanks again to #Klitos.
setlocal
set enqfolder=%cd%
cd ..
move "%enqfolder%" ..\projects\
Following on from the comments to your question, the reason it doesn't move the folder is that when the batch file runs, the current directory is still the enquiry folder. You need to move out of it and then move it. Also, as it turns out, you don't have to delegate to a "master" batch file either. You can just do the move in the same batch file (but the move should be the last line of the batch file; once the batch file itself moves, the command processor won't be able to read the following lines).
setlocal
set enqfolder=%cd%
cd ..
move %enqfolder% ..\projects

Windows batch autoanswer XCOPY /i

I have created a batch file which uses FOR command to read a file of FROM Directory, FROM File, TO Directory, TO File as the parameters. (I am giving the files NEW names in the destination)
Everything works great until I add a new file to the mix.
In XCOPY /i option says it is a directory (which is NOT true). IF I don't use /i it wants to know if it is a file or a directory. It is ALWAYS a File. Is there a way I can autoreply or does someone have another suggestions.
echo f|xcopy [options] [files*]
A short investigation did not yield an easy command line parameter solution.
If I got you right, you are trying to copy a file from one directory to a new directory + give it a new name in the new directory. Copying to the new directory should work fine when you terminate target directory name with a tailing '\' (backslash) - this should result in a file with the same name in the target dir. Renaming this file to the new name will be straight forward. However, it's two commands instead of one...
In case this does not work for you: maybe you can illustrate your qn with a sample / snippet of the batch file?

How to use the list files in a given directory via batch file without showing the full path?

I have searched for this everywhere so I hope it has not already been asked, but I have a batch file where the user can write his / her own 'scripts' if you will. When the batch file is ran for the first time it will make a directory under %appdata%\Mellow\Mango\scripts and these scripts will simply be .txt files. Anyway...
I am trying to list the 'scripts' to the user by using dir /b /s *.txt and the output is C:\Users\Tate\AppData\Roaming\Mellow\Mango\scripts\template.txt
My question is, sorry if I got off-topic before, how to display only template.txt and not the full file path. I simply would like to list all .txt files contained in the scripts folder. Thanks in advanced!
Current Output:
C:\Users\Tate\AppData\Roaming\Mellow\Mango\scripts\template.txt
C:\Users\Tate\AppData\Roaming\Mellow\Mango\scripts\another_script.txt
Desired Output:
template.txt
another_script.txt
Simply remove the /s
dir /b *.txt
That should do it :)

Resources