Mourning the loss of our friend, WhitPhil.
There's no such thing as a stupid question, but they're the easiest to answer.
JoinTour
Login
Search
 
DOS/PDA/Other
Tag Cloud
access audio black screen blue screen boot bsod connection crash dell desktop drivers dvd email error excel firefox hard drive hardware hijackthis internet keyboard laptop malware monitor motherboard network networking outlook problem ram recovery router safe mode screen slow sound spyware tdlwsp.dll trojan upgrade vba video virus vista vundo windows windows 7 windows vista windows xp wireless
Search
Search for:
Tech Support Guy Forums > Operating Systems > DOS/PDA/Other >
Solved: Batch file: File sorting

Tip: Click here to scan for System Errors and Optimize PC performance
[ Sponsored Link ]

 
Thread Tools
xibit1987's Avatar
Computer Specs
Junior Member with 3 posts.
 
Join Date: Oct 2009
Experience: Bit more than basic batch
14-Oct-2009, 03:55 PM #1
Smile Solved: Batch file: File sorting
Hi Guys and Girls

I'm currently working on a very simple batch sorting "program" with drag and drop.

But I have a very strange problem. i can't drag and drop more than 38 files. then it says that i do not have permission to the drive, path or file.

i have checked every thing about the permission problem, and i have all rights to the drive, path and files.

Here is the code:
Code:
@echo off
if [%1]==[] goto :eof
:loop
IF NOT EXIST %~dp1SORTERET\ ( MKDIR %~dp1SORTERET )
IF NOT EXIST %~dp1SORTERET\file%~x1\ ( MKDIR %~dp1SORTERET\file%~x1 )
MOVE /Y %1 %~dp1SORTERET\file%~x1\
shift
if not [%1]==[] goto loop 
Basically i want the batch file to create a folder called "SORTERET" in the folder where all the files are.

And in that folder create a new folder with the extension name of the file it is handling, ect. exe.
The the folder must be called "file.exe" or even just "exe", why i want it to be called "file" first, is becaus of some of my files have no extension so when it is handling the "no extension file" it will just create a folder called "file"
Then i want to move the file to that folder.

It is working as planed. but only for 38 files at a time.
What i want it to do is sorting my mixed files folder with more than 1000 files in it.
TheOutcaste's Avatar
Computer Specs
Distinguished Member with 5,486 posts.
 
Join Date: Aug 2007
Location: Oregon, USA
Experience: Intermediate
14-Oct-2009, 07:29 PM #2
Welcome to TSG!

You are limited to 8191 characters + a CR in a command line. The files you drop will include the full path to the file, plus 2 quotes, and a space between each filename. Plus you have to add in the length of the batch file path/name as well.
Here's the result of dropping 4 files from My Documents\Tech Info on a test.cmd batch file in the C:\Test Dir folder. The line length is 313 characters.
Code:
 C:\Test Dir\Test.cmd "C:\Documents and Settings\TheOutcaste\My Documents\Tech Info\DIMM0.txt" "C:\Documents and Settings\TheOutcaste\My Documents\Tech Info\DIMM1.txt" "C:\Documents and Settings\TheOutcaste\My Documents\Tech Info\DIMM2.txt" "C:\Documents and Settings\TheOutcaste\My Documents\Tech Info\DIMM3.txt"
If you are several folders deep under My Documents it gets long quite quickly.

Would probably be better to drop the parent folder on the batch file, then use a For loop to run through each file in the folder.
Something like this should work:
Code:
@Echo Off
If [%1]==[] Goto _Usage
If Not Exist "%~1" Goto _Usage2
If Not Exist %~s1\nul Goto _Usage1
Set _Source=%1
PushD "%_Source%"
For /F "Tokens=1 Delims=" %%A In ('Dir /A-D /B %_Source%') Do (
IF NOT EXIST "%%~dpASORTERET" MKDIR "%%~dpASORTERET"
IF NOT EXIST "%%~dpASORTERET\file%%~xA" MKDIR "%%~dpASORTERET\file%%~xA"
MOVE /Y "%%A" "%%~dpASORTERET\file%%~xA"
)
PopD
Goto :EOF
:_Usage2
Echo Error: %1 does not exist.
Goto _Usage
:_Usage1
Echo Parameter Error: %1 is a file name.
Echo                : Please specify a folder name
:_Usage
Echo.
Echo %~n0 [drive:][path]foldername
Echo.
Echo.  foldername  : Name of the folder to process.
Echo.              : It must be quoted if it contains spaces and is entered
Echo.              : on the Command Line. If dropped on the batch file or it's
Echo.              : shortcut, it will be quoted automatically
Echo.
Pause
HTH

Jerry
__________________
Microsoft MVP - Windows Desktop Experience
Of course I know all the answers ; I just don't always match the answers to the right questions
Are you aware of the New Signature Limitations?
xibit1987's Avatar
Computer Specs
Junior Member with 3 posts.
 
Join Date: Oct 2009
Experience: Bit more than basic batch
15-Oct-2009, 03:52 PM #3
Thumbs up Thank you :)
You are the man

Thx so much, now i will go right ahed and test it. And i can see I have much to learn. i was looking into the FOR LOOP, but didn't quite understand it. hope i will some day

I will return as quickly as i can, and mark it as solved if it works as i planned

EDIT: It's working like a charm, i can only dream of being just as good as you

Last edited by xibit1987 : 15-Oct-2009 04:09 PM. Reason: tested program
TheOutcaste's Avatar
Computer Specs
Distinguished Member with 5,486 posts.
 
Join Date: Aug 2007
Location: Oregon, USA
Experience: Intermediate
15-Oct-2009, 05:53 PM #4
You're welcome!

Thanks for letting us know it worked.

Jerry
xibit1987's Avatar
Computer Specs
Junior Member with 3 posts.
 
Join Date: Oct 2009
Experience: Bit more than basic batch
15-Oct-2009, 06:09 PM #5
It was the least i could do, after such a great service from your side
Reply Bookmark and Share

Smart Search

Find your solution!



Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
WELCOME TO TECH SUPPORT GUY! Are you looking for the solution to your computer problem? Join our site today to ask your question -- for free! Our site is run completely by volunteers who want to help you solve your computer problems. See our Welcome Guide to get started.

Thread Tools


You Are Using:
Server ID
Advertisements do not imply our endorsement of that product or service.
All times are GMT -5. The time now is 01:20 AM.
Copyright © 1996 - 2009 TechGuy, Inc. All rights reserved.
Powered by vBulletin, Copyright © 2000 - 2009, Jelsoft Enterprises Ltd.
Powered by Cermak Technologies, Inc.