Computer Hope
Microsoft => Microsoft DOS => Topic started by: liechie on January 17, 2017, 09:05:23 AM
-
Hi i'm an imposition specialist. I need to move files that are all present in one folder to folders that are of the file names. formats are (2).pdf and .psd. I need a batch file that will read the file name, make a folder of part of that file name and move all files that start with that file name into that folder regardless the extension.
For example, if I have 9 files named as
111111_1_abcde - pdf
111111_001_Cut - psd
111111_1_Bar - pdf
222222_2_abcde - pdf
222222_002_Cut - psd
222222_2_Bar - pdf
333333_ 3_2S_100 - pdf
333333_3_Barcode - psd
333333_A_-003_Cut - pdf
I need a batch file that will make folders 111111, 222222 and 333333 and move all the respective files into the respective folders. So, files 111111_1_abcde - pdf, 111111_001_Cut - psd, 111111_1_Bar - pdf will be in folder named after the fiest pdf w/c is files 111111_1_abcde - pdf that doesn't have extension of Bar.
I'm researching every now and then to figure this out that I just came up making 1 folder for the example mentioned above and not 3. I've been to stock overflow and other sites that helps in coding but ends up always a mistake.
For this i tried these programs with the basic language that i have about dos programming and using examples from other thread is this website
http://www.computerhope.com/forum/index.php?topic=152980.0
I'm hoping that some script geek will have a lil time for this. It will be very appreciated
thanks in advance!
-
I am not understanding what you want the folder names to be with your given example because this statement confuses me.
So, files 111111_1_abcde - pdf, 111111_001_Cut - psd, 111111_1_Bar - pdf will be in folder named after the fiest pdf w/c is files 111111_1_abcde - pdf that doesn't have extension of Bar.
-
I'll make a more understandable example, sorry for typography error and confusing
111111_1_abcde - pdf
111111_001_Cut - psd
111111_1_Bar - pdf
created folder name: 111111_1_abcde
thanks a lot
-
For example, if I have 9 files named as
111111_1_abcde - pdf
111111_001_Cut - psd
111111_1_Bar - pdf
222222_2_abcde - pdf
222222_002_Cut - psd
222222_2_Bar - pdf
333333_ 3_2S_100 - pdf
333333_3_Barcode - psd
333333_A_-003_Cut - pdf
So these files have no file extension?
I am also confused on which file from the 333333 set is supposed to be used for the folder name?
-
folder name: 111111_1_abcde
111111_1_abcde - pdf
111111_001_Cut - psd
111111_1_Bar - pdf
folder name: 222222_2_abcde
222222_2_abcde - pdf
222222_002_Cut - psd
222222_2_Bar - pdf
folder name: 333333_ 3_2S_100
333333_ 3_2S_100 - pdf
333333_3_Barcode - psd
333333_A_-003_Cut - pdf
they are pdf and a psd. each folder will have 2 pdf and 1 psd
-
here's another example
folder name will be: 306113_A_3
306113_A_3
306113_A_BAR
306113_003_Cut
thank a lot!
-
they are pdf and a psd. each folder will have 2 pdf and 1 psd
Then why are you providing file name examples with a space dash space for the file extension.
This seems to make more sense to me.
333333_ 3_2S_100.pdf
333333_3_Barcode.psd
333333_A_-003_Cut.pdf
-
correct, they are just the file format
I just use dash space to indicate that it's a pdf/psd
names will be just
111111_1_abcde
111111_001_Cut
111111_1_Bar
222222_2_abcde
222222_002_Cut
222222_2_Bar
333333_ 3_2S_100
333333_3_Barcode
333333_A_-003_Cut
306113_A_3
306113_A_BAR
306113_003_Cut
hope that this will help
thanks again
-
correct, they are just the file format
I just use dash space to indicate that it's a pdf/psd
names will be just
111111_1_abcde
111111_001_Cut
111111_1_Bar
222222_2_abcde
222222_002_Cut
222222_2_Bar
333333_ 3_2S_100
333333_3_Barcode
333333_A_-003_Cut
306113_A_3
306113_A_BAR
306113_003_Cut
hope that this will help
thanks again
So now the file names have no extension?
-
yes they do not have, I just used that dash space to indicate its file format
-
yes they do not have, I just used that dash space to indicate its file format
Are you using Windows? Windows can only identify the file type and open files based on the file extension. It will not show the correct icon for a file without it.
-
sorry I made a confusion again,
these are the file formats
333333_ 3_2S_100.pdf
333333_3_Barcode.psd
333333_A_-003_Cut.pdf
306113_A_3.pdf
306113_A_BAR.psd
306113_003_Cut.pdf
sorry for the late reply
-
Hi Everyone,
Im not that good is scripting and It will be very appreciated if someone will spend a minute with this on
is it possible for a batch script to open a folder and arranged like this
(http://img04.deviantart.net/fcee/i/2017/024/b/6/2_by_kukang-dawkiko.jpg)
(http://img05.deviantart.net/5d16/i/2017/024/5/a/1_by_kukang-dawkih9.jpg)
thanks!
-
Please don't start multiple threads for the same question. I merged the two threads into this one.
-
Also the image is impossible to view...
-
save below line as myvbs.vbs
change line 13 to the target folder also
---------------------------------------------------------
Option Explicit
On Error Resume Next
Dim T
dim fs
dim folder
dim files
dim file
Dim oFSO
Dim X
Set fs = CreateObject("Scripting.FileSystemObject")
'Directory you want sorted
Set folder = fs.GetFolder("c:\myvbs\")
Set files = folder.Files
For Each file in files
If file.name = "myvbs.vbs" Then
rem wscript.echo "oops found myself"
Else
T = Mid(file.name,1,len(file.name) - 4)
MD(T)
Set oFSO = CreateObject ("Scripting.FileSystemObject")
X = folder & "\" & T & "\"
oFSO.MoveFile file.name,X & file.name
End IF
Next
Private Function MD(X)
Dim objFS, objFol
Set objFS = CreateObject("Scripting.FileSystemObject")
Set objFol = objFS.CreateFolder(X)
End function
-
Looks like your code is creating a folder for each file name. Which is not what the user asked. Of the set of three files, there should only be one folder created and the three files moved to that folder. Also, why not just use .GetBaseName(strPath) instead of stripping the extension with -4. Many file extensions these days are no longer dot 3.
-
it would be more efficient if it didnt try to make a folder each time, but the outcome is the same. good point with getbasename.
i have cleaned it up a little bit and added what you said , also filename is irrelevant now as long as it has a .vbs extension , and it will just run in the folder it is in.
___________________________________
Dim T , fs, folder, files, file ,X , objFol
Set fs = CreateObject("Scripting.FileSystemObject")
Set folder = fs.GetFolder(WScript.ScriptFullName & "\..")
Set files = folder.Files
For Each file in files
If Not file.name = Wscript.ScriptName Then
T = fs.getbasename(file.name)
Set objFol = FS.CreateFolder(T)
X = folder & "\" & T & "\"
FS.MoveFile file.name,X & file.name
End IF
Next
-
not even a thankyou for solving this problem after a year :'(
-
not even a thankyou for solving this problem after a year :'(
If you are here for teh th4nxx you are in the wrong place.