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:\Files\One.Two.Three.Four.12.34.5.pdf

The corresponding folder is named:

C:\Files\One 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.

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
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.

Not the answer you're looking for? Browse other questions tagged or ask your own question.