I'm trying to create a batch file that can delete .xmlb files is there is a .engb file of the same name in the same folder. I want it to work so that it can check the folder where the batch file is placed as well as all of the sub-folders. I found this question where someone pointed out how to do this in a single folder, but I'm trying to do it in every sub folder. Here's what I have so far:
#echo off
for /r %%I in (*.xmlb) do (
if exist %%~pnI.engb del %%I
)
pause
It gives me a "the system cannot find the path specified" error. I tried changing del with echo, and when I do that it does manage to display the names of the .xmlb files (with .engb extensions), so I'm assuming it can actually find them and my syntax is off somewhere. If I try to use %%~nI like the original code, it won't do anything (because the .engb files are in the same folders as the .xmlb files). I'm sure I'm probably missing some small thing that's preventing it from deleting the right files. Any help is appreciated! I'm attaching two screenshots: one with the batch file in a folder, and then one of the sub-folders that contains .xmlb and .engb files. So in the jungle1, jungle2, and jungle3 folders I want to keep the .engb files and remove any .xmlb files with the same names as .engb files
Related
I need to replace files in destination with ignore source structure.
Basicly source folder have many subfolders, destination is only one folder without the subfolders so I tried Xcopy but the result is not good.
I have another folder with same issue I beleive the solution for the upper question will solve both.
Drop folder from TFS get everytime different name, I need to be able to copy from buildoutput folder(parent folder for all builds) only existing files to destination, destination doesn't include folders.
As best as I can tell from your question:
#echo off
set "src=C:\Your\Source\Directory"
set "des=C:\Your\Destination\Folder"
for /r "%src%" %%A in (*) do (
if exist "%des%\%%~nxA" copy /y "%%A" "%des%\%%~nxA"
)
Will loop through all files in your source directory, check to see if those files exist in your destination folder, and if they do it will copy/overwrite them.
Reference: For, Copy.
If you're trying to accomplish something more specific you'll need to edit your question.
I want a batch file to check for a certain files in a folder and all of its subdirectories and if that file is found I want to copy the folder in which the file sits.
How can I achieve it? Can anyone help?
You can try something like this:
#echo off
for /R "full_path_to_folder_with_subfolders" %%A IN (filename_you_want_to_check) do (
copy %%~FA "full_path_you_want_file_to_be_copied"
)
NOTES:
full_path_to_folder_with_subfolders should be replaced with the FULL PATH of folder which contains the subfolders in which you want to search the certain files.
filename_you_want_to_check is only ONE certain file you want EXCEPT if your files have a common suffix, for example you have files a1.txt and a2.txt (ONLY IF these files will be copied in the same location) replace filename_you_want_to_check with a*.txt.
full_path_you_want_file_to_be_copied is the FULL PATH where your certain files (filename_you_want_to_check) should be copied.
Hope this helps!
I'm wondering if a batch file could help to move all the files which i need from a couple of folders to a specific one. The folder structure looks like this example below:
d:\home\\(random)\upload\\*.*
d:\home\\(random)\uplaod\\*.*
The files in the directory upload should be moved to a specific folder. It can be done by putting every single path in to the batch file, (there are more then 100 folders and there will some more in the future). I guess there is an easier way to get this done.
Thanks for you help in advance.
for /d %%a in ("D:\home\*") do echo move "%%a\upload\*" "x:\destination\
This is the syntax for use in a batchfile. For use on commandline replace every %%a with %a.
The for /d returns subfolders of D:\home\. Just append the upload\* part.
I need to write a batch script to move files from one sub-directory to another in Windows 7. These directories have the same structure, and always start with the same characters but end in a random seven digit number.
For example, I need to move all files and folders within \EMAIL_XXXXXXX\ to \MAGMA_XXXXXXX\. These two sub-directories both exist within the same parent directory PROJECT_XXXXXXX. So the MAGMA directory is actually PROJECT_XXXXXXX\MAGMA_XXXXXXX\. Again, the folder numbers will always be random, I just need to run the batch file from within the start of the PROJECT_XXXXXXX directory.
I have successfully been able to delete text files from these directories by placing the below batch file within the parent PROJECT_XXXXXXX directory:
FOR /R %%Y IN (EMAIL*) DO del *.txt /S /Q "%%Y"
As you can see above, using wildcards allows me to use batch to find all the directories starting with EMAIL and delete all files with the extension .txt.
Now I just need to move the remaining files from the EMAIL_XXXXXX sub-directory to the MAGMA_XXXXXXX sub-directory. I understand wildcards can be tricky when manipulating directories. Is there any way I can move these files in a similar way I was able to delete files, running the batch script within the parent directory?
Thanks in advance for your help!
how can I organize my directories automatically?, I have a "downloads" folder, which currently contains lots of different info, for example, work related info, tv-shows, movies, etc, software, etc.
How can I automatically, maybe using some .bat execution, not sure, check for example the name of the files, or the type, and put them in the right subfolders?.
Thanks!.
You can use the move command to move files. You can also use wildcards in it.
So you could write a batch script that looks something like this:
cd C:\Users\You\Downloads
rem Excel sheets are work.
move *.xls Work
rem Reports are work.
move Report*.pdf Work\Reports
rem Pron and other viewing material ;)
move *.mp4 Private
You could run this script automatically by making it a scheduled job. Note that this script changes to the right directory first and then moves items to a relative subdirectory. This means that the directories Work, Work\Reports and Private must exist in the Downloads directory.
Of course you can expand the script to make it check and create directories as well, or you can specify different paths if you want to move the files out of the Downloads directory.
Basically, try to do it on the command line and then try to generalize those steps into your script.
This batch file will create a set of folders like .mkv .jpg .mp3 using the filetypes inside the folder, and move the files into the appropriate folders.
Launch it from your desktop and change the "c:\media" to the right folder name.
#echo off
cd /d "c:\media" && for %%a in (*) do md "%%~xa" 2>nul & move "%%a" "%%~xa" >nul