Problems creating a Batch script to detect files and directories that have dots in their names [closed]





.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty{ height:90px;width:728px;box-sizing:border-box;
}







0















The problem I'm having is that my file names use dots, but no spaces.
My folder names use spaces, not dots.



For example, I have a file named:



C:FilesOne.Two.Three.Four.12.34.5.pdf


The corresponding folder is named:



C:FilesOne Two Three Four


I would like a script that would detect all of the .pdf files in the C:Files directory, all of the folders in the C:Files directory, and then figure out which folder the file should be placed into based on the naming structure given previously.



I'm having a problem with the dots being in the file name, but not in the folder name, as well as the fact that there's the extra 12.34.5 at the end of the file name that is not in the corresponding folder name. Also, the extra stuff after the One.Two.Three.Four tend to change randomly. It's not always 12.34.5.



Any help I could get would be greatly appreciated.










share|improve this question















closed as too broad by BenjiWiebe, DavidPostill Mar 10 at 9:14


Please edit the question to limit it to a specific problem with enough detail to identify an adequate answer. Avoid asking multiple distinct questions at once. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.














  • 2





    Clearly this can be done with some scripting. You’d respectfully be out of your mind doing this in a batch file. Use powershell at the very least. However, we’re not a script writing service. So you’ll have to figure out how to enumerate your folder names, convert the names to contain periods and search for files that start with that name and move them. Not an easy task for a novice, but not insurmountable for the diligent.

    – Appleoddity
    Mar 10 at 5:42


















0















The problem I'm having is that my file names use dots, but no spaces.
My folder names use spaces, not dots.



For example, I have a file named:



C:FilesOne.Two.Three.Four.12.34.5.pdf


The corresponding folder is named:



C:FilesOne Two Three Four


I would like a script that would detect all of the .pdf files in the C:Files directory, all of the folders in the C:Files directory, and then figure out which folder the file should be placed into based on the naming structure given previously.



I'm having a problem with the dots being in the file name, but not in the folder name, as well as the fact that there's the extra 12.34.5 at the end of the file name that is not in the corresponding folder name. Also, the extra stuff after the One.Two.Three.Four tend to change randomly. It's not always 12.34.5.



Any help I could get would be greatly appreciated.










share|improve this question















closed as too broad by BenjiWiebe, DavidPostill Mar 10 at 9:14


Please edit the question to limit it to a specific problem with enough detail to identify an adequate answer. Avoid asking multiple distinct questions at once. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.














  • 2





    Clearly this can be done with some scripting. You’d respectfully be out of your mind doing this in a batch file. Use powershell at the very least. However, we’re not a script writing service. So you’ll have to figure out how to enumerate your folder names, convert the names to contain periods and search for files that start with that name and move them. Not an easy task for a novice, but not insurmountable for the diligent.

    – Appleoddity
    Mar 10 at 5:42














0












0








0








The problem I'm having is that my file names use dots, but no spaces.
My folder names use spaces, not dots.



For example, I have a file named:



C:FilesOne.Two.Three.Four.12.34.5.pdf


The corresponding folder is named:



C:FilesOne Two Three Four


I would like a script that would detect all of the .pdf files in the C:Files directory, all of the folders in the C:Files directory, and then figure out which folder the file should be placed into based on the naming structure given previously.



I'm having a problem with the dots being in the file name, but not in the folder name, as well as the fact that there's the extra 12.34.5 at the end of the file name that is not in the corresponding folder name. Also, the extra stuff after the One.Two.Three.Four tend to change randomly. It's not always 12.34.5.



Any help I could get would be greatly appreciated.










share|improve this question
















The problem I'm having is that my file names use dots, but no spaces.
My folder names use spaces, not dots.



For example, I have a file named:



C:FilesOne.Two.Three.Four.12.34.5.pdf


The corresponding folder is named:



C:FilesOne Two Three Four


I would like a script that would detect all of the .pdf files in the C:Files directory, all of the folders in the C:Files directory, and then figure out which folder the file should be placed into based on the naming structure given previously.



