Need Help Starting My First Code

Code helps me move files and create directories

Page 1 of 1

8 Replies - 670 Views - Last Post: 29 November 2009 - 03:04 PM Rate Topic: -----

#1 syeo  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 5
  • Joined: 29-November 09

Need Help Starting My First Code

Posted 29 November 2009 - 02:01 PM

Hi everyone,

I'm starting to learn visual basic. I'm using 2008 VB express. I'm using the online help that came with the program, but its not as detailed as I would like.

I'm currently trying to make a command line code that does something like this:

C:Unsorted\StargateXXXX\XXXXS01E09.mkv
C:Unsorted\HouseXXXXX\XXXXXS05E02.mkv
to
C:Tv Shows\Stargate\Season 1\XXXXS01E09.mkv
C:Tv Shows\House\Season 5\XXXXXS05E02.mkv

I need to program to read the initial directory to figure out what tv show directory to place the file, then I need the program to read the file name to figure out which season folder directory to place it in. It should also verify the season folder exist, and if it doesn't create it.

I'm use to coding in batch, although I'm not the greatest. There aren't very many commands for batch, but for VB there seems to be a zillion. The online guide isn't the greatest for showing me what does what. I'm starting to get confused fast, without know what does what. I've been look at example codes a lot.

Module Module1

	Sub Main()
	Read = File.OpenText(C:\tv.txt)

 While Read.Peek <> -1
	   LineIn = Read.ReadLine()

 End While

 Read.Close()


	End Sub

End Module


Will that working in pulling tv shows, line by line from a txt file?
Also should I put a for command before the end while, which executes a sub that will resolve the directory, season, and tv show? then move it before it loops back to figure out the next line of the tv.txt file?

I can't even figure out how to make the program "ECHO" the lines of the file back to me to make sure its reading correctly.

This post has been edited by syeo: 29 November 2009 - 02:29 PM


Is This A Good Question/Topic? 0
  • +

Replies To: Need Help Starting My First Code

#2 raziel_  Icon User is offline

  • Like a lollipop
  • member icon

Reputation: 464
  • View blog
  • Posts: 4,255
  • Joined: 25-March 09

Re: Need Help Starting My First Code

Posted 29 November 2009 - 02:03 PM

wrong forum dude :)
Was This Post Helpful? 0
  • +
  • -

#3 syeo  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 5
  • Joined: 29-November 09

Re: Need Help Starting My First Code

Posted 29 November 2009 - 02:09 PM

View PostNoBrain, on 29 Nov, 2009 - 01:03 PM, said:

wrong forum dude :)


Really?! I thought this is the visual basic forum.
Was This Post Helpful? 0
  • +
  • -

#4 raziel_  Icon User is offline

  • Like a lollipop
  • member icon

Reputation: 464
  • View blog
  • Posts: 4,255
  • Joined: 25-March 09

Re: Need Help Starting My First Code

Posted 29 November 2009 - 02:13 PM

it is vb6 not vb.net. i report it to be moved so pls dont make second one in vb.net forum :)

so you want to copy the files in other directory ? is that true ?

This post has been edited by NoBrain: 29 November 2009 - 02:15 PM

Was This Post Helpful? 0
  • +
  • -

#5 syeo  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 5
  • Joined: 29-November 09

Re: Need Help Starting My First Code

Posted 29 November 2009 - 02:14 PM

View PostNoBrain, on 29 Nov, 2009 - 01:13 PM, said:

it is vb6 not vb.net. i report it to be moved so pls dont make second one in vb.net forum :)


Ok, thanks. Btw whats the difference?
Was This Post Helpful? 0
  • +
  • -

#6 raziel_  Icon User is offline

  • Like a lollipop
  • member icon

Reputation: 464
  • View blog
  • Posts: 4,255
  • Joined: 25-March 09

Re: Need Help Starting My First Code

Posted 29 November 2009 - 02:17 PM

see the difference here :
http://www.dreaminco...wtopic58039.htm

i edit my last topic do you want to copy the files in other directory ?
Was This Post Helpful? 0
  • +
  • -

#7 syeo  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 5
  • Joined: 29-November 09

Re: Need Help Starting My First Code

Posted 29 November 2009 - 02:21 PM

