1.

Solve : Part filename to folder (dos)?

Answer»

Hello,

I've asked this question also on a other forum, but it seems that that forum mostly uses powershell. Unfortunaltely i am unable to use this.
For a while now i've been trying to FIGURE out how to make a dos command that can "see" part of a file name, then create a folder and sort every file which has that part of a filename in it.

Every filename has the following characters (excluding the extension):

3 letters, 5 digits, 1 letter, 1 digit
For example: BBB12345B0

Each letter and number in the filename can vary, but the filename will allway's have the same build.
What the script is supposed to do is recognize only the 5 digits, then create a folder from those 5 digits and then move those files to that folder.

The following i found on the internet:

@echo off
for /f "delims=" %%a in ('dir /b /a-d') do (
if not "%%~fa"=="%~f0" (
md "%%~na" 2>nul
if exist "%%a" move "%%~na.*" "%%~na"
)
)

This works great, except that the whole filename is used to create a folder and sort the files. I want the script to do the same thing but only using the 5 digits.

I've tried to work with "tokens" in this script. Also used some onther methods but none of them work properly. I'm also not so familiar with this kind of batch SCRIPTING. Can anyone help me with this?
You also got a batch solution on another forum.

You failed to respond in any way at all, and the only issue with it was that the filter for the batch filename itself needed fixing.

Code: [Select]@echo off
for %%a in (
BBB11345B0
BBB12345B0
BBB13345B0
BBB14345B0
BBB15345B0
BBB16345B0
) do type nul >%%a

@echo off
setlocal enabledelayedexpansion
for /f "delims=" %%a in ('dir /b /a-d') do (
if /i not "%%a"=="%~nx0" (
echo moving "%%a"
set "name=%%a"
md "!name:~3,5!" 2>nul
move "%%a" "!name:~3,5!" >nul
)
)Quote from: foxidrive on February 18, 2014, 05:28:38 AM

You also got a batch solution on another forum.

I believe i said that in my first post. The sollutions given involved Powershell.
I cannot run powershell, because of a rights problem on my terminal.

Quote from: foxidrive on February 18, 2014, 05:28:38 AM
You failed to respond in any way at all.....

I find this a little OFFENSIVE, so please clarify.
In my opinion i did reply (superuser.com) on every notification/respond I got from the website/users.

This script works perfect btw!
Quote from: SHAPE on February 18, 2014, 06:31:30 AM
I believe i said that in my first post. The sollutions given involved Powershell.
I cannot run powershell, because of a rights problem on my terminal.

Read what I wrote. You got a BATCH solution.

Quote from:
I find this a little offensive, so please clarify.

You are offended?? You posted the question to so many places you obviously forgot to check them all.

4 Days ago.
http://stackoverflow.com/questions/21774670/make-folder-from-part-of-a-filename-and-move-the-files-thereQuote from: Shape on February 18, 2014, 06:31:30 AM
I cannot run powershell, because of a rights problem on my terminal.
Doesn't have anything to do with rights. Powershell defaults to that setting. You just need to change the setting.
http://technet.microsoft.com/en-us/library/ee176949.aspxQuote from: foxidrive on February 18, 2014, 06:43:03 AM
Read what I wrote. You got a BATCH solution.

You are offended?? You posted the question to so many places you obviously forgot to check them all.

You're writing as if i intentionally post my question "everywhere" but do not take the effort of answering them all. That is certainly not the case. I welcome and appriciate ideas and sollutions posted. I will respond to posts/solutions given to me, if i know how to get there.

First of all, I am a "newbie" to stackoverflow.com. If I log in on Stackoverflow.com, and i want to see my posts i'm rerouted to superuser.com. I do not see the post you are refering to (see link from squashman). I also did not get an "email warning" that someone has handed me a option/sollution. Only got email warning from superuser.com.

So i'm sorry that i did not respond to your sollution of batch scripting, but you offended me when you said that "i failed to respond in every way at all". I believe that i did saw every post when i log in to stackoverflow.com.
It is my intention to respond to every post.

I'm am gratefull for your sollution, so thank you very much.
It works flawless and it makes my (working) life certainly more pleasant

Quote from: Squashman on February 18, 2014, 07:34:36 AM
4 Days ago.
http://stackoverflow.com/questions/21774670/make-folder-from-part-of-a-filename-and-move-the-files-there

Hello Squashman.
Thanks for the link.
I will look further in the powershell option.I just found your post on StackOverFlow by using a novel approach CALLED Google.


Discussion

No Comment Found