I'm using Windows CMD via an ANT Build file to move files from a sub-folder into a parent folder that is three levels up. The structure looks like this:
containingFolder
-tempFolder
-unkownNamedFolder
-contents.xyz
Using linux I can do this with the command mv */*.* .. with the current working directory being the temp folder. I don't know what the unknownNamedFolder will be called, but I do know that it will always be the only folder within the temp folder and that whatever content is within it needs to be extracted out to the containingFolder so that temp can be deleted and only the files will remain.
I've tried a command such as /c move *\*.* .. 2>NUL but this doesn't work.
Related
So I'm trying to create basic directory and push it out across our end users. I've got the basic .cmd to work but it breaks when I have a folder with multiple spaces.
cmd /c mkdir "C:\ProgramData\Example\This Folder Has Four Spaces\Example"
the plan is to set this to run automatically on machines.. If I remove the path with the long folder name, it works perfectly fine. Is there a way for me to place a file in the directory that has a long folder name with spaces? I wasn't sure if there was any sort of bypass to this. I initially thought it was because I was trying to copy a file to the program data folder but I've tested this with other folder names and it works fine. Just seems to be this specific folder it doesn't work with so I'm led to believe it's because of how long the folder name is.
I'm only started scripting a few weeks ago and have been testing a few scripts I've put together with help from some posted on this site.
Currently I'm struggling and require some help or assistance.
I want to be able to move all files with any particular/given file extension, from within any directory, and any of their sub-directories, if they exist. I just want the files, not the folders copied.
The script works, I'm hoping for anyway, as such:
You enter the directory you want to move the files from e.g. D:\TestMove
You enter the directory you want to move the files to e.g. D:\Test
You enter the file extension of all of the files that you want to be moved from the given directory, and then sub-directories eg. .txt
If the directory you're moving them to doesn't exist, it should be created.
So in my case, I've got the directory D:\Test, with multiple sub-directories, (TestMove\Test2, etc.), and within each of those directories multiple .txt files, (for example). I want to be able to move all of the .txt files from the D:\Test directory to wherever I want.
At the moment, it's just moving the files from the directory I choose, but not from within the sub-directories.
I'm happy to get this script ripped to bits so that I can learn where I'm going wrong.
set /P DMF=Please enter Directory moving from:
set /P DMT=Please enter Directory moving too:
set /P FEX=Please enter File Extension:
if not exist %DMT% mkdir %DMT%
for %%a in (%FEX%) do (
echo Moving all %%a files to "%DMT%" ...
move "%DMF%\*%%a" "%DMT%"
)
So I am trying to make a batch file to sync an external hard drive.
My hard drive is not always connected to the same letter, so i cannot just make a batch file with xcopy F:\Folder1 G:\backupharddrive because G:\backupharddrivewould be variable
Is there a way to just copy to the folder the batch file is in?
Just use relative addressing, where . represents the current directory.
xcopy F:\Folder1 .
For future reference, you can also access the parent of the current folder (IOW, 1 level higher up in the directory tree) using ... This makes it handy to move up a level, or even over one. For instance, to copy files from C:\Temp\One to C:\Temp\Two, you can use
xcopy *.* ..\Two\
which means copy the files from this folder up one level and then over to the Two folder.
If you use dir from a command prompt, you'll see that in any level below the drive root you'll have items for . and .. in the list. (The root only has ., because it has no parent folder.
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
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%