View PostNoBrain, on 29 Nov, 2009 - 01:17 PM, said:

see the difference here :
http://www.dreaminco...wtopic58039.htm

i edit my last topic do you want to copy the files in other directory ?


Oh ok, commands are named different.

Yea the program will move files from one directory to another, and create a subdirectory if needed. Take a peek at my example of directories above. I need it to exactly that, from only reading the directory and file name.

The subdirectory of the unsorted directory contains the name of the show, the subdirectory of the show will contain a file that has the show name and season number. That file name has to be read, then used to move the .mkv file to a completely separate directory structure, TV Shows. It must then search for the right subdirectory, the one corresponding to the correct tv show, then another subdirectory of the tv show corresponding to the season, the simply move the file there. I'd like it to check for the subdirectory, season, and make sure its there and if not create one as required.

P.s. The difference in VB6 and VB.net might be why some of the code I found online doesn't seem to work in my compiler. It keeps showing me errors. LoL thanks for pointing it out, I would have just been way more confused.

This post has been edited by syeo: 29 November 2009 - 02:23 PM

Was This Post Helpful? 0
  • +
  • -

#8 raziel_  Icon User is offline

  • Like a lollipop
  • member icon

Reputation: 464
  • View blog
  • Posts: 4,255
  • Joined: 25-March 09

Re: Need Help Starting My First Code

Posted 29 November 2009 - 02:30 PM

well it is not so hard see this

Public Class Form1

	Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
		Dim FileToCopy As String
		Dim WhereToCopy As String

		FileToCopy = "C:\Unsorted\StargateXXXX\XXXXS01E09.mkv"
		WhereToCopy = "C:\Tv Shows\Stargate\Season 1\XXXXS01E09.mkv"

		If System.IO.Directory.Exists("C:\Tv Shows\Stargate\Season 1\") Then
			If System.IO.File.Exists(FileToCopy) Then
				System.IO.File.Copy(FileToCopy, WhereToCopy)
			End If
		Else
			System.IO.Directory.CreateDirectory("C:\Tv Shows\Stargate\Season 1\")
			If System.IO.File.Exists(FileToCopy) Then
				System.IO.File.Copy(FileToCopy, WhereToCopy)
			End If
		End If
	End Sub
End Class



now System.IO.File.Exists(FileToCopy) check if the file exist and System.IO.Directory.Exists() check if directory exist.

if exist the directory and the file System.IO.File.Copy() copy the file. if the directory dont exists the System.IO.Directory.CreateDirectory create one and the if the file exist it same function copy it :)

good luck dude :)

This post has been edited by NoBrain: 29 November 2009 - 02:32 PM

Was This Post Helpful? 0
  • +
  • -

#9 syeo  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 5
  • Joined: 29-November 09

Re: Need Help Starting My First Code

Posted 29 November 2009 - 03:04 PM

View PostNoBrain, on 29 Nov, 2009 - 01:30 PM, said:

well it is not so hard see this

Public Class Form1

	Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
		Dim FileToCopy As String
		Dim WhereToCopy As String

		FileToCopy = "C:\Unsorted\StargateXXXX\XXXXS01E09.mkv"
		WhereToCopy = "C:\Tv Shows\Stargate\Season 1\XXXXS01E09.mkv"

		If System.IO.Directory.Exists("C:\Tv Shows\Stargate\Season 1\") Then
			If System.IO.File.Exists(FileToCopy) Then
				System.IO.File.Copy(FileToCopy, WhereToCopy)
			End If
		Else
			System.IO.Directory.CreateDirectory("C:\Tv Shows\Stargate\Season 1\")
			If System.IO.File.Exists(FileToCopy) Then
				System.IO.File.Copy(FileToCopy, WhereToCopy)
			End If
		End If
	End Sub
End Class



now System.IO.File.Exists(FileToCopy) check if the file exist and System.IO.Directory.Exists() check if directory exist.

if exist the directory and the file System.IO.File.Copy() copy the file. if the directory dont exists the System.IO.Directory.CreateDirectory create one and the if the file exist it same function copy it :)

good luck dude :)


Thanks for the start. I can definitely use that for the second half of the code. I'm going to go work on it for a few hours and I'll post back if I run into any trouble.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1