Specialty Forums
Security and Virus
General Hardware
CPUs/Overclocking
Networking
Digital Photo/Video
Office Software
PC Gaming
Console Gaming
Programming
Database
Web Development
Digital Home

General Forums
Windows XP
Windows Vista
Windows 95/98
Windows Me
Windows NT
Windows 2000
Win Server 2008
Win Server 2003
Windows 3.1
Linux
PDAs
BeOS
Novell Netware
OpenVMS
Solaris
Disk Op. System
Unix
Mac
OS/2

Drivers
Driver Scan
Driver Forum

Software
Automatic Updates

BIOS Updates

My Computing.Net

Solution Center

Free IT eBook

Howtos

Site Search

Message Find

RSS Feeds

Install Guides

Data Recovery

About

Home
Reply to Message Icon Go to Main Page Icon

Make new folder from file name

Original Message
Name: YACOLT
Date: February 2, 2008 at 21:50:01 Pacific
Subject: Make new folder from file name
OS: xp pro
CPU/Ram: not sure
Model/Manufacturer: not sure
Comment:
I would like to take every file name in a folder - make a new sub-folder inside that folder naming it from each file name - and then put the file in the folder that has been named after the file.

I spent over an hour on this site looking through past posts to see if I could find something I could modify - but I’m not much of a programmer. I did see stuff that was similar but I’m not even sure if I would use a batch file or DOS commands to do what I need to do.

I’m using XP professional and I saw some code that used XP to do stuff.

Could someone point me to the best way to do this?

Thanks a lot!


Report Offensive Message For Removal


Response Number 1
Name: IVO
Date: February 3, 2008 at 02:25:02 Pacific
Subject: Make new folder from file name
Reply: (edit)
If you want to run a batch, save the following code

@Echo Off
For %%J in (%1\*.*) Do (
MD %%~dpnJ
move %%J %%~dpnJ)

and at prompt type

MyBatch Your_Folder

or if you want to type just one command at prompt

For %J in (Your_Folder\*.*) Do @(MD %~dpnJ & move %J %~dpnJ)


Report Offensive Follow Up For Removal

Response Number 2
Name: klint
Date: February 3, 2008 at 06:40:00 Pacific
Subject: Make new folder from file name
Reply: (edit)
It's not quite as easy as it seems. Do you want the directory name to have the same extension as the file name? If so, you can't create a directory of the same name as an existing file name, so you'll have to create a directory with a temporary name first, then move the file into the temporary directory and finally rename the directory to the name of the file.

Even if you want to name the directory without an extension, you will still have to use a temporary name because some files may have no extension and you won't be able to create directories for them.

Now there's another problem: what name do you use as a temporary name that you can guarantee it will never clash with an existing file name?

So... easy problem, tricky solution.


Report Offensive Follow Up For Removal

Response Number 3
Name: Mechanix2Go
Date: February 4, 2008 at 02:47:22 Pacific
Subject: Make new folder from file name
Reply: (edit)
Hard tellin' why anybody would want a dir name like my.xls but if so, just increment the temp names.


=====================================
If at first you don't succeed, you're about average.

M2



Report Offensive Follow Up For Removal




Use following form to reply to current message:

   Name: From My Computing.Net Settings
 E-Mail: From My Computing.Net Settings

Subject: Make new folder from file name

Comments:

 
  Homepage URL (*): 
Homepage Title (*): 
         Image URL: 
 


Data Recovery Software




Slow boot time

Trasnferring Documents from old HD

My k8T Neo-v usb's aren't working!

Date Modified = Date Created Time

system files on removable harddrive


The information on Computing.Net is the opinions of its users. Such opinions may not be accurate and they are to be used at your own risk. Computing.Net cannot verify the validity of the statements made on this site. Computing.Net and Computing.Net, LLC hereby disclaim all responsibility and liability for the content of Computing.Net and its accuracy.
PLEASE READ THE FULL DISCLAIMER AND LEGAL TERMS BY CLICKING HERE

All content ©1996-2007 Computing.Net, LLC