473,326 Members | 2,805 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,326 software developers and data experts.

how to allocate file to perticular folde by name

seshu
156 100+
hi every body
this is seshu i have a problem in moveing files in a folder to to anther file the problem is like this in a folder with name files i have nine files with names abc1,abc2,abc3,seshu1,seshu2,seshu3,ram1,ram2,ram3 now i want to move the files with name abc tp folder abc ,files with name seshu to folder seshu and files with name ram to folder ram
how is it possible please some one of u give a clue how to do this
thanking you
regards
seshu
Jan 3 '07 #1
8 1357
axtens
32
hi every body
this is seshu i have a problem in moveing files in a folder to to anther file the problem is like this in a folder with name files i have nine files with names abc1,abc2,abc3,seshu1,seshu2,seshu3,ram1,ram2,ram3 now i want to move the files with name abc tp folder abc ,files with name seshu to folder seshu and files with name ram to folder ram
how is it possible please some one of u give a clue how to do this
thanking you
regards
seshu
Do you know what all the folders names are going to be? or are they simply the first part of each filename before the numbers?

I can suggest a VBScript technique. However, CMD has a simple way of doing this:
Expand|Select|Wrap|Line Numbers
  1. MD ABC
  2. MD SESHU
  3. MD RAM
  4. MOVE ABC*.* ABC
  5. MOVE SESHU*.* SESHU
  6. MOVE RAM*.* RAM
  7.  
Jan 3 '07 #2
seshu
156 100+
Sir iam very thank ful for your suggetion but i dint under stand any i mean i have very knowledge in this vb so if can please give help in explaing it detailedly
thanking you
regards
seshu
Jan 3 '07 #3
Killer42
8,435 Expert 8TB
Sir iam very thank ful for your suggetion but i dint under stand any i mean i have very knowledge in this vb so if can please give help in explaing it detailedly
thanking you
regards
seshu
Very important question - do the folders already exist?

If so, you could set up a fairly simple process to do something like this...
Expand|Select|Wrap|Line Numbers
  1. For each SubFolder in this folder
  2.   Find Files whose name starts with SubFolder name
  3.     Move File to SubFolder
  4.   Loop
  5. Loop
Does that sound like what you want to do? If so, I or others here can help you put together the code to do it.

If not, please try to describe in detail what you want to achieve. I think the overall idea is clear, but there are details missing such as:
  • Do the folders already exist?
  • Do you need to create the folders?
  • Do you know in advance which files/folders to process, or do you need the code to find them all and work it out?
  • Are all files to be moved, or only certain ones? Which ones?
Jan 4 '07 #4
seshu
156 100+
i am very sorry to say this that i observed you reply a litle bit late but the question u have rosed is really imp and even estimated that and i wrote the following code
[PHP]Private Sub Command2_Click()
Dim fsys As New FileSystemObject
Dim fsys1 As New FileSystemObject
Dim fd As Folder
Dim fd1 As Folder
Dim fls As Files
Dim f As File
Dim str As String
Dim str1 As String
Dim str2 As String
Set fd = fsys.GetFolder(Dir1.Path)
Set fls = fd.Files
For Each f In fls
'Debug.Print f.Name
str = Split(f.Name, "_")(0)
str1 = Split(f.Name, "_")(1)
str2 = "C:\Documents and Settings\kseshachalam\Desktop\New Folder (2)\" & str & "\" & str1
If fsys1.FolderExists(str2) Then
fsys.CopyFile f.Path, "C:\Documents and Settings\kseshachalam\Desktop\New Folder (2)\" & str & "\" & str1 & "\"
Else
MsgBox "folder dosnt exist and is creating now"
fsys1.CreateFolder "C:\Documents and Settings\kseshachalam\Desktop\New Folder (2)\" & str
fsys1.CreateFolder "C:\Documents and Settings\kseshachalam\Desktop\New Folder (2)\" & str & "\" & str1
fsys.CopyFile f.Path, "C:\Documents and Settings\kseshachalam\Desktop\New Folder (2)\" & str & "\" & str1 & "\", True
End If

Next
End Sub[/PHP]
i dont know where the mistake has happened but it is show in an error while creating me the second folder it is sying the folder alreddy exists
please help me out
Jan 4 '07 #5
Killer42
8,435 Expert 8TB
So I believe you're saying that an "already exists" error occurs on this line?