I'm having a problem with the dots being in the file name, but not in the folder name, as well as the fact that there's the extra 12.34.5 at the end of the file name that is not in the corresponding folder name. Also, the extra stuff after the One.Two.Three.Four tend to change randomly. It's not always 12.34.5.



Any help I could get would be greatly appreciated.







windows batch batch-file filenames






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Mar 10 at 5:24









JakeGould

32.8k10100142




32.8k10100142










asked Mar 10 at 5:11









Ed VEd V

1




1




closed as too broad by BenjiWiebe, DavidPostill Mar 10 at 9:14


Please edit the question to limit it to a specific problem with enough detail to identify an adequate answer. Avoid asking multiple distinct questions at once. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.









closed as too broad by BenjiWiebe, DavidPostill Mar 10 at 9:14


Please edit the question to limit it to a specific problem with enough detail to identify an adequate answer. Avoid asking multiple distinct questions at once. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.










  • 2





    Clearly this can be done with some scripting. You’d respectfully be out of your mind doing this in a batch file. Use powershell at the very least. However, we’re not a script writing service. So you’ll have to figure out how to enumerate your folder names, convert the names to contain periods and search for files that start with that name and move them. Not an easy task for a novice, but not insurmountable for the diligent.

    – Appleoddity
    Mar 10 at 5:42














  • 2





    Clearly this can be done with some scripting. You’d respectfully be out of your mind doing this in a batch file. Use powershell at the very least. However, we’re not a script writing service. So you’ll have to figure out how to enumerate your folder names, convert the names to contain periods and search for files that start with that name and move them. Not an easy task for a novice, but not insurmountable for the diligent.

    – Appleoddity
    Mar 10 at 5:42








2




2





Clearly this can be done with some scripting. You’d respectfully be out of your mind doing this in a batch file. Use powershell at the very least. However, we’re not a script writing service. So you’ll have to figure out how to enumerate your folder names, convert the names to contain periods and search for files that start with that name and move them. Not an easy task for a novice, but not insurmountable for the diligent.

– Appleoddity
Mar 10 at 5:42





Clearly this can be done with some scripting. You’d respectfully be out of your mind doing this in a batch file. Use powershell at the very least. However, we’re not a script writing service. So you’ll have to figure out how to enumerate your folder names, convert the names to contain periods and search for files that start with that name and move them. Not an easy task for a novice, but not insurmountable for the diligent.

– Appleoddity
Mar 10 at 5:42










1 Answer
1






active

oldest

votes


















1














If you want this to happen:



file: "cat.dog.bird.tree.2345.pdf" to folder: "cat dog bird tree"
file: "egg.bacon.bread.coffee.efgh.pdf" to folder: "egg bacon bread coffee"
file: "mother.father.sister.brother.pdf" to folder: "mother father sister brother"
file: "one.two.three.four.5678.pdf" to folder: "one two three four"


...you can capture the first 4 tokens of the file name and put them back together with spaces instead of dots to form the folder name.



@echo off 
for /f "delims=" %%A in ('dir /s /b *.pdf') do (
for /f "tokens=1-4 delims=." %%B in ("%%~nA") do (
echo file: "%%A" to folder: "%%B %%C %%D %%E"
)
)


Note: this assumes that all .pdf files in the folder where the batch script is, and all subfolders, have this format: token1.token2.token3.token4 followed by some characters (or no more characters), then the .pdf extension.






share|improve this answer


























  • Thank you Michael.

    – Ed V
    Mar 10 at 21:48


















1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes









1














If you want this to happen:



file: "cat.dog.bird.tree.2345.pdf" to folder: "cat dog bird tree"
file: "egg.bacon.bread.coffee.efgh.pdf" to folder: "egg bacon bread coffee"
file: "mother.father.sister.brother.pdf" to folder: "mother father sister brother"
file: "one.two.three.four.5678.pdf" to folder: "one two three four"


