I have some pdf files in a dir with a code in the name and I need to find the same code and export to a txt file separated by commas. Like this:009900(2).pdf, 009900(3).pdf, 012345(2).pdf, 012345(3).pdf, 012345(4).pdf >> 012345.csv (This file will contain the text: 012345(2).pdf, 012345(3).pdf, 012345(4).pdf) and 009900.csv (This file will contain exactly :009900(2).pdf, 009900(3).pdf)
Please I need so much this bat.
HELP!List the same prefix files in a txt separated by commas
Moderator: DosItHelp
-
- Expert
- Posts: 442
- Joined: 01 Aug 2010 17:13
- Location: Canadian Pacific
- Contact:
Re: HELP!List the same prefix files in a txt separated by co
So many repeat question types lately, hmm...
Puts all 009900*.pdf filenames CSV'ed into 009900.csv.
Puts all 012345*.pdf filenames CSV'ed into 012345.csv.
Puts all 009900*.pdf filenames CSV'ed into 009900.csv.
Puts all 012345*.pdf filenames CSV'ed into 012345.csv.
Code: Select all
setlocal enabledelayedexpansion
:: Make sure this ends with \
set "target=C:\...\Target Folder\"
for %%x in ("%target%*.pdf") do (
set "name=%%~nx"
if "!name:~0,6!"=="009900" set "out009900=!out009900!%%~nxx, "
if "!name:~0,6!"=="012345" set "out012345=!out012345!%%~nxx, "
echo:%%x
)
set "out009900=%out009900:~0,-2%"
set "out012345=%out012345:~0,-2%"
echo:!out009900!>"%target%009900.csv"
echo:!out012345!>"%target%012345.csv"
-
- Posts: 319
- Joined: 12 May 2006 01:13
Re: HELP!List the same prefix files in a txt separated by co
here's a vbscript
usage:
Code: Select all
Set objFS = CreateObject("Scripting.FileSystemObject")
strFolder="c:\test"
Set objFolder = objFS.GetFolder(strFolder)
For Each strFile In objFolder.Files
If objFS.GetExtensionName(strFile) = "pdf" Then
strFileName = strFile.Name
m = InStr(strFileName,"(")
If m > 0 Then
number= Mid(strFileName,1,m-1)
strNewFileName = number&".csv"
If Not objFS.FileExists(strNewFileName) Then
Set objNewFile = objFS.CreateTextFile(strNewFileName,True)
Else
Set objNewFile = objFS.OpenTextFile(strNewFileName,8)
End If
objNewFile.Write(strFileName &",")
objNewFile.Close
End If
End If
Next
usage:
Code: Select all
c:\test> cscript //nologo myscript.vb
-
- Posts: 319
- Joined: 12 May 2006 01:13
Re: HELP!List the same prefix files in a txt separated by co
orange_batch wrote:So many repeat question types lately, hmm...
Puts all 009900*.pdf filenames CSV'ed into 009900.csv.
Puts all 012345*.pdf filenames CSV'ed into 012345.csv.
but it doesn't cater for other numbers...
-
- Expert
- Posts: 442
- Joined: 01 Aug 2010 17:13
- Location: Canadian Pacific
- Contact:
Re: HELP!List the same prefix files in a txt separated by co
Hello, thanks for all!
In the Vb Script how can I include the file without "(x)" if I have? Like this: 009900.pdf, 009900(2).pdf, 009900(3).pdf, 012345(2).pdf, 012345(3).pdf, 012345(4).pdf >> 012345.csv
Thank you again!
In the Vb Script how can I include the file without "(x)" if I have? Like this: 009900.pdf, 009900(2).pdf, 009900(3).pdf, 012345(2).pdf, 012345(3).pdf, 012345(4).pdf >> 012345.csv
Thank you again!
-
- Posts: 319
- Joined: 12 May 2006 01:13
Re: HELP!List the same prefix files in a txt separated by co
Code: Select all
....
m = InStr(strFileName,"(")
If m > 0 Then
....
else
' if there is no "(" in the file name
' do your stuff here.
end if