Create folders based on file names Help?

February 12, 2010 at 10:23:24
Specs: Windows XP
Hi
I use a script based on an old thread :http://www.computing.net/answers/windows-xp/create-folders-based-on-file-names/155238.html
modified to resist to filenames with space. After hours searching forums, and try and retry IT WOKS... nearly!
Iget error message "le lecteur spécifié est inftouvable" (in French) that is "drive not found" why?. Second how to get rid of repeat error message "dir already exist".
Please help me to improve my awful code.
Thanks for your help
the code:
@echo off
@SetLocal EnableDelayedExpansion

rem dir command displays :
rem dir /b all files and subdirectories in the current directory
rem dir /b /a-d For just a list of files:
rem dir /b /ad For just a list of subdirectories:
rem Like many other DOS commands the results can be piped to an external file, if desired. For

example:
rem dir /b /ad > list_of_directories.txt


::http://www.computing.net/answers/windows-xp/create-folders-based-on-file-names/155238.html
::This script creates folders based on file names and moves those files into the folders.

:: *.jpg is the search term. Change this to search for different files.
:: ne fonctionne pas avec les espaces


REM md on the first 6 characters of the file name. Change to 5% for the first 5 characters.
REM move %* %name:~0,6% will move the file to the directory based on the first 6 characters of

the file name.


for /f "tokens=*" %%i in ('dir/b/a-d *.jpg') do (

set name=%%i
::les !! sont obligatoires pour récupérer les variables dans une boucle
::echo traitement de [[%%i]] --- name[!name!]& pause
set ndir=!name:~0,13%!
::echo ndir [!ndir!] & pause
:: les guillemets sont obligatoires pour les espaces
md "!ndir!"
copy "!name!" "!ndir!">nul

)

goto :eof



See More: Create folders based on file names Help?

Report •

#1
February 12, 2010 at 12:50:31
Not sure what you are asking.

I do notice that you seem to have left the "REM" in.

The rem is a remark. It is not processed.

Playing to the angels
Les Paul (1915-2009)


Report •

#2
February 12, 2010 at 14:28:40
@echo off & setLocal EnableDELAYedeXpansion

for /f "tokens=* delims= " %%a in ('dir/b/a-d') do (
set F=%%a
set F=!F:~0,6!
if not exist !F! md !F!
move "%%a" !F!
)


=====================================
Helping others achieve escape felicity

M2


Report •

#3
February 12, 2010 at 23:14:04
Many thanks : Mechanix2Go
Both for your reply and for your speed.
Excuse the time i take for reading your post it was late at night here.


Realy sorry but your code does not work...

With th file in exemple:
Le Feul - T02 - Les Brohms - 000.jpg
Le Feul - T02 - Les Brohms - 001.jpg
Le Feul - T02 - Les Brohms - iii.jpg
it creates new folders
Feu
Le
wich stay EMPTY
If i try 12 car (the goal of the bat in this exemple) i get 5 folders (the 5 words of the 12 car)
Feu
Le
-
Feul
T0
and all stay empty.

As you see the original post was made to parse the name whith 5 or so caracters and it works well. I had to modify it to handle names like this:
Le Feul - T02 - Les Brohms - 000.jpg
Le Feul - T02 - Les Brohms - 001.jpg
Le Feul - T02 - Les Brohms - iii.jpg
so i have a collection of batchs hard coded with the number of caracters to parse .
To treat a large variety of name of files I must first put the similar names in one folder by the hand and then run the bat. Could you imagine a way to automatise the process?

Uselly the patterns of the names are:
number(s)letter(s)number(s).jpg
The only relatively fixed zone is from the end:
the extension=.jpg
just before = number from 2 to 3 digits
I think using the name minus the end of the name to choose the files to move could be the way to make a more intelligent batch. I admit this is not the kind of thing i could code.
May be you will find the solution.
Regards
thanks again
and respect for your knowlege (i believe i read 3/4 of your posts and IVO's too to achieve writing 2 lines of code)
Good night


Report •

Related Solutions

#4
February 13, 2010 at 04:51:41
change this:

if not exist !F! md !F!

to this:

if not exist "!F!" md "!F!"
---------------------------
and this:

move "%%a" !F!

to this:

move "%%a" "!F!"


=====================================
Helping others achieve escape felicity

M2


Report •

#5
February 13, 2010 at 07:27:52
waooo
it works - BRAVO

What about the second party (giving some intelligence at this bat)
May be this algo should work.

FOR each *.jpg
set activeName without extension
L=Len(activeNane)
WorkName=ActiveName
:construct
if the last car of WorkName is a digit (
L=L-1
WorkName=L (first cars of WorkName)
goto :construct
)
Here Workname is the Maximum length interresting word to sort the jpgs,
then follow treatement as the first batch.


If you have a little time how do you translate this in true batch commands.

Regards from France




Report •

Ask Question