...you can capture the first 4 tokens of the file name and put them back together with spaces instead of dots to form the folder name.



@echo off 
for /f "delims=" %%A in ('dir /s /b *.pdf') do (
for /f "tokens=1-4 delims=." %%B in ("%%~nA") do (
echo file: "%%A" to folder: "%%B %%C %%D %%E"
)
)


Note: this assumes that all .pdf files in the folder where the batch script is, and all subfolders, have this format: token1.token2.token3.token4 followed by some characters (or no more characters), then the .pdf extension.






share|improve this answer


























  • Thank you Michael.

    – Ed V
    Mar 10 at 21:48
















1














If you want this to happen:



file: "cat.dog.bird.tree.2345.pdf" to folder: "cat dog bird tree"
file: "egg.bacon.bread.coffee.efgh.pdf" to folder: "egg bacon bread coffee"
file: "mother.father.sister.brother.pdf" to folder: "mother father sister brother"
file: "one.two.three.four.5678.pdf" to folder: "one two three four"


...you can capture the first 4 tokens of the file name and put them back together with spaces instead of dots to form the folder name.



@echo off 
for /f "delims=" %%A in ('dir /s /b *.pdf') do (
for /f "tokens=1-4 delims=." %%B in ("%%~nA") do (
echo file: "%%A" to folder: "%%B %%C %%D %%E"
)
)


Note: this assumes that all .pdf files in the folder where the batch script is, and all subfolders, have this format: token1.token2.token3.token4 followed by some characters (or no more characters), then the .pdf extension.






share|improve this answer


























  • Thank you Michael.

    – Ed V
    Mar 10 at 21:48














1












1








1







If you want this to happen:



file: "cat.dog.bird.tree.2345.pdf" to folder: "cat dog bird tree"
file: "egg.bacon.bread.coffee.efgh.pdf" to folder: "egg bacon bread coffee"
file: "mother.father.sister.brother.pdf" to folder: "mother father sister brother"
file: "one.two.three.four.5678.pdf" to folder: "one two three four"


...you can capture the first 4 tokens of the file name and put them back together with spaces instead of dots to form the folder name.



@echo off 
for /f "delims=" %%A in ('dir /s /b *.pdf') do (
for /f "tokens=1-4 delims=." %%B in ("%%~nA") do (
echo file: "%%A" to folder: "%%B %%C %%D %%E"
)
)


Note: this assumes that all .pdf files in the folder where the batch script is, and all subfolders, have this format: token1.token2.token3.token4 followed by some characters (or no more characters), then the .pdf extension.






share|improve this answer















If you want this to happen:



file: "cat.dog.bird.tree.2345.pdf" to folder: "cat dog bird tree"
file: "egg.bacon.bread.coffee.efgh.pdf" to folder: "egg bacon bread coffee"
file: "mother.father.sister.brother.pdf" to folder: "mother father sister brother"
file: "one.two.three.four.5678.pdf" to folder: "one two three four"


...you can capture the first 4 tokens of the file name and put them back together with spaces instead of dots to form the folder name.



@echo off 
for /f "delims=" %%A in ('dir /s /b *.pdf') do (
for /f "tokens=1-4 delims=." %%B in ("%%~nA") do (
echo file: "%%A" to folder: "%%B %%C %%D %%E"
)
)


Note: this assumes that all .pdf files in the folder where the batch script is, and all subfolders, have this format: token1.token2.token3.token4 followed by some characters (or no more characters), then the .pdf extension.







share|improve this answer














share|improve this answer



share|improve this answer








edited Mar 10 at 8:41

























answered Mar 10 at 8:11









Michael HarveyMichael Harvey

38738




38738













  • Thank you Michael.

    – Ed V
    Mar 10 at 21:48



















  • Thank you Michael.

    – Ed V
    Mar 10 at 21:48

















Thank you Michael.

– Ed V
Mar 10 at 21:48





Thank you Michael.

– Ed V
Mar 10 at 21:48



Popular posts from this blog

Index of /

Tribalistas

Listed building