fsys1.CreateFolder "C:\Documents and Settings\kseshachalam\Desktop\New Folder (2)\" & str & "\" & str1

I think it would be useful to know the value of all the significant variables at that time. Um... I think that would be...
  • f.Name
  • str
  • str1
  • str2
Since you just created the folder, it seems very unlikely that any folders exist within it, so perhaps you are accidentally building the same name again, or something.

Oh, and just in case you're interested, I think you could have shortened this line to...

fsys1.CreateFolder str2

P.S. Please use [code] tags, not [PHP]. Or do you use [PHP] on purpose, for the colour-coding?
Jan 4 '07 #6
seshu
156 100+
thank you sir thanks for ur quick responce by no you should have understod what i want to do any how for giveing a clear picture i shall explain you agin
here in my company i am recieving hundreds of files dialy with different name for time being let us assume there are 20 files in them five files are with this name abc_def_1 upto abc_def_5 similarly five more files like seshu_seshi_1 to seshu_seshi_5 and five more are hai_hello_1 to hai_heloo_5 and five more are net_thecripts_1 to net _thescripts _5 now all these 20 files are in one folder folder1 now i want send these files to respective folders like this the files with name abc _def_1 to 5 are to be sent into the folder def which is a sub folder of abc similarly all for the first file i can create folder and sib folder but what should be the code for if the folder all reddy exists i think you got me please help me sir
thanking you
regards
seshu
Jan 5 '07 #7
Killer42
8,435 Expert 8TB
Hm... I have an idea. I'm trying to quickly interpret the code here, so I may get it wrong. But how does this sound...

I think you are trying to create two levels of directories, when one of them already exists.

For example, let's assume you find these two files:
  • abc_def1
  • abc_ghi1
I believe your code will first check and find that folder abc\def\ doesn't exist. It will create folder abc\, then create folder abc\def\, and move file abc_def1 into it.

Then for the second file, it will see that folder abc\ghi\ doesn't exist, so it will create folder abc\, then create folder abc\ghi\, and move file abc_ghi1 into it. But this process will fail, because folder abc\ already exists.

I think that you need to check each level before creating it, but you are just checking the lower level (def\ or ghi\ in this example) then trying to create both levels.

Does this sound reasonable?
Jan 5 '07 #8
seshu
156 100+
thank you sir
i could do it
and it ios even working tooo
Jan 5 '07 #9

Sign in to post your reply or Sign up for a free account.

Similar topics

0
by: Rob Tomson | last post by:
--C#, VS.net 2003, WinXP SP1- how can i copy a file to a website, ie. file.ext ---> http://site.site.com/folde the way i've been putting my files in is creating a webfolder in windows and then...
3
by: chetan | last post by:
Hi , myself Chetan Is There anybody could help me ? I am working on the project in c++ ,, I am in great confusion that should I export c++ member functions OR methods to create objects of...
8
by: M. Moennigmann | last post by:
Dear all: I would like to write a function that opens a file, reads and stores data into an 2d array, and passes that array back to the caller (=main). The size of the array is not known before...
0
by: ripal.soni | last post by:
Hi there I am .net developer ,right now working on a project in that i need to print pdf file using vb.net and i also have to pass printer name as argument ,file should be printed on a...
3
by: valerio | last post by:
Hello all I would like to dinamically allocate an array of array of structures. To explain this: struct file{ char* fileName,int inode) myfiles; struct file{ char* fileName,int inode) mydirs; ...
0
by: singhipst | last post by:
Hi All, I am very new in VB. Can anybody please give me sample source code for serching a perticular string in a text file and its count in some Grid. Description of problem: I will...
1
seshu
by: seshu | last post by:
Hi everybody this is seshu long back i remember me posting a code in vb how write a for each loop and getting the names of ech file in a perticular folder but today i want a...
14
by: blueboy | last post by:
Hi, I am planning to automate a nighty restore of a DB on another server can someone point me in the right direction with the SQL script to modify the logical file names to the correct path and...
2
mafaisal
by: mafaisal | last post by:
Hello Experts I am Using vb.net2005 How To Know a File or Folde is Exist in Specific Folder Using vb.net2005 eg : test.txt this file is exist in D:\Faisal Hw to check this Faisal
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.