If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below. |
|
|
Thread Tools | Rate Thread | Display Modes |
#1
|
|||
|
|||
Sorting Files Into Separate Directories Based on the First 2 Characters of the Filename
I have TONS of fonts that I use in my graphic design business. Over
300,00 0of them to be exact. I don't use all 300K of them, but I like to keep them organized in folders based on the first two characters of the file name. After they're renamed, then are put into a Sorting folder in one huge group. My batch file moves them into the appropriate folders. The ones starting with letters and numbers are easy, as are most of the ones that start or have a non-alphanumeric character in the first two positions. There are some files that may start with A&, and a few other chracters (that can be used in files names of course) that don't sort. I get an error saying it can't find the file. We all know the & is used as an accelerator key in Windows, but it is a legal filename character, so I am wondering how i can do a simple move with the combo of chracters. It's been decades since I used DOS batch files on a regular basis, so some of the more refined detials escapes me because i'm getting old and senile. Oh, and if I didn't mention it, I'm getting old and senile. A lline of my batch file looks like this: move /y e:\fonts\!Renamed2Sort\Aa*.ttf E:\Fonts\Fonts\A\aa A very simple move. My folder structure looks like this: e:\fonts\a\a# (first char "a", second char non-alpha) e:\fonts\a\a0 (first char "a", second char number 0-9) e:\fonts\a\aa ... e:\fonts\a\az e:\font\b\b# ... A few of those lines look like this: move /y e:\fonts\!Renamed2Sort\A!*.ttf E:\Fonts\Fonts\A\a# move /y E:\Fonts\Fonts\A\a# move /y e:\fonts\!Renamed2Sort\A#*.ttf E:\Fonts\Fonts\A\a# move /y e:\fonts\!Renamed2Sort\A%*.ttf E:\Fonts\Fonts\A\a# move /y e:\fonts\!Renamed2Sort\A^*.ttf E:\Fonts\Fonts\A\a# move /y e:\fonts\!Renamed2Sort\A&*.ttf E:\Fonts\Fonts\A\a# move /y e:\fonts\!Renamed2Sort\A(*.ttf E:\Fonts\Fonts\A\a# move /y e:\fonts\!Renamed2Sort\A)*.ttf E:\Fonts\Fonts\A\a# move /y e:\fonts\!Renamed2Sort\A[*.ttf E:\Fonts\Fonts\A\a# move /y e:\fonts\!Renamed2Sort\A]*.ttf E:\Fonts\Fonts\A\a# Filenames sometimes have some crazy combos, so originally I was going to have a line in the batch file for each legal character. So the basic question after all my rambling is, how do I move all files that start with a letter then following by any non-alpha-numeric character into the x# folder? I have over 30G of fonts in 826 folders. I was thinking about creating a 3 character directory structure, but the amount of folder names got to be HUGE. (Not that there isn't a decent amount of them already...) Anyone have any good ideas? Thanks! Mike |
Ads |
#2
|
|||
|
|||
Sorting Files Into Separate Directories Based on the First 2 Characters of the Filename
"FontLeroy" wrote:
I have TONS of fonts that I use in my graphic design business. Over 300,00 0of them to be exact. I don't use all 300K of them, but I like to keep them organized in folders based on the first two characters of the file name. After they're renamed, then are put into a Sorting folder in one huge group. My batch file moves them into the appropriate folders. The ones starting with letters and numbers are easy, as are most of the ones that start or have a non-alphanumeric character in the first two positions. There are some files that may start with A&, and a few other chracters (that can be used in files names of course) that don't sort. I get an error saying it can't find the file. Did you enclose the path\file or a variable used to hold that with double quote characters, the same as you have to do to account for paths or filenames that may contain spaces? & is not a valid as the FIRST character of a path or file name due to parsing problems in the command interpreter. If you try to run: echo hello &myfile.txt you'll get: & was unexpected at this time. That's because the interpreter saw the ampersand as a command delimiter (see below). echo hello "&myfile.txt" returns: The handle could not be duplicated during redirection of handle 1. We all know the & is used as an accelerator key in Windows, Not in a .bat file. Accelerator keys are menu entries that have a specific character in their string that a single keypress of that same character will activate that menu entry. There are no menus in a batch file. but it is a legal filename character, so I am wondering how i can do a simple move with the combo of chracters. The command delimiter character (ampersand) is used to specify multiple commands within the same input line. command1 && command2 execute command1 if command1 was successful (errorlevel = 0) then execute command2 command1 & command2 execute command1 execute command2 (regardless of whether command1 was successful or not) A single & means to list multiple commands in one line where all of the commands get executed. && means the next command depends on successful completion of the prior command. For example: cls & dir *.abc & dir *.xyz will clear the screen and run BOTH the 'dir' commands whereas: cls & dir *.abc && dir *.xyz clears the screen, runs the first 'dir' command, but the 2nd 'dir' command doesn't run unless errorlevel=0 from the first 'dir' command. Since it is unlikely you have .abc files then the 2nd 'dir' never executes. Since 'cls' is always successful, it doesn't matter if you follow it with & or &&. While spacing is shown above, it is not required. For example: echo hello myfile.txt and echo hellomyfile.txt and dir *.abc & dir *.xyz and dir *.abc&dir *.xyz are the same commands. Whitespacing, when not required, is only to provide legibility to humans. The above points out confusion when you use a leading ampersands as a character in a filename because the parser might not understand the scope of your use. copy myfile.txt "&myfile.txt" will work because 'copy' expects a 2nd argument and enclosing it in double quotes escapes the usually meaning of ampersand. If the double quotes were missing then it would look like: copy myfile.txt &myfile.txt which is the same as: copy myfile.txt & myfile.txt which means to do a 'copy' command with a missing 2nd parameter and trying to use the .txt filetype association to open whatever program is assigned to that filetype (e.g., Notepad). The result of not quoting the 2nd argument would result in the interpreter reporting "The file cannot be copied onto itself" for the 'copy' command that was missing the 2nd (output) parameter and loading Notepad to view myfile.txt. Using an ampersand as the first character of a filename is fraught with unexpected errors due to parsing problems. Don't do it. And when you use the ampersand within a filename, make damn sure to enclose the path or filename or both with double quotes to ensure the parser understands that you are specifying one string and not using the command delimiter. If I meant to copy myfile.txt into &myfile.txt (a bad choice), I'd use: copy myfile.txt "&myfile.txt" Later when I want to delete the 2nd file, I can't run: del &myfile.txt because that looks to the parser to be a 'del' command with no parameters followed by just a filename of myfile.txt. I have to use: del "&myfile.txt" Anytime you have special characters in paths or filenames that could be interpreted by the parser means having to double-quote the string; however, that sometimes doesn't work. You should already know that: dir C:\Program Files won't work because the 'dir' command uses whitespace for parsing which means it see TWO parameters: "C:\Program" and "Files". You must use: dir "C:\Program Files" It's been decades since I used DOS batch files on a regular basis, so some of the more refined detials escapes me because i'm getting old and senile. Oh, and if I didn't mention it, I'm getting old and senile. A lline of my batch file looks like this: move /y e:\fonts\!Renamed2Sort\Aa*.ttf E:\Fonts\Fonts\A\aa A very simple move. You have to forget about what you are entering for a command and consider that command gets executed when the list gets expanded. The 'move' command isn't grabbing a whole bunch of files as one unit and copying them as one object. It expands that wildcarded list and executes the command on each expansion. You sure you don't want to enclose those parameters with double quotes? Are you sure that none of the fonts' filenames have spaces in them? What if a font was named "Moby Dick Eats Jonah.ttf" and you ran a single move command against that file, as in: move Moby Dick Eats Jonah.ttf destination The 'move' command has FOUR parameters, not one. The above command would specify to move 3 files (Moby, Dick, Eats, and Jonah.ttf) into the destination. You need to use double quotes as in: move "Moby Disk Eats Jonah.ttf" destination Unless you have a means of guaranteeing that every file will not contain a space or other special character then you need to delineate the string by using double quotes. The 'move' command is going to expand the list of wildcarded substrings and use those. That means 'move fil*" could hit an instance of a file named "file&rank". That instance from the expansion would look like: file&rank so 'move would try to execute: move file&rank target As above explained, parsing will screw up because you're specified a command delimiter in the expanded string for a particular instance. If you double-quoted the parameters then 'move "fil*"' would hit: file&rank but add the double quotes to become: "file&rank" and the instance command of: move "file&rank" target would work. Even if you believe that no paths or files involved in a batch or DOS prompt command will involve spaces, command delimiters, or other special characters, just get in the habit of always enclosing string parameters for paths, files, or both with double quotes. My folder structure looks like this: e:\fonts\a\a# (first char "a", second char non-alpha) e:\fonts\a\a0 (first char "a", second char number 0-9) e:\fonts\a\aa ... e:\fonts\a\az e:\font\b\b# ... A few of those lines look like this: move /y e:\fonts\!Renamed2Sort\A!*.ttf E:\Fonts\Fonts\A\a# move /y E:\Fonts\Fonts\A\a# move /y e:\fonts\!Renamed2Sort\A#*.ttf E:\Fonts\Fonts\A\a# move /y e:\fonts\!Renamed2Sort\A%*.ttf E:\Fonts\Fonts\A\a# move /y e:\fonts\!Renamed2Sort\A^*.ttf E:\Fonts\Fonts\A\a# move /y e:\fonts\!Renamed2Sort\A&*.ttf E:\Fonts\Fonts\A\a# move /y e:\fonts\!Renamed2Sort\A(*.ttf E:\Fonts\Fonts\A\a# move /y e:\fonts\!Renamed2Sort\A)*.ttf E:\Fonts\Fonts\A\a# move /y e:\fonts\!Renamed2Sort\A[*.ttf E:\Fonts\Fonts\A\a# move /y e:\fonts\!Renamed2Sort\A]*.ttf E:\Fonts\Fonts\A\a# Filenames sometimes have some crazy combos, so originally I was going to have a line in the batch file for each legal character. So the basic question after all my rambling is, how do I move all files that start with a letter then following by any non-alpha-numeric character into the x# folder? I have over 30G of fonts in 826 folders. I was thinking about creating a 3 character directory structure, but the amount of folder names got to be HUGE. (Not that there isn't a decent amount of them already...) Anyone have any good ideas? Thanks! Mike Currently I have 288 fonts. In the past, I've had over 800 fonts. None of them used a non-alphanumeric character in their filenames. I suspect the non-alphanumeric characters were your addition, not how they were named from the font foundary. Use of ampersand, caret, and other non-alphanumeric characters can result in parsing problems. For now, see what happens when you encapsulate your path and/or file parameters in the commands within double quotes. |
#3
|
|||
|
|||
Sorting Files Into Separate Directories Based on the First 2 Characters of the Filename
On Fri, 25 Jan 2013 11:25:32 -0600, VanguardLH wrote:
"FontLeroy" wrote: I have TONS of fonts that I use in my graphic design business. Over 300,00 0of them to be exact. I don't use all 300K of them, but I like to keep them organized in folders based on the first two characters of the file name. After they're renamed, then are put into a Sorting folder in one huge group. My batch file moves them into the appropriate folders. The ones starting with letters and numbers are easy, as are most of the ones that start or have a non-alphanumeric character in the first two positions. There are some files that may start with A&, and a few other chracters (that can be used in files names of course) that don't sort. I get an error saying it can't find the file. Did you enclose the path\file or a variable used to hold that with double quote characters, the same as you have to do to account for paths or filenames that may contain spaces? & is not a valid as the FIRST character of a path or file name due to parsing problems in the command interpreter. If you try to run: echo hello &myfile.txt you'll get: & was unexpected at this time. That's because the interpreter saw the ampersand as a command delimiter (see below). echo hello "&myfile.txt" returns: The handle could not be duplicated during redirection of handle 1. We all know the & is used as an accelerator key in Windows, Not in a .bat file. Accelerator keys are menu entries that have a specific character in their string that a single keypress of that same character will activate that menu entry. There are no menus in a batch file. but it is a legal filename character, so I am wondering how i can do a simple move with the combo of chracters. The command delimiter character (ampersand) is used to specify multiple commands within the same input line. command1 && command2 execute command1 if command1 was successful (errorlevel = 0) then execute command2 command1 & command2 execute command1 execute command2 (regardless of whether command1 was successful or not) A single & means to list multiple commands in one line where all of the commands get executed. && means the next command depends on successful completion of the prior command. For example: cls & dir *.abc & dir *.xyz will clear the screen and run BOTH the 'dir' commands whereas: cls & dir *.abc && dir *.xyz clears the screen, runs the first 'dir' command, but the 2nd 'dir' command doesn't run unless errorlevel=0 from the first 'dir' command. Since it is unlikely you have .abc files then the 2nd 'dir' never executes. Since 'cls' is always successful, it doesn't matter if you follow it with & or &&. While spacing is shown above, it is not required. For example: echo hello myfile.txt and echo hellomyfile.txt and dir *.abc & dir *.xyz and dir *.abc&dir *.xyz are the same commands. Whitespacing, when not required, is only to provide legibility to humans. The above points out confusion when you use a leading ampersands as a character in a filename because the parser might not understand the scope of your use. copy myfile.txt "&myfile.txt" will work because 'copy' expects a 2nd argument and enclosing it in double quotes escapes the usually meaning of ampersand. If the double quotes were missing then it would look like: copy myfile.txt &myfile.txt which is the same as: copy myfile.txt & myfile.txt which means to do a 'copy' command with a missing 2nd parameter and trying to use the .txt filetype association to open whatever program is assigned to that filetype (e.g., Notepad). The result of not quoting the 2nd argument would result in the interpreter reporting "The file cannot be copied onto itself" for the 'copy' command that was missing the 2nd (output) parameter and loading Notepad to view myfile.txt. Using an ampersand as the first character of a filename is fraught with unexpected errors due to parsing problems. Don't do it. And when you use the ampersand within a filename, make damn sure to enclose the path or filename or both with double quotes to ensure the parser understands that you are specifying one string and not using the command delimiter. If I meant to copy myfile.txt into &myfile.txt (a bad choice), I'd use: copy myfile.txt "&myfile.txt" Later when I want to delete the 2nd file, I can't run: del &myfile.txt because that looks to the parser to be a 'del' command with no parameters followed by just a filename of myfile.txt. I have to use: del "&myfile.txt" Anytime you have special characters in paths or filenames that could be interpreted by the parser means having to double-quote the string; however, that sometimes doesn't work. You should already know that: dir C:\Program Files won't work because the 'dir' command uses whitespace for parsing which means it see TWO parameters: "C:\Program" and "Files". You must use: dir "C:\Program Files" It's been decades since I used DOS batch files on a regular basis, so some of the more refined detials escapes me because i'm getting old and senile. Oh, and if I didn't mention it, I'm getting old and senile. A lline of my batch file looks like this: move /y e:\fonts\!Renamed2Sort\Aa*.ttf E:\Fonts\Fonts\A\aa A very simple move. You have to forget about what you are entering for a command and consider that command gets executed when the list gets expanded. The 'move' command isn't grabbing a whole bunch of files as one unit and copying them as one object. It expands that wildcarded list and executes the command on each expansion. You sure you don't want to enclose those parameters with double quotes? Are you sure that none of the fonts' filenames have spaces in them? What if a font was named "Moby Dick Eats Jonah.ttf" and you ran a single move command against that file, as in: move Moby Dick Eats Jonah.ttf destination The 'move' command has FOUR parameters, not one. The above command would specify to move 3 files (Moby, Dick, Eats, and Jonah.ttf) into the destination. You need to use double quotes as in: move "Moby Disk Eats Jonah.ttf" destination Unless you have a means of guaranteeing that every file will not contain a space or other special character then you need to delineate the string by using double quotes. The 'move' command is going to expand the list of wildcarded substrings and use those. That means 'move fil*" could hit an instance of a file named "file&rank". That instance from the expansion would look like: file&rank so 'move would try to execute: move file&rank target As above explained, parsing will screw up because you're specified a command delimiter in the expanded string for a particular instance. If you double-quoted the parameters then 'move "fil*"' would hit: file&rank but add the double quotes to become: "file&rank" and the instance command of: move "file&rank" target would work. Even if you believe that no paths or files involved in a batch or DOS prompt command will involve spaces, command delimiters, or other special characters, just get in the habit of always enclosing string parameters for paths, files, or both with double quotes. My folder structure looks like this: e:\fonts\a\a# (first char "a", second char non-alpha) e:\fonts\a\a0 (first char "a", second char number 0-9) e:\fonts\a\aa ... e:\fonts\a\az e:\font\b\b# ... A few of those lines look like this: move /y e:\fonts\!Renamed2Sort\A!*.ttf E:\Fonts\Fonts\A\a# move /y E:\Fonts\Fonts\A\a# move /y e:\fonts\!Renamed2Sort\A#*.ttf E:\Fonts\Fonts\A\a# move /y e:\fonts\!Renamed2Sort\A%*.ttf E:\Fonts\Fonts\A\a# move /y e:\fonts\!Renamed2Sort\A^*.ttf E:\Fonts\Fonts\A\a# move /y e:\fonts\!Renamed2Sort\A&*.ttf E:\Fonts\Fonts\A\a# move /y e:\fonts\!Renamed2Sort\A(*.ttf E:\Fonts\Fonts\A\a# move /y e:\fonts\!Renamed2Sort\A)*.ttf E:\Fonts\Fonts\A\a# move /y e:\fonts\!Renamed2Sort\A[*.ttf E:\Fonts\Fonts\A\a# move /y e:\fonts\!Renamed2Sort\A]*.ttf E:\Fonts\Fonts\A\a# Filenames sometimes have some crazy combos, so originally I was going to have a line in the batch file for each legal character. So the basic question after all my rambling is, how do I move all files that start with a letter then following by any non-alpha-numeric character into the x# folder? I have over 30G of fonts in 826 folders. I was thinking about creating a 3 character directory structure, but the amount of folder names got to be HUGE. (Not that there isn't a decent amount of them already...) Anyone have any good ideas? Thanks! Mike Currently I have 288 fonts. In the past, I've had over 800 fonts. None of them used a non-alphanumeric character in their filenames. I suspect the non-alphanumeric characters were your addition, not how they were named from the font foundary. Use of ampersand, caret, and other non-alphanumeric characters can result in parsing problems. For now, see what happens when you encapsulate your path and/or file parameters in the commands within double quotes. That was wihtout a doubt the most informative inforamtion I have seen in DECADES! I read through it ince, but now will analyze it and fill what's left of my brain cells with this info as I restructure my batch file. I did forget about the ampersand 'function' in windows. it's been a long time... Pretty much EVERY font has spaces in there and I totally forgot aboutwhat you wrote about spaces. I'm an idiot. I used to be smart(er)... thanks again and I'm gonna get to work! Mike |
Thread Tools | |
Display Modes | Rate This Thread |
|
|