Computer Hope

Microsoft => Microsoft DOS => Topic started by: fleisch on December 12, 2014, 01:16:40 PM

Title: Seeking help to move files from specifically named directory up one level
Post by: fleisch on December 12, 2014, 01:16:40 PM
I have a vast collection of fonts, sorted in different ways depending on where I downloaded them.  Many of them are sorted into foundries or families, with a sublevel for designer. Thus:
Presence Typo/Alinea Sans/Puyfoulhoux, Thierry/AlineaSans.ttf   

This is not an ideal structure for me, (for one thing, I'd put the designer before the font family name) but the immediate problem is that for many of them, the sorting program that did this could not identify the designer, so the vast majority of them are in a folder structure that goes:

2 the Left/Leftovers/_unknown/Leftovers.ttf
4YEO/4YEOSports/_unknown/4YEOSports.ttf

This just creates an unnecessary level (and often leads to a structure where the file name is too long).  There are literally thousands of foundries and designers (and hundreds of thousands of fonts). What I would like, if possible, is a batch file or visual basic script that would allow me to move all the files that in are a folder called "_unknown" up one level to the parent directory (which should be the family name), and then delete the folder called "_unknown". The number of directory levels may vary, and if they're in a folder that actually is a designer name, I don't want to move them.  Is this possible?
Title: Re: Seeking help to move files from specifically named directory up one level
Post by: foxidrive on December 12, 2014, 01:36:48 PM
Need some clarification of the task here:

Will every folder called \_unknown have no folders inside it, and only *.ttf files inside it
that need to be moved up one folder level, and then the\_unknown folder deleted?


Title: Re: Seeking help to move files from specifically named directory up one level
Post by: fleisch on December 12, 2014, 02:20:13 PM
Every folder called unknown will have no folders inside it, but it may have .otf, or .pfb, .pfm, or .afm files.  It is possible there may be some sort of .txt (.doc, .wri) file, but unlikely.  I haven't specifically checked for that.  If there is one, perhaps there is a solution that would only delete the folder if it were empty??
Title: Re: Seeking help to move files from specifically named directory up one level
Post by: foxidrive on December 13, 2014, 03:37:51 AM
Ohhh kay!

In every folder called \_unknown, do you only want the *.ttf files inside it
to be moved up one folder level, and then the\_unknown folder deleted if it is empty?

If there are folders called \_unknown that you do not want processed, then how do we tell if it is to be processed, or not?
Title: Re: Seeking help to move files from specifically named directory up one level
Post by: fleisch on December 13, 2014, 08:21:45 AM
Thanks for your help.  Ideally, I want every folder called \_unknown to be processed, ALL the files in it moved up one level, and the \_unknown folder deleted.
Title: Re: Seeking help to move files from specifically named directory up one level
Post by: Squashman on December 13, 2014, 08:30:03 AM
Yeah. I have written this batch file before. Just can't remember what forum I posted it in.
Title: Re: Seeking help to move files from specifically named directory up one level
Post by: foxidrive on December 14, 2014, 03:09:35 AM
This is untested:

This is supposed to process the folders called "_unknown" and move all files up one folder and remove the "\_unknown" folder.

It is designed to process the folders below the current folder - so test it well in a test folder with copies of your data.

If there are HUGE numbers of folders and long paths that match, then it could take a long time to begin. 
If so then there is a different way to approach this.

Code: [Select]
@echo off
for /f "delims=" %%a in (' dir /b /s /ad "_unknown" ^|find /i "\_unknown" ') do (
    echo processing "%%a"
    pushd "%%a" &&(move * .. & popd)
    rd "%%a" 2>nul
)
pause
Title: Re: Seeking help to move files from specifically named directory up one level
Post by: fleisch on December 14, 2014, 03:24:39 PM
Thank you very much.  That did the trick!