I have researched the similarly titled questions, but they don't appear to be quite what I need. In addition, on my first day, I had found a post (I apologize, I can't find it now, and even though I bookmarked it, the bookmark only took me to the home page for this forum), that was very similar to what I was looking for, but was unsuccessful (not batch file savvy enough), to modify it for my purposes.
What I have is a directory with several thousand pdf files.
They're named something like this.
12345.pdf,
12345.pdf,
12347.pdf,
(and so on).
In the source directory are several thousand matching folders which are named something like this:
12345_eventnumber_eventprovider,
12346_eventnumber_eventprovider,
12347_eventnumber_REF alt#_eventprovider,
(And so on).
What I want to do is have all of the pdfs magically go to their associated folders based on their filename. The whole file name for the pdfs, the first set of numbers up to the first underscore for the folders.
At any rate, here is what I ended up with (with my pathetically limited batch file skills) after modifying the other poster's file.
@Echo off
cd /d "c:\My source Directory"
setlocal enabledelayedexpansion
for %%a in (*_*.*) do (
for /f "delims=_" %%b in ("%%a") do (
set "f=%%b"
if /i "%%~xa"==".pdf" (
md "c:\My source directory" 2>nul
move "%%a" "C:\My destination directory!f:~0,-1!" >nul
)
It does understand my source directory, at least based on the results. But it was a fail as all it did was create new folders (and not all of them) in my source directory. So I'm hoping someone can help me fix it and get it to do what I want?
If it were up to me, we wouldn't be tracking file sequence by putting them each in their own little folder, but would list them in a database or some such (yes, the boss wants each file in its own little folder so he can look in the MS Window and see if any numbers are missing. Lord have mercy).
But this is not up to me. Also, though there appear to be some pretty handy little shareware or even cheap software out there, our network allows little to no outside applications. At least not without an act of congress (almost literally).
But I have great hope, seeing that the batch file seems to be going in the direction I want, so thanks in advance if anyone can straighten me out and help me get the right language.
Thanks in advance!