List Directory Folder Names & Subdirectory Folder Names Only & in Sorted Order - directory-listing

I am trying to use the DIR command to create a list of Folder names with the names of any and all subfolders listed after the parent folder name - but just the names of the folders.
So if the tree looks like:
Folder1
subfoldera
subfolderb
Folder2
subfolderc
subfloderd
The list would be essentially that:
Folder1
subfoldera
subfolderb
Folder2
subfolderc
subfloderd
Only folder names with no files listed, without any attributes and without the leading directory tree information. Is that even doable ??

Assuming you are asking for the windows command prompt
dir /s /ad /b /on
Will list only directory names but, will display the full path

Well I never solved this via a command line option, but I did finally come across a flexible and useful free utility that will do what I was looking to do. It is called Karen's Directory Printer (your favorite search engine will find it) and once you figure out which options to include/exclude it will print out just the folder names with the children folder names under the appropriate parent folder name. Thought I would share...

Related

Delete duplicate files of different extensions recursively

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

Copy multiple files with same naming format from different directories using Batch file

I'm trying to copy a specific file name that ends with _current in many different directories. Each directory has the same folder structure. I need to be able to copy all files that end in _current from each of the sub-folders in each directory. I've tried the code below as a test, not using my real directory names rather using test directories.
for /R "C:\Users\testuser\Desktop\testfolder\*\ABCD" %%f in (*_current) do copy %%f C:\Users\testuser\Desktop\abcd

Move a folder if a file exist, the check should perform in multiple directories

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!

Moving files from one dynamic directory to another using batch script

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 to search and copy results with file structure?

I am trying to find a way to search a directory for files by name, then copy the found files to an output directory. Because the files will have the same file name, I'm wondering if I can copy the folder structure as well, or alternatively append the filename with its parent folder name (i.e. folder\file.txt becomes folder-file.txt)
The search I'm using is a basic dir call:
dir file.xml /s
Can I do what I'm trying with only cmd? I would be ok using this in a batch script as well, though I believe the syntax is the same.
I would probably do this with robocopy (built in to newer versions of Windows). Something like this should do the trick...
robocopy.exe /S C:\FromDir C:\ToDir file.xml
This will copy the file.xml files that match on c: and keep the folder structure intact, to d:\results
xcopy "c:\file.xml" "d:\results\" /s

